Add new HDD to LVM group

First step: use gdisk (or fdisk)

#gdisk /dev/sdb
and select part code 8e00 -  LVM partition

we need to prepare our new partitions for LVM 

#pvcreate /dev/sdb1

Check pvs
#pvdisplay

Second step: extends the logical partition as far as it can. No need to check and calculate GBs or blocks in various methods.

#vgextend /dev/ubuntu-vg /dev/sdb1

Third step: Extent the logical to max of new extented VG 

#lvresize -l +100%FREE /dev/ubuntu-vg/ubuntu-lv

Step 4 extends the file system to the size of the logical partition.
#resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv

PS: On Ubuntu 18.04 I have to reboot or remount (mount-a) to update the full new space

Test:
Let’s shrink it to 10GB again:

#lvreduce -L10G /dev/ubuntu-vg/ubuntu-lv

#lvdisplay

— Logical volume —
LV Path /dev/ubuntu-vg/ubuntu-lv
LV Name ubuntu-lv
VG Name ubuntu-vg
LV UUID 3SfTpe-ZyKo-UDLI-2JRM-VTbP-GL0D-4cMyi6
LV Write Access read/write
LV Creation host, time ubuntu-server, 2018-08-14 04:30:49 +0000
LV Status available
# open 1
LV Size 10.00 GiB
Current LE 2560
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:0

Try another 10GB

#lvreduce -L10G /dev/ubuntu-vg/ubuntu-lv

#lvdisplay

— Logical volume —
LV Path /dev/ubuntu-vg/ubuntu-lv
LV Name ubuntu-lv
VG Name ubuntu-vg
LV UUID 3SfTpe-ZyKo-UDLI-2JRM-VTbP-GL0D-4cMyi6
LV Write Access read/write
LV Creation host, time ubuntu-server, 2018-08-14 04:30:49 +0000
LV Status available
# open 1
LV Size 10.00 GiB
Current LE 2560
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:0

Leave a Reply