Resizing a Raw VMDK For a VirtualBox Guest

Had to resize a partition as I had run out of space on my VirtualBox Linux guests.  Pain in the butt.

Shut the guest down.  Ran a ‘lvextend -L+2GB /dev/amdfx/guestname‘ where “amdfx” is my physical volume and “guestname” is the logical volume name.

Had an extended partition with swap space, so used fdisk to delete the extended partition.  Also deleted and recreated the primary partition making sure to select the same starting sector and setting the end sector using the previous ending value plus 2*1024*1024 (should have been *2 again, but decided it was alright for now).

Recreated the raw disk image for the VM.  First detached and deleted it with ‘vboxmanage storageattach kmm –storagectl “SATA Controller” –port 0 –device 0 –medium none‘, ‘vboxmanage closemedium disk VirtualBox\ VMs/guestname/guestdiskname.vmdk‘, ‘vboxmanage closemedium disk VirtualBox\ VMs/guestname/guestdiskname.vmdk‘, and ‘rm VirtualBox\ VMs/guestname/guestdiskname.vmdk‘.  Then recreated and re-attached it with ‘vboxmanage internalcommands createrawvmdk -filename VirtualBox\ VMs/guestname/guestdiskname.vmdk -rawdisk /dev/mapper/amdfx-guestname‘, ‘vboxmanage storageattach guestname –storagectl “SATA Controller” –port 0 –device 0 –type hdd –medium /home/user/VirtualBox\ VMs/guestname/guestdiskname.vmdk‘.

Restarted the VM, it booted normally.  I was then able to run a ‘resize2fs /dev/sda1‘ from within the guest and realize a gig of extra space (would have been 2GB, except for my screw-up forgetting to multiply by two).

Resources

  • http://askubuntu.com/questions/115310/how-to-resize-enlarge-grow-a-non-lvm-ext4-partition
  • https://forums.virtualbox.org/viewtopic.php?f=7&t=50255
  • http://www.tldp.org/HOWTO/LVM-HOWTO/extendlv.html

Leave a Reply

Your email address will not be published. Required fields are marked *