Add Extra Disc to Virtualbox

Are you looking to install software on your Virtual Box but running low on disk space?

From Oracle VM Virtual Box Manager window add new disc.

Partition the Device

1
$ fdisk /dev/sdb

Follow the screen instructions as shown below.

1
2
3
4
5
6
7
8
9
10
11
12
[/sociallocker] Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x2e3c77cd.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n
Command action
e extended
p primary partition (1-4)

1
p

Partition number (1-4): 1
First cylinder (1-1566, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1566, default 1566):
Using default value 1566

1
Command (m for help): w

The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
We have used ‘n’ to create a new partition, p to create the partition as primary, 1 to specify the partition number and used defaults for begin and end range for partition size.

Finally ‘w’ to make changes permanent.

Query the partition table again.

1
# fdisk -l

Disk /dev/sda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000e4833

Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 13055 104344576 8e Linux LVirtualBox

Format the Partition

Next step is to format the partition. Normally Linux uses ext4 now a day, so we can use that. You can format using the following command.

1
# mkfs.ext4 /dev/sdb1

Mounting the Partition

This partition can now be mounted to location of your choosing. For example if you want to mount this under /u02. Here the steps.

1
2
3
# mkdir -p /u02
# mount /dev/sdb1 /u02
# ll /u02

total 16
drwx—— 2 root root 16384 Feb 1 23:07 lost+found
Presence of lost+found directory suggests that we are ready to go.

You don’t have to do all these steps again except for very last mount command. It will be required on every reboot.

You can avoid that as well by putting the following entry into /etc/fstab file.

1
/dev/sdb1               /u02           ext4    defaults        1 2