today i will show you what i had to do to add a new hard drive to my linux virtualbox.

my situation was that i had a linux virtualbox machine i originally created with 8 gigs of virtual hard disk space. and while this was just a test server, i ran out of space when i tried to unpack a tarball file that was like 2GB in size, it gave me this message:
# tar xvfz MyBackUp.tar.gz ./backups

gzip: stdin: unexpected end of file
tar: Unexpected EOF in archive
tar: Error is not recoverable: exiting now


basically what this error means, its that there is not enough space in your hard drive to complete unpacking the tarball package.

so abviously, i had to add more space. now i you would think since this is a virtualbox, i could just extend the virtual hard disk space with a click of a button. but unfortunately there is none. i visited some sites and the last one sounds most promising, but i didnt try any of them:

http://www.dedoimedo.com/computers/virtualbox-shrink-expand-disks.html
http://www.modhul.com/2008/10/21/re-sizing-a-virtualbox-virtual-disk-image-file/

i didnt want to mess around with all that. so the easiest thing for me to do at this point i to just add another virtual hard disk to my virtualbox.

01p-8638-add-virtual-disk.png

so once i booted my linux virtual machine, i logged in as root and send this command:

fdisk -l


it listed both hard drives under /dev
/dev/hda1
/dev/hdb1


my next command was:

fdisk /dev/hdb


Select n for New Partition
The number of cylinders for this disk is set to 41610.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help):n


Enter p for Primary Partition
Command action
e extended
p primary partition (1-4)
p


Enter 1

Partition number (1-4):1


Dont enter anything, leave as the default
First cylinder (1-41610, default 1):


Dont enter anything, leave as the default
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-41610, default 41610):


now save the partition. enter w to write to the disk
Command (m for help):w


After you submit w, you will get a message that says:
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.


now you need to create a file system on the new partition. since we are using linux, we are going to create a ext3 file system with this command:
mkfs.ext3 /dev/hdb1


after you send the above command, you might get something like this:

mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
2621440 inodes, 5242852 blocks
262142 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
160 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 23 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.


now you can mount your new hard drive. so i sent this command:
mount -t ext3 /dev/hdb1 /mnt/hd2


* NOTE: /mnt/hd2 is the directory i created to mount this new hard drive