8

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?

5
  • 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
    Commented May 5, 2022 at 3:15
  • Hi Terrance, done. Thanks.
    – Jeff0129
    Commented May 5, 2022 at 3:28
  • Can you please do one more edit and add the output of vgdisplay vgubuntu?
    – Terrance
    Commented May 5, 2022 at 13:40
  • Ah, I also missed something here. Your pvs states 0 free space. You need to extend out nvme0n1p2 partition size. See askubuntu.com/questions/877743/cannot-extend-lvm-partition?rq=1
    – Terrance
    Commented May 5, 2022 at 15:37
  • Thanks Terrance. I just reinstalled my Ubuntu yesterday and it is working fine now.
    – Jeff0129
    Commented May 6, 2022 at 3:52

4 Answers 4

12

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% / 
1
  • 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
    Commented Jun 3, 2023 at 2:32
6

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
1
  • 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
    Commented May 5, 2022 at 3:52
2

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.

0

There's two way to increase a LVM partition:

Solution A: Extending the partition in the VG

  1. Resize the disk and reboot the VM/Machine in order for OS to detect the new disk size (Depending on your hypervisors, there may also be other ways to do that without reboot)

  2. Resize Existing Partition

fdisk /dev/sda
* d
* n
* enter
* enter
* enter
* N
* p
* w
  1. Increase LV size by resizing PV and extending LV
pvresize /dev/sda3
lvextend -l+100%FREE /dev/ubuntu-vg/ubuntu-lv

Solution B: Creating new partition and adding it to the VG

  1. Resize the disk and reboot the VM/Machine in order for OS to detect the new disk size (Depending on your hypervisors, there may also be other ways to do that without reboot)

  2. Partition the new disk space

fdisk /dev/sda
* n
* p
* enter
* enter
* enter
* t
* enter
* 8e
* w
  1. Increasing the logical volume by adding the new disk to the VG
partprobe
pvcreate /dev/sda3
vgdisplay |grep 'VG Name' ### you need the name of the VG Name for the next cmd
pvscan ### you can check the physical volumes with this command
vgextend centos /dev/sda3
lvdisplay ### find the name of the logical volume you want to extend
lvextend /dev/centos/root /dev/sda3
xfs_growfs /dev/centos/root

Online Disk Size Change Detection

There some solution that may work to detect extended disk size without restart. It depends on your Hypervisor and OS. So it may not work for you. Give it a try and if it did not work reboot the OS. Reboot always work.

Try 1

echo "- - -" > /sys/class/scsi_host/host0/scan
echo "- - -" | sudo tee /sys/class/scsi_host/host1/scan

note that you should replace host0 with the correct option.

Try 2

lsscsi
cat /proc/scsi/scsi

you can check if the space has been detected by the OS with fdisk -l or lsblk

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .