11

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
  • 425
  • 7
  • 16
Jeff0129
  • 111

5 Answers5

19

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
  • 436
9

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
  • 43,712
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.

2

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

sajjadG
  • 647
0

Looks like you need to add the new volume to the volume group

so "vgextend vgubuntu /Your_new_volume/partition"

then use lvextend and after that, then grow the Filesystem

the steps I usually follow are,

  1. parted /dev/yourdiskname
  2. print # show the total disk size and find the end of the last partition
  3. mkpart.... create the new partition
  4. set New_partition_number lvm on # set the LVM flag
  5. exit parted "quit"
  6. partprobe # sync changes
  7. pvcreate /dev/new_partition_number
  8. vgextend your_vg /dev/new_volume/partition # add volume to volume group
  9. lvextend -l +100%FREE # to extend the logical volume
  10. xfs_growfs # to grow the filesystem if you using xfs

So basically, create a new partition/volume with the physical free space, extend the vggroup with the new volume, then extend the logical volume with the new free space in the vggroup