1

I'm working on a 64-bit CentOS 7 VM on my Windows 10 host, and I have a dynamically-allocated VHD that is giving me problems.

At first, the VHD's maximum size was set to 16GB, functionally about 14.4 usable. While working on a project I realized that I would need much more space, so I used VBoxManage to increase the maximum to 100GB. Then I used GParted to expand the sda2 partition so that it took up the extra space.

So VirtualBox recognizes that the VHD can go up to 100GB and sda2 takes up most of that space. The actual size of the VHD right now is still 14.4GB. However when I fill up all of this space on the guest OS (by writing a long seq into a file), the drive not does automatically expand.

A couple of things to note:

  1. The first time I tried to fill up the space, when I restarted the VM after filling it up, the VHD file on my host did increase by about 1GB, however it won't expand any more now.

  2. There seems to be a discrepancy between the devices my guest OS reports and what partitions GParted reports. CentOS lists /dev/sda1 and /dev/mapper/centos-root, which is a link to /dev/dm-0, while GParted lists /dev/sda1 and /dev/sda2. Could this be causing the issue, or is this normal? If it is normal, any ideas as to why VirtualBox won't expand the VHD?

  • 2
    Did you "resize2fs"? – slass100 Dec 6 '17 at 19:31
  • @slass100 I just tried using resize2fs, and I got this: resize2fs: Bad magic number in super-block while trying to open /dev/mapper/centos-root Couldn't find valid filesystem superblock. – Connor Howington Dec 6 '17 at 19:51
  • If you are using lvm/xfs, then 'xfs_growfs'. resizefs is for ext2/3/4 – slass100 Dec 6 '17 at 20:04
  • Yep, I figured that out and tried it, however it just says that /dev/mapper/centos-root is already at its maximum size. – Connor Howington Dec 6 '17 at 20:24
2

Ok, I found what the problem was. My filesystem uses Logical Volume Management (LVM), which I have never worked with before, and so I didn't know how to properly handle it. Using LVM terminology, centos is a volume group:

centos

sda2 is a physical volume in that volume group:

sda2

and root is a logical volume in that volume group, along with swap:

root

The centos VG and the sda2 PV had already registered the extra storage I'd allocated, but all that was left was to allocate that extra space to the root LV (21504 is the number of free physical extents (PEs) that I got from vgdisplay):

$ sudo lvextend /dev/centos/root /dev/sda2 -l+21504

and then expand the root filesystem so that it could make use of this extra space:

$ sudo xfs_growfs /dev/centos/root

After this the guest OS recognized that it had extra space, and filling up this space causing a corresponding growth in the size of the virtual hard disk on the host OS. Success!

Source: http://www.techotopia.com/index.php/Adding_a_New_Disk_to_a_CentOS_6_Volume_Group_and_Logical_Volume

  • I had not done sudo xfs_growfs /dev/centos/root. Your answer saved me lot of time. – Pankaj Bansal Dec 21 '18 at 7:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.