Expanding a Virtual Box (6.1.16) Virtual NVMe Disk Without Downtime on CentOS 8.2 is Not Possible

  • Post author:
  • Post category:CentOS / OS

Today I have tried to expand a virtual disk online, a feature, which I have done on VMware for a long time,
but it looks that this feature is still not possible.

I understand that resizing a virtual disk is not possible, if it is a fixed size disk, or if it has snaphots on it,
but even with a dynamic sized disk, you still can’t do it online.

My plan was to resize the PostgreSQL Disk PGDisk02, which is a dynamic disk online.

C:\Program Files\Oracle\VirtualBox>VBoxManage.exe showmediuminfo D:\OCM\Virtualbox\ocm199\PGDisk02.vdi
UUID:           32545f8c-8791-4b3c-9a41-e5f0e6477446
Parent UUID:    base
State:          locked write
Type:           normal (base)
Location:       D:\OCM\Virtualbox\ocm199\PGDisk02.vdi
Storage format: VDI
Format variant: dynamic default
Capacity:       32768 MBytes
Size on disk:   9 MBytes
Encryption:     disabled
Property:       AllocationBlockSize=1048576
In use by VMs:  ocm199 (UUID: 4bca963d-eb2f-4179-91a8-132f67635b09)

Unfortunately, if you try to do so, you will run into the following error:

C:\Program Files\Oracle\VirtualBox>VBoxManage.exe modifymedium disk D:\OCM\Virtualbox\ocm199\PGDisk02.vdi --resize 40960
VBoxManage.exe: error: Failed to lock media when resizing 'D:\OCM\Virtualbox\ocm199\PGDisk02.vdi'
VBoxManage.exe: error: Details: code VBOX_E_INVALID_OBJECT_STATE (0x80bb0007), component MediumWrap, interface IMedium, callee IUnknown
VBoxManage.exe: error: Context: "Resize(cbResize, pProgress.asOutParam())" at line 810 of file VBoxManageDisk.cpp
VBoxManage.exe: error: Failed to resize medium!

You really need to shutdown the Virtual Box VM first, to get the job done. After I did so, I could resize the
disk from 32GB to 40GB.

C:\Program Files\Oracle\VirtualBox>VBoxManage.exe modifymedium disk D:\OCM\Virtualbox\ocm199\PGDisk02.vdi --resize 40960
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

Afterwards, it is immediately reflected in the Gui.

Now we can start up the VM and do the rest of the work.

However, like expected, in the OS it still has not the full capacity. That is very normal. You need to expand the PV disk first, and afterwards use lvextend to do the rest.

[root@ocm199 ~]# df -h | grep ptdbdata
/dev/mapper/pgvgdata-pglvdata   21G  183M   21G   1% /ptdbdata
[root@ocm199 ~]#

[root@ocm199 ~]# cat /etc/fstab | grep ptdbdata
/dev/pgvgdata/pglvdata          /ptdbdata                       xfs     defaults        0 0
[root@ocm199 ~]#

[root@ocm199 ~]# pvs | grep pgvgdata
/dev/nvme0n9 pgvgdata lvm2 a--   <22.00g 1020.00m

[root@ocm199 ~]# pvresize /dev/nvme0n9
Physical volume "/dev/nvme0n9" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized

The PV disk reflects now the new size. (40GB)

[root@ocm199 ~]# pvs | grep pgvgdata
/dev/nvme0n9 pgvgdata lvm2 a--  40.00g 19.00g

Now we can use lvresize to extend the logical volumne to it’s full extent (100%) and at the same time extend the XFS file system.

[root@ocm199 ~]# lvresize --extents +100%FREE --resizefs /dev/pgvgdata/pglvdata
Size of logical volume pgvgdata/pglvdata changed from 21.00 GiB (5376 extents) to 40.00 GiB (10239 extents).
Logical volume pgvgdata/pglvdata successfully resized.
meta-data=/dev/mapper/pgvgdata-pglvdata isize=512    agcount=4, agsize=1376256 blks
=                       sectsz=512   attr=2, projid32bit=1
=                       crc=1        finobt=1, sparse=1, rmapbt=0
=                       reflink=1
data     =                       bsize=4096   blocks=5505024, imaxpct=25
=                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=2688, version=2
=                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 5505024 to 10484736

[root@ocm199 ~]# df -h | grep ptdbdata
/dev/mapper/pgvgdata-pglvdata   40G  318M   40G   1% /ptdbdata

Conclusion

Unfortunately, the online resize feature is still not available with Virtual Box Version 6.1.16. In case I
have missed something, and it is possible, then please leave a comment.