4

I recently cloned my ubuntu from a 250GB SSD to my new 2TB SSD. It automatically created an LVM with 248GB with my root filesystem in it.

I would like to resize the LVM to full 2TB.

nvme0n1             259:1    0   1.8T  0 disk 
├─nvme0n1p1         259:7    0   512M  0 part /boot/efi
└─nvme0n1p2         259:8    0   1.8T  0 part 
  ├─vgubuntu-root   253:0    0 231.4G  0 lvm  /
  └─vgubuntu-swap_1 253:1    0   976M  0 lvm  [SWAP]

However the PSize is only 250 GB, rather than 2TB fromsudo pvs

PV             VG       Fmt  Attr PSize   PFree
  /dev/nvme0n1p2 vgubuntu lvm2 a--  232.38g    0 

I see the following output from lvdisplay:

--- Logical volume ---
  LV Path                /dev/vgubuntu/root
  LV Name                root
  VG Name                vgubuntu
  LV UUID                0wM6pq-o26o-qVBf-1x61-vFbP-Poyf-fFW3f7
  LV Write Access        read/write
  LV Creation host, time ubuntu, 2021-04-24 06:13:08 +0800
  LV Status              available
  # open                 1
  LV Size                <231.43 GiB
  Current LE             59246
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

I tried the following lvextend command but it does not extend beyond 248GB size:

lvextend -l +100%FREE /dev/vgubuntu/root/

with the output:

New size (59246 extents) matches existing size (59246 extents).

Can someone please advise?

EsmaeelE
  • 337
  • Welcome to AskUbuntu! Can you please edit your question and add the output of lvdisplay? A lot of the time the lvname is different than what you see when you run like lsblk or df. What we are looking for is the name associated with LV Path. – Terrance May 05 '22 at 03:15
  • Hi Terrance, done. Thanks. – Jeff0129 May 05 '22 at 03:28
  • Can you please do one more edit and add the output of vgdisplay vgubuntu? – Terrance May 05 '22 at 13:40
  • Ah, I also missed something here. Your pvs states 0 free space. You need to extend out nvme0n1p2 partition size. See https://askubuntu.com/questions/877743/cannot-extend-lvm-partition?rq=1 – Terrance May 05 '22 at 15:37
  • Thanks Terrance. I just reinstalled my Ubuntu yesterday and it is working fine now. – Jeff0129 May 06 '22 at 03:52

3 Answers3

8

Looks like what you need is growpart. I'm not sure which steps you already did. Here is what I did on a similar machine:

Before storage expansion, this is what I have

root@agw:~# lsblk /dev/vda
NAME                 MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
vda                  252:0    0   20G  0 disk 
├─vda1               252:1    0    1M  0 part 
├─vda2               252:2    0  513M  0 part /boot/efi
└─vda3               252:3    0 19.5G  0 part 
  ├─vgxubuntu-root   253:0    0 18.5G  0 lvm  /
  └─vgxubuntu-swap_1 253:1    0  976M  0 lvm  [SWAP]

root@agw:~# vgs VG #PV #LV #SN Attr VSize VFree vgxubuntu 1 2 0 wz--n- 19.49g 0

I added 2G to the underlying disk. You'll see vda now has 22G of space, while vda3 is not automatically using all the space.

root@agw:~# lsblk /dev/vda
NAME                 MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
vda                  252:0    0   22G  0 disk 
├─vda1               252:1    0    1M  0 part 
├─vda2               252:2    0  513M  0 part /boot/efi
└─vda3               252:3    0 19.5G  0 part 
  ├─vgxubuntu-root   253:0    0 18.5G  0 lvm  /
  └─vgxubuntu-swap_1 253:1    0  976M  0 lvm  [SWAP]

root@agw:~# vgs VG #PV #LV #SN Attr VSize VFree vgxubuntu 1 2 0 wz--n- 19.49g 0

After expanding vda3, run lvextend and resize2fs (if you're on ext4).

root@agw:~# growpart /dev/vda 3
CHANGED: partition=3 start=1054720 old: size=40888287 end=41943007 new: size=45082591 end=46137311

root@agw:~# pvs PV VG Fmt Attr PSize PFree /dev/vda3 vgxubuntu lvm2 a-- 21.49g 2.00g

root@agw:~# lvextend -l+100%FREE /dev/vgxubuntu/root Size of logical volume vgxubuntu/root changed from <18.54 GiB (4746 extents) to <20.54 GiB (5258 extents). Logical volume vgxubuntu/root successfully resized.

root@agw:~# df -hPT / Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/vgxubuntu-root ext4 19G 11G 7.2G 59% /

root@agw:~# resize2fs /dev/mapper/vgxubuntu-root resize2fs 1.46.5 (30-Dec-2021) Filesystem at /dev/mapper/vgxubuntu-root is mounted on /; on-line resizing required old_desc_blocks = 3, new_desc_blocks = 3 The filesystem on /dev/mapper/vgxubuntu-root is now 5384192 (4k) blocks long.

root@agw:~# df -hPT / Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/vgxubuntu-root ext4 21G 11G 9.1G 53% /

xpk
  • 176
  • Works for me, but a little change. /dev/vda -> /dev/sda, /dev/vgxubuntu/root -> /dev/ubuntu-vg/ubuntu-lv, /dev/mapper/vgxubuntu-root -> /dev/mapper/ubuntu--vg-ubuntu--lv – Aincvy Jun 03 '23 at 02:32
3

You are close to extending it. The name we were looking for is what the LV Path states from the command of lvdisplay. LV Path shows the name as /dev/vgubuntu/root.

The command to extend it should be:

lvextend -l +100%FREE /dev/vgubuntu/root
Terrance
  • 41,612
  • 7
  • 124
  • 183
  • 1
    Yes I tried the name /dev/vgubuntu/root too. It showed the same output which could not extend beyond the 250GB size: New size (59246 extents) matches existing size (59246 extents). – Jeff0129 May 05 '22 at 03:52
0

You need to use pvresize

In this case pvresize /dev/nvme0n1p2

Then you should be able to resize the lv using the method you employed.