Skip to content

Instantly share code, notes, and snippets.

@latuminggi
Last active November 20, 2024 03:59
Show Gist options
  • Save latuminggi/0e51b419ae07c2358713a9ed9f23a9b0 to your computer and use it in GitHub Desktop.
Save latuminggi/0e51b419ae07c2358713a9ed9f23a9b0 to your computer and use it in GitHub Desktop.
Add a Disk to Expand Storage of Existing LVM
### This walkthrough has been tested on Ubuntu Linux 22.04 LTS for xfs filesystem
### Reference: https://www.cyberciti.biz/faq/howto-add-disk-to-lvm-volume-on-linux-to-increase-size-of-pool
# df -h | grep -v tmpfs
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VG_SERVER-LV_ROOT 45G 7.9G 38G 18% /
/dev/sda2 974M 374M 533M 42% /boot
# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
LV_ROOT VG_SERVER -wi-ao---- <45.00g
LV_SWAP VG_SERVER -wi-ao---- 4.00g
# lvmdiskscan
/dev/sda2 [ 1.00 GiB]
/dev/sda3 [ <49.00 GiB] LVM physical volume
/dev/sdb [ 500.00 GiB]
1 disk
0 LVM physical volume whole disks
1 LVM physical volume
# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created.
# lvmdiskscan -l
WARNING: only considering LVM devices
/dev/sda3 [ <49.00 GiB] LVM physical volume
/dev/sdb [ 500.00 GiB] LVM physical volume
1 LVM physical volume whole disk
1 LVM physical volume
# vgextend VG_SERVER /dev/sdb
Volume group "VG_SERVER" successfully extended
# lvm lvextend -l +100%FREE /dev/VG_SERVER/LV_ROOT
Size of logical volume VG_SERVER/LV_ROOT changed from <45.00 GiB (11519 extents) to 544.99 GiB (139518 extents).
Logical volume VG_SERVER/LV_ROOT successfully resized.
# mount | grep '/dev/mapper'
/dev/mapper/VG_SERVER-LV_ROOT on / type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
# xfs_growfs /dev/mapper/VG_SERVER-LV_ROOT
meta-data=/dev/mapper/VG_SERVER-LV_ROOT isize=512 agcount=4, agsize=2948864 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1 bigtime=0 inobtcount=0
data = bsize=4096 blocks=11795456, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=5759, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 11795456 to 142866432
# df -h | grep -v tmpfs
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VG_SERVER-LV_ROOT 545G 12G 534G 3% /
/dev/sda2 974M 374M 533M 42% /boot
### This walkthrough has been tested on Ubuntu Linux 22.04 LTS for ext4 filesystem
# df -h | grep -v tmpfs
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-ubuntu--lv 24G 6.9G 16G 31% /
/dev/sda2 2.0G 125M 1.7G 7% /boot
# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
ubuntu-lv ubuntu-vg -wi-ao---- <24.00g
# lvmdiskscan
/dev/nvme0n1 [ 50.00 GiB]
/dev/sda2 [ 2.00 GiB]
/dev/sda3 [ <48.00 GiB] LVM physical volume
0 disks
0 LVM physical volume whole disks
1 LVM physical volume
# pvcreate /dev/nvme0n1
Physical volume "/dev/nvme0n1" successfully created.
# lvmdiskscan -l
WARNING: only considering LVM devices
/dev/nvme0n1 [ 50.00 GiB] LVM physical volume
/dev/sda3 [ <48.00 GiB] LVM physical volume
0 LVM physical volume whole disks
2 LVM physical volumes
# vgextend ubuntu-vg /dev/nvme0n1
Volume group "ubuntu-vg" successfully extended
# lvm lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
Size of logical volume ubuntu-vg/ubuntu-lv changed from <24.00 GiB (6143 extents) to 97.99 GiB (25086 extents).
Logical volume ubuntu-vg/ubuntu-lv successfully resized.
# mount | grep '/dev/mapper'
/dev/mapper/ubuntu--vg-ubuntu--lv on / type ext4 (rw,relatime)
# resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
resize2fs 1.46.5 (30-Dec-2021)
Filesystem at /dev/mapper/ubuntu--vg-ubuntu--lv is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 13
The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 25688064 (4k) blocks long.
# df -h | grep -v tmpfs
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-ubuntu--lv 97G 6.9G 86G 8% /
/dev/sda2 2.0G 125M 1.7G 7% /boot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment