I like to keep my VM guests reasonably tidy and minimise how much they encroach onto the host, but this means sometimes I run into the need to enlarge the VM's drive.
Note that these instructions assume that there are no snapshots. These can be handled, but it gets more complicated.
- With the VM off, go to the Virtual Media Manager in Virtualbox
- Expand the drive size by dragging the slider
- Boot from a GParted live cd (or similar)
$ sfdisk -l /dev/sda
Desk /dev/sda 60GiB, 64424509440 bytes, 125829120 sectors
Disk model: VBOX HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x359d5cbf
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 104447 102400 59M 7 HPFS/NTFS/exFAT
/dev/sda2 104448 103811496 103707049 49.5G 7 HPFS/NTFS/exFAST
/dev/sda3 103813120 104853503 1040384 508M 27 Hidden NTFS WinRE
$ sfdisk -F /dev/sda
Unparitioned space /dev/sda: 10GiB, 10739515392 bytes, 20975616 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
Start End Sectors Size
104853504 125829119 20975616 10G
$ echo '+20975616' | sfdisk /dev/sda -N 3 --move-data
...
- Refresh gparted and expand sda2
- CLI equivalent (although the gparted live CD doesn't have
growpartinstalled, so you will have to runapt-get update && apt-get install cloud-guest-utilsfirst):
$ growpart /dev/sda 2
$ ntfsresize /dev/sda2
