Increase VirtualBox Windows 7/10 VDI and C: partition size

Do you use Windows as a VirtualBox guest inside a Linux host and eventually find the VDI size you initially set too small, need to to increase it, as well as extend the C: partition even though some recovery partition may be blocking Windows Disk Management to do the task? Move the partition inside VHD on the host OS in gparted by mounting VDI by qemu-nbd!

My scenario: I use Linux Mint as my main OS for most tasks. However, for Adobe Creative Cloud (Illustrator, Photoshop, et al.) and Office 365 (mainly Excel 2016) I need Windows. I need everything encrypted, and I need to access Linux partitions from within Windows. SSD is a self-encrypting drive. Second HDD is encrypted by dm-crypt/LUKS. All volumes are ext4 therefore cannot be reasonably accessed from Windows if I were using dual-boot. Mounting these volumes to Virtual machine is the way to accomplish that. After migrating to a larger 480 GB SSD and struggling with not enough space on the Windows C: partition I decided to increase the space for Windows as I could afford it now thanks to the larger enterprise-grade SSD :-)

Steps to perform:

  1. Shutdown and backup whole Virtual machine with all settings, in case something goes wrong. In my case the virtual machine is stored at ~/VirtualBox VMs/Work/Win10
  2. cd to this folder where the VDI lies and run a command to increase the Virtual disk size, in my case to 90 000 MB:
    VBoxManage modifyhd VIRTUALDISKNAME.vdi --resize 90000
  3. You can boot Windows in VirtualBox to see if it boots OK. The C: partition is however unchanged as only the virtual disk size has changed but not the partitions inside it. Run Disk management as Administrator (Win -> diskmgmt.msc). If your C: partition is the last one and there is free space after it, you can immediately expand the partition from within Windows Disk management console and in a few seconds you are done. In case there is some other partition after C: that cannot be moved by Disk Management (such as a 450 MB recovery partition in my case) you cannot directly expand the C: partition and you need to first move these extra partitions to the end of the larger VHD.
  4. Shutdown the virtual machine and install qemu with tools. I like using gparted on Linux for doing partition changes but parted cannot directly work with VDI images. qemu-nbd can however create a virtual device from a VDI file so it can be accessed by gparted or any other tool. By following a tutorial by Giles Orr open a root shell (sudo -s), load the proper kernel module (modprobe nbd) and mount the VDI as a virtual device:
    qemu-nbd -c /dev/nbd0 ./VIRTUALDISKNAME.vdi
  5. Run gparted (gparted /dev/nbd0) and simply move the extra partition to the end of drive and expand the main NTFS partition to fill the empty space. In my case the layout after these changes look like this:
  6. Disconnect the nbd0 device:
    qemu-nbd -d /dev/nbd0
  7. Start Windows virtual machine and enjoy extra space on the C: partition :-)

Autor

Martin

Pracuji jako ajťák a grafik na volné noze, zejména ale pro brněnskou firmičku vyrábějící ekodrogerii. Dále působím v brněnském systému místní směny Rozleťse, Českém zahrádkářském svazu, České psychedelické společnosti, spolku Archetypal a Mezinárodní komunitě dzogčhenu. Asi mě baví kumulovat různé funkce a přidávat si spoustu práce. Lidi o mě říkají, že jsem multifunkční, což je asi trochu pravda :-)

Napsat komentář

Vaše emailová adresa nebude zveřejněna. Vyžadované informace jsou označeny *