Friday, April 3, 2020

growing virtualbox guest centos7 linux VM on windows 10 host

Here's another thing that was a whole lot harder than it seems like it should have been. I found several threads/links that were ALMOST everything I needed to know, but missing a couple of important details that probably weren't relevant to the author's situation so not in their process.

This link is very helpful (and this one) and basically describes the correct process.

The details that were missing from the first link were:

1. modifyhd must be done for each snapshot in the VM, not just the main vdi itself (see this link):

To list all the virtualbox drives, use "c:\Program Files\Oracle\VirtualBox>VBoxmanage list hdds". Then for each one associated with the vm you are growing, use modifyhd: "c:\Program Files\Oracle\VirtualBox>VBoxmanage modifyhd "C:\Users\auto\VirtualBox VMs\craigmcc APS dev\Snapshots\{4841ac14-4e09-4b0b-aa54-9665bb1bd4b3}.vdi" --resize 50000". So in my case I used modifyhd 5 times:

c:\Program Files\Oracle\VirtualBox>VBoxmanage modifyhd "C:\Users\auto\VirtualBox VMs\craigmcc APS dev\craigmcc APS dev 20200306 1620-disk001.vdi" --resize 50000
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

c:\Program Files\Oracle\VirtualBox>VBoxmanage modifyhd "C:\Users\auto\VirtualBox VMs\craigmcc APS dev\Snapshots\{97e89522-0465-4f68-bfa9-ca33d790a379}.vdi" --resize 50000
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

c:\Program Files\Oracle\VirtualBox>VBoxmanage modifyhd "C:\Users\auto\VirtualBox VMs\craigmcc APS dev\Snapshots\{9eb0ae2e-6b3a-41ba-a212-3c27410d8dbf}.vdi" --resize 50000
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

c:\Program Files\Oracle\VirtualBox>VBoxmanage modifyhd "C:\Users\auto\VirtualBox VMs\craigmcc APS dev\Snapshots\{6b89d87f-f0d2-4a10-a64a-0b22fdde66de}.vdi" --resize 50000
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

c:\Program Files\Oracle\VirtualBox>VBoxmanage modifyhd "C:\Users\auto\VirtualBox VMs\craigmcc APS dev\Snapshots\{4841ac14-4e09-4b0b-aa54-9665bb1bd4b3}.vdi" --resize 50000
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

2. after using "lvextend" you must use "xfs_growfs" to make the space available (this is mentioned in the 2nd link above, but not the first.

After running lvextend, "lsblk" output looked correct, but "df -h" did not show the newly available space. I fixed this by running "sudo xfs_growfs /dev/mapper/centos-root". Now df shows the correct output.

So in a nutshell here are the steps:

1. make the disk partition larger, I used the command line tools shown above whereas the first link does so in vbox manager. "df" doesn't show the available space at this point, unlike the example in the first link above where df does show the space. But gparted does see it...
2. download gparted .iso file
3. mount the .iso file under the vm's storage tab on settings under IDE controller, make sure on system tab that optical is before hard disk in boot order
4. start the vm and run gparted, add the unallocated space to the partition you want to grow (in my case where / is mounted)
5. i had to follow the special LVM instructions in the first link, so in gparted you must "deactivate" the partition with the lock icon before growing it
6. unmount optical disk for gparted and reboot vm
7. display physical volumns with "sudo pvs", should show new free space
8. grow the physical volume with "sudo pvresize /dev/sda2"
9. "lsblk" still shows that the root partition is not using the entire available free space
10. run "sudo lvextend -l +100%FREE /dev/centos/root" to use the entire free space for the logical volume
11. run "sudo xfs_growfs /dev/mapper/centos-root" to grow the logical volume while mounted

No comments: