Score:0

Resize Ubuntu LV

ng flag

I need help to resize my LV: /dev/mapper/ubuntu--vg-ubuntu--lv

The ubuntu installation is a VM, and the disk has been expanded from 8 GB to 11 GB. How do I resize / expand the /dev/mapper/ubuntu--vg-ubuntu--lv volume?

sudo pvdisplay:

  --- Physical volume ---
  PV Name               /dev/vda3
  VG Name               ubuntu-vg
  PV Size               8.46 GiB / not usable 3.00 MiB
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              2166
  Free PE               503
  Allocated PE          1663
  PV UUID               fhw3L2-RTCL-wu3w-WovP-6pGF-iQjv-tujWKE

sudo vgdisplay:

--- Volume group ---
  VG Name               ubuntu-vg
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               8.46 GiB
  PE Size               4.00 MiB
  Total PE              2166
  Alloc PE / Size       1663 / <6.50 GiB
  Free  PE / Size       503 / 1.96 GiB
  VG UUID               ZTcc3J-A3jZ-olN4-rFGR-h40F-wqFD-c3hmCn

sudo lvdisplay:

  LV Path                /dev/ubuntu-vg/ubuntu-lv
  LV Name                ubuntu-lv
  VG Name                ubuntu-vg
  LV UUID                Q31Qia-F92v-te0V-P1fH-4SXv-3uB8-4889p0
  LV Write Access        read/write
  LV Creation host, time ubuntu-server, 2021-10-02 09:59:32 +0200
  LV Status              available
  # open                 1
  LV Size                <6.50 GiB
  Current LE             1663
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

More info added:

GPT PMBR size mismatch (20971519 != 23068671) will be corrected by write.
The backup GPT table is not on the end of the device. This problem will be corrected by write.
Disk /dev/vda: 11 GiB, 11811160064 bytes, 23068672 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 07C77B10-B73C-442D-9F03-A422017A6AE9

Device       Start      End  Sectors  Size Type
/dev/vda1     2048  1050623  1048576  512M EFI System
/dev/vda2  1050624  3147775  2097152    1G Linux filesystem
/dev/vda3  3147776 20899839 17752064  8.5G Linux filesystem


Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 6.51 GiB, 6975127552 bytes, 13623296 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

When I try sudo lvextend -l 100%VG ubuntu-vg/ubuntu-lv I get:

/etc/lvm/archive/.lvm_outlineserver_26853_1055914493: write error failed: No space left on device

And when I try sudo fdisk -l /dev/mapper/ubuntu--vg-ubuntu--lv:

Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 6.51 GiB, 6975127552 bytes, 13623296 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes

and last when I try sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv I get:

resize2fs 1.45.5 (07-Jan-2020) The filesystem is already 1702912 (4k) blocks long. Nothing to do!

ridgy avatar
my flag
Could you please add the output of `sudo pvdisplay`, `sudo vgdisplay` and `sudo lvdisplay` to your question?
julianb avatar
ng flag
Of course, no problem. I just updated the question with pvdisplay, vgdisplay and lvdisplay
Score:0
my flag

I'm not really sure what you have done so far. The partition /dev/vda3 has been increased to 8.5 GB (which means 10GB of the disk are used), but the end of partition vda3 (20899839) is less than the end of the "physical" disk (23068672), see the output of fdisk -l. Maybe GPT PMBR size mismatch (20971519 != 23068671) gives some hint.

Anyway, parts of the LVM structures (pv and vg) are already reflecting the new size. What is missing is the size of the logical volume and the size of the filesystem. As you can see from pvdisplayand vgdisplay, there are 503 extents = 1.96 GiB still free.

So, first increase the size of the logical volume to that of the volume group:

sudo lvextend -l 100%VG ubuntu-vg/ubuntu-lv

fdisk -l /dev/mapper/ubuntu--vg-ubuntu--lv should then give you the new size of ~ 8.5 GB.

Now, increase the size of the filesystem to that of the logical volume (I suppose ext4 here for '/'; if it is a different filesystem, you will have to use a different command!):

sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv

This is possible for a mounted filesystem, when the kernel supports it, which all recent kernels should do.

For more information, see man lvextend and man resize2fs. Or Please help me work out what is happening with the available space on my VM's LVM2 partition

julianb avatar
ng flag
Thank you, but I can't get this to work for some reason. I added more info to my question above after running the commands you specified.
julianb avatar
ng flag
This worked, but I needed to delete some files first, so I could write the changes..
ridgy avatar
my flag
You are right. Your root filesystem was 100% full, so writing LVM information was not possible. Sorry, I did not take that into account ....
mCasamento avatar
in flag
Windows guy here, wasn't easy for me to follow what was wrong on my home server installation until I found this post. Thanks, it worked.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.