VirtualBox: Extend Linux Disk Space
How to extend a guest Linux Operating System in Oracle VirtualBox?
Use the command line “VBoxManage”, like this:
VBoxManage modifyhd "C:\Users\h3\VirtualBox VMs\ubuntu1\ubuntu 11.10.vdi" --resize 20000
If you are using Oracle VirtualBox, and is out of disk space for a Linux virtual machine, you can extend the storage space by command line.
However, you still need to go into the guest Linux to partition it. This is sometimes impossible, because your main Linux dir structure is already in place. You need to do a lot work. I highly recommend you start a virtual machine with enough disk space for the main directory structure. Anyhow, here's the story on how to extend disk space.
my VirtualBox Linux disk is full.
xah@xah-VirtualBox ◆ 2012-10-13 ◆ 08:13 ◆ ~ ◆ df -H Filesystem Size Used Avail Use% Mounted on /dev/sda1 7.7G 6.9G 383M 95% / udev 403M 4.1k 403M 1% /dev tmpfs 164M 779k 164M 1% /run none 5.3M 0 5.3M 0% /run/lock none 410M 140k 410M 1% /run/shm web 989G 289G 700G 30% /media/sf_web xah@xah-VirtualBox ◆ 2012-10-13 ◆ 08:14 ◆ ~ ◆
after a hour, learned VirtualBox command line to extend disk space. Now to 20G.
C:\Program Files\Oracle\VirtualBox>VBoxManage modifyhd "C:\Users\h3\VirtualBox VMs\ubuntu1\ubuntu 11.10.vdi" --resize 20000
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
C:\Program Files\Oracle\VirtualBox>
But that only extend logical space. You'll need to dive into guest OS to partition it.
So, i dove in, and then realized one can't extend a partition of a mounted disk. And i probably can't easily do because the Operating System is there.
xah@xah-VirtualBox◆ 2012-10-13 ◆ 07:53 ◆ ~ ◆ sudo fdisk -l Disk /dev/sda: 21.0 GB, 20971520000 bytes 255 heads, 63 sectors/track, 2549 cylinders, total 40960000 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0004f1c7 Device Boot Start End Blocks Id System /dev/sda1 * 2048 15136767 7567360 83 Linux /dev/sda2 15138814 16775167 818177 5 Extended /dev/sda5 15138816 16775167 818176 82 Linux swap / Solaris
the sda1 is my mounted root. It's 7G, 95% used. But now the disk is 21G. I want extend sda1.
alternative is just to add the new space as a new partition and mount it on some path, but this isn't good as the file structure is already on the main partition.
so, after about 3 hours, looks like it'll be faster if i start fresh. Create a new Linux guest VB, install guest additions, and install the whole stuff i had. I end up starting a fresh guest Linux install. The process takes about 5 hours. See: How to Install Linux on VirtualBox and Xah Linux Setup.