Why isn't the newly resized virtual disk image(vdi) space showing up and how do I fix it?

You're dealing with disk space on three (and an implied fourth) level of abstraction:

  • Disk space in the .vdi file -- You've resized this file with VBoxManage, but the space hasn't yet appeared in the next two levels of abstraction. Essentially, what you've done is like installing a larger physical disk in a real computer and copied the contents of the original disk over with dd. You have more (virtual) disk space now, but you can't use it because the data structures used to access the disk have not yet been updated.
  • Partitions (aka physical volumes, or PVs) in the virtualized disk -- You must either resize your existing PV or create a new one and add it to your volume group (VG). See this question for pointers on this topic.
  • Logical volumes (filesystems) -- Once you've expanded the PV or created a new one and added it to the VG, you must expand the logical volume (LV) and the filesystem it contains. The question referenced in the previous bullet point describe how to do this.
  • Disk space in the host system -- This is the fourth/implied level of abstraction, and is actually "above" the preceding ones. Although the VBoxManage command probably resulted in a trivial change to your host system disk space use, once you begin using that space in the virtualized environment, physical disk space use will increase. Assuming you have sufficient real disk space, this shouldn't be a problem, and it doesn't affect what you need to do; I mention it only for completeness.

Olavi Sau's answer seems to be correct, but is presented in the reverse order of what you must actually do, so it could be confusing. (That is, the answer describes filesystem/LV operations before partition/PV operations; but you need to do the partition/PV operations first.) Thus, I thought that presenting a "bird's-eye view" answer would be a helpful supplement.


The first thing you should do is verify that you don't already have the space you need by seeing how much free space your volume group has.

All the following commands usually require sudo.

You can see the attributes of volume groups with vgdisplay

vgdisplay

You should see something like this:

     --- Volume group ---
  VG Name               example-vg
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               15.52 GiB
  PE Size               4.00 MiB
  Total PE              3972
  Alloc PE / Size       3963 / 15.48 GiB
  Free  PE / Size       9 / 36.00 MiB
  VG UUID               JZCVgU-QvdG-2dMN-ZLrO-YXHp-83bq-zItAUD

If you have free physical extents (PE) you can just add those ( if the free physical extents size covers your needs, skip to adding to logical volume Ctrl + F ADDING TO LOGICAL VOLUME ).

If you don't have enough free space in your volume group, you need to add it from your free allocated space, but first you need to partition it.

You can do that with fdisk

fdisk /dev/sda

First list the existing table ( You need to know where to start the partition from )

In fdisk ( Command (m for help): )

p

Will display something like this:

Device     Boot    Start      End  Sectors  Size Id Type
/dev/sda1  *        2048   999423   997376  487M 83 Linux
/dev/sda2        1001470 32000000 30998531 14.8G  5 Extended
/dev/sda3       32002048 48779263 16777216    8G 8e Linux LVM
/dev/sda5        1001472 32000000 30998529 14.8G 8e Linux LVM

Copy the highest End. Otherwise you might create a partition between partitions, which limits the partition's size to the space between the partitions. ( like 1 kb )

Proceed by pressing n ( create a new partition )

n

Choose the default number ( it doesn't matter much, but write it down or remember it)

Paste the highest end for the first sector and end as +size{K,M,G,T,P} ( or however you like )

That will create the new partition.

You should now reboot ( sudo reboot )

After reboot create the physical volume pvcreate /dev/sda##THE NUMBER YOU CHOSE##

Reboot again if needed sudo reboot

If you don't remember the number you can just fdisk /dev/sda ... p to list them.

Now extend your volume group vgextend example-vg /dev/sda##NUMBER##

ADDING TO LOGICAL VOLUME

sudo parted ##example-vg-path ( from vgdisplay) ##

print list ( find your /dev/mapper/example-vg--vg-root )

resizepart NUMBER

Enter your size

quit

sudo resize2fs  /dev/mapper/example--vg-root

Run df -h to check.

The ending got a bit clunky but oh well in a hurry :)