Virtualbox resizing a partition for Ubuntu troubles

Hello all,

System specifics:
- Virtualbox
- Ubuntu  v18.x LTS
- Virtual drive (dynamic)


I am trying to expand an extended partition in a Virtualbox Ubuntu 18.x installation. I stupidly started with a 10 GB virtual drive and quickly ran out of space. :(

So this is what I did:
  1. Increased the virtual drive size via, "VBoxManage modifyhd “virtualmachine.vdi" --resize kbytes"
  2. Started a secondary copy of Ubuntu and mounted the primary Ubuntu vitual volume (the one I want to expand)
  3. Deactivated the /dev/sda2 (sdb2 - in secondary boot) partition
  4. [a few other steps]
  5. Selected partition and resized.

[so far so good]
Then I rebooted into the primary Ubuntu and discovered that Ubuntu couldn't see the additional 10 GB of volume space. :(
But gparted shows that I should have 10.02 GiB of unused space?

I think the problem is that gparted extended the partition but didn't do the same for the file system.

How do I fix this? I am at a loss.

Booting back into the secondary Ubuntu and mounting the other virtual disk, I have tried:
- resize2fs I just see some variation of a "superblock error"

pvscan shows:
PV /dev/sdb5   VG yvr-UbuntuDevTest01-vg   lvm2 [19.52 GiB / 10.02 GiB free]

Which looks perfect but when I boot back into the primary Ubuntu system, I see only 170 MB free... which gparted still shows that I should have 10.02 GiB of free space. :(

repartition.png
Any ideas on how I can solve this without starting over? I am primarily asking so that I might learn something new... it's not mission critical if I must start over. :)


Thank you
LVL 4
S ConnellyTechnical WriterAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nociSoftware EngineerCommented:
In general you also need to let the filesystem known (and adjust to) the new container size.
In your  case this means first you need to expand the LVM partition,
lvresize -l 100%VG    lvname

Open in new window

to use all "free" VG size to the LV.
Then retry the resize2fs  command.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
S ConnellyTechnical WriterAuthor Commented:
Thank you for the assistance, noci.

So this is what I did...

Before:

sudo lvmdiskscan
  /dev/loop0                         [     582.08 MiB]
  /dev/yvr-UbuntuDevTest01-vg/root   [       8.54 GiB]
  /dev/loop1                         [     142.01 MiB]
  /dev/sda1                          [     487.00 MiB]
  /dev/yvr-UbuntuDevTest01-vg/swap_1 [     976.00 MiB]
  /dev/loop2                         [      86.52 MiB]
  /dev/loop3                         [      93.52 MiB]
  /dev/loop4                         [     142.04 MiB]
  /dev/sda5                          [      19.52 GiB] LVM physical volume
  1 disk
  7 partitions
  0 LVM physical volume whole disks
  1 LVM physical volume

sudo lvresize -l 100%VG /dev/yvr-UbuntuDevTest01-vg/root
 Size of logical volume yvr-UbuntuDevTest01-vg/root changed from 8.54 GiB (2187 extents) to 18.57 GiB (4753 extents).
  Logical volume root successfully resized.


After
sudo lvmdiskscan
  /dev/loop0                         [     582.08 MiB]
  /dev/yvr-UbuntuDevTest01-vg/root   [      18.57 GiB]
  /dev/loop1                         [     142.01 MiB]
  /dev/sda1                          [     487.00 MiB]
  /dev/yvr-UbuntuDevTest01-vg/swap_1 [     976.00 MiB]
  /dev/loop2                         [      86.52 MiB]
  /dev/loop3                         [      93.52 MiB]
  /dev/loop4                         [     142.04 MiB]
  /dev/sda5                          [      19.52 GiB] LVM physical volume
  1 disk
  7 partitions
  0 LVM physical volume whole disks
  1 LVM physical volume

Next and last step:

sudo resize2fs /dev/yvr-UbuntuDevTest01-vg/root

resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/yvr-UbuntuDevTest01-vg/root is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
The filesystem on /dev/yvr-UbuntuDevTest01-vg/root is now 4867072 (4k) blocks long.

sudo df -h

/dev/mapper/yvr--UbuntuDevTest01--vg-root   19G  7.8G  9.6G  45% /

Done! :)

Thank you.
root---low-space-warning.png
0
S ConnellyTechnical WriterAuthor Commented:
Hi Noci,

I kind of did this somewhat "blindly". Could you help me learn a bit more by briefly describing what is happening during each step. Thank you.
0
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

S ConnellyTechnical WriterAuthor Commented:
Noci provided the essential tip in order for me to solve the problem. Thank you so much.

I posted the necessary steps to complete a LVM expansion but I would like some additional explanation of what exactly is happening in the background for each of those steps. Thanks.
0
nociSoftware EngineerCommented:
with pvs, vgs, lvs    the current size & status can be determines.
When the storage container is enlarged on the server, only the Disk is larger... (like changing the disk for a larger one and retoring an disk image.
The next ring in the onion is the partition table.  that needs to be enlarged... if partitions can be just enlarged (the last partition) then it is sufficient to delete it and create it with the same start and the new end of disk/size...
Otherwise some partitions need to be moved around (out of scope for this question...).
If this is saved and ready the next layer in the onion, in this case LVM, first pv resizing (to gain the storage within PV), next layer then vgresizing (to gain the storage in the Virtual group, then next layer lvresizing for the LVM...,     then finaly the filesystem can be enlarged...
for ext2/3/4   this is resize2fs... for btrfs: btrfs filesystem resize...,   for xfs: xfs_grow.

Note: enlarging filesystems is easy and mostly can be done online..., shrinking is near impossible. The easiest for that  is making a backup and restore in a smaller partition. (No image backup, a filesystem backup , like tar, xfsdump, dumpfs .
0
S ConnellyTechnical WriterAuthor Commented:
Thank you so much, noci.
I really appreciate your explanation. :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Virtual Box

From novice to tech pro — start learning today.