2021-11-22
Resizing a filesystem through several layers
For work I use a supplied laptop with Windows 10. For some of my work I want to have a Linux environment available so I have VirtualBox with a Linux virtual machine running. And because some of the work I do on that Linux virtual machine I use full-disk encryption. And the installation was done with the encrypted lvm setting. Resizing the filesystem because it was getting full turned out to be a lot of steps! After stopping the virtual machine I wanted to resize the disk from the VirtualBox media manager but that gave an error. After that I tried the commandline, giving about the same error:> "\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifymedium rotterdam.vdi --resize 32768 0%... Progress state: VBOX_E_NOT_SUPPORTED VBoxManage.exe: error: Failed to resize medium VBoxManage.exe: error: Resizing to new size 34359738368 is not yet supported for medium 'C:\Users\hout0101\VirtualBox VMs\rotterdam\rotterdam.vdi' VBoxManage.exe: error: Details: code VBOX_E_NOT_SUPPORTED (0x80bb0009), component MediumWrap, interface IMedium VBoxManage.exe: error: Context: "enum RTEXITCODE __cdecl handleModifyMedium(struct HandlerArg *)" at line 816 of file VBoxManageDisk.cppIt turns out the .vdi is the wrong type for dynamic resizing. Solution: clone it! The new .vdi will have the dynamic type automatically and there is a "before" .vdi now on disk to revert to if anything goes wrong.> "\Program Files\Oracle\VirtualBox\VBoxManage.exe" showhdinfo rotterdam.vdi UUID: f832b0b4-8738-491d-bd9c-291d755a4af7 Parent UUID: base State: created Type: normal (base) Location: C:\Users\hout0101\VirtualBox VMs\rotterdam\rotterdam.vdi Storage format: VDI Format variant: fixed default Capacity: 26067 MBytes Size on disk: 26070 MBytes Encryption: disabled Property: AllocationBlockSize=1048576 In use by VMs: rotterdam (UUID: 2454dadb-a82d-4d74-bbea-8dcf2b2d1bf1) > "\Program Files\Oracle\VirtualBox\VBoxManage.exe" clonehd rotterdam.vdi rotterdam-2.vdi 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% Clone medium created in format 'VDI'. UUID: 835e2f75-c19d-4e98-865e-d7acf1359fc7 > "\Program Files\Oracle\VirtualBox\VBoxManage.exe" showhdinfo rotterdam-2.vdi UUID: 835e2f75-c19d-4e98-865e-d7acf1359fc7 Parent UUID: base State: created Type: normal (base) Location: C:\Users\hout0101\VirtualBox VMs\rotterdam\rotterdam-2.vdi Storage format: VDI Format variant: dynamic default Capacity: 26067 MBytes Size on disk: 26069 MBytes Encryption: disabled Property: AllocationBlockSize=1048576 > "\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifymedium rotterdam-2.vdi --resize 32768 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%I moved the old .vdi out of the way and added the new .vdi to the virtual machine and started it again. This worked fine, but the root volume wasn't any bigger (yet). Next steps: enlarge the extended partition and the Linux partition in it on disk using parted. You really have to know what you are doing here, so I'm not just going to give a cut-and-paste sample. Now I can resize the encrypted and mounted volume! With the right passphrase.# cryptsetup resize /dev/mapper/sda5_cryptAnd grow the 'physical' (ahem) volume:# pvresize /dev/mapper/sda5_cryptResize the logical volume:# lvextend /dev/rotterdam-vg/root -l +1674And finally resize the mounted filesystem:# resize2fs /dev/mapper/rotterdam--vg-rootAnd the filesystem has grown, and looks good in a fsck on the next boot. So solid state disk → Windows filesystem → vdi file → VirtualBox → disk in Linux virtual machine → partition → lukscrypt → logical volume manager → volume → filesystem.