Sunday, January 18, 2015

Ubuntu - VirtualBox - Setup - Add a new hard drive to Ubuntu VM

Environment:

OS: Ubuntu 14.04 guest VM
VirtualBox: 4.3.6 on Windows 7 host




Add a hard drive in VirtualBox:

  1. Go to VirtualBox Manager
  2. Select the VM where drive needs to be added and click 'Settings' (ctrl+S)
  3. On settings dialog, click on 'Storage' from left navigation panel. 'Storage Tree' and 'Attributes' will be shown at right side (see Pic-01)
  4. Under 'Storage Tree', select 'Controller: SATA', 'Add CD/DVD Device' and 'Add Hard Disk' icons will be displayed (see Pic-01)
  5. Click on 'Add Hard Disk' (see Pic-01)
  6. Pic-01: Settings dialog box
  7. Click on 'Create New Disk' on popup (see Pic-02)
    Pic-02
  8. Select 'VDI - VirtualBox Disk Image' and Click Next
    Pic-03: HDD file type
  9. Select hard drive file type and click Next
    Pic-04: Storage on Hard drive
  10. Specify file lcoation and size and click Create. It will take few minutes to finish. 

Make the hard drive available in Ubuntu:
  1. Check drives
    Command: "sudo fdisk -l"
    Output:
    Disk /dev/sdb: 107.4 GB, 107374182400 bytes255 heads, 63 sectors/track, 13054 cylinders, total 209715200 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/sdb doesn't contain a valid partition table
  2. Create partition
    Command: "sudo fdisk /dev/sdb"
  3. type 'n' to create partition
  4. Next select partition type p=Primary, e=Extended
  5. Specify number of partitions
  6. I had to create two partitions. For me next two options were to specify first sector and last sector where I selected default.
  7. 'w' to write the changes
  8. 'q' to quite fdisk
  9. Update kernel with changes
    Command: "sudo partprobe /dev/sdb"
  10. Format hard drive
    Command: "sudo mkfs /dev/sdb2 -t ext4"
  11. Create a directory for mount point. Following convention to create under /mnt
    Command: "sudo mkdir /mnt/sdb2"
  12. Make the folder writable
    Command: "sudo chmod 777 /mnt/sdb2"
  13. Mount drive to folder
    Command: "sudo mount /dev/sdb2 /mnt/sdb2 -t ext4"

2 comments:

hor said...

Command: "sudo mount /dev/sdb2 /mnt/sdb2 -t ext4" error : no entry point for sdb2

Catherine said...

Thanks for the command (comment above)!