How can I add the new space to a volume group after resizing partition?

This was the output of lsblk before running parted:

sda 8:0 0 90G 0 disk └─sda1 8:1 0 40G 0 part ├─ubuntu--vg-root 253:0 0 39G 0 lvm / └─ubuntu--vg-swap_1 253:1 0 976M 0 lvm [SWAP] 

After adding more space to my virtual machine disk I ran the following commands to reflect the new space in the OS:

sudo parted /dev/sda resizepart 1 sudo resize2fs /dev/sda1 quit 

Then o got this message:

Information: You may need to update /etc/fstab. 

Now the output of lsblk is:

sda 8:0 0 90G 0 disk └─sda1 8:1 0 90G 0 part ├─ubuntu--vg-root 253:0 0 39G 0 lvm / └─ubuntu--vg-swap_1 253:1 0 976M 0 lvm [SWAP] 

But the system is still showing 42GB instead of new 90GB disk size, I think I need to do something to add the storage in ubuntu--vg-root ...

Is it because I need to update /etc/fstab? If so, how? If not then which commands should I run?

4

1 Answer

Your system uses Logical Volume Management (LVM). In this setup, a partition does not directly host a filesystem but an LVM physical volume. The filesystem is hosted by an LVM logical volume which is contained on one or more physical volumes.

I recreated your situation in a VM. Just doing resizepart using parted does not extend the physical volume:

$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 90G 0 disk └─sda1 8:1 0 90G 0 part ├─ubuntu--vg-root 252:0 0 39G 0 lvm / └─ubuntu--vg-swap_1 252:1 0 976M 0 lvm [SWAP] $ sudo pvs PV VG Fmt Attr PSize PFree /dev/sda1 ubuntu-vg lvm2 a-- 40,00g 44,00m 

So you need to extend the physical volume:

sudo pvresize /dev/sda1 

The result can be checked using pvs:

$ sudo pvs PV VG Fmt Attr PSize PFree /dev/sda1 ubuntu-vg lvm2 a-- 90,00g 50,04g 

Then resize the logical volume. Use -r to automatically resize the contained filesystem. After the prefix /dev/mapper/, specify the logical volume name shown by lsblk below sda1:

sudo lvresize -r -l+100%FREE /dev/mapper/ubuntu--vg-root 

Both these operations can be done even when booted from the resized drive, you don’t need to boot a live CD.

The result:

$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 90G 0 disk └─sda1 8:1 0 90G 0 part ├─ubuntu--vg-root 252:0 0 89G 0 lvm / └─ubuntu--vg-swap_1 252:1 0 976M 0 lvm [SWAP] 
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like