In Part 1, we have allocated free space of Virtual Disk 1, to existing volume group by creating new partition from same disk. However, we may run in scenario where whole disk 1 is fully utilized and we need to add second disk for arranging free space for logical volumes. Some use cases, like syslog servers where new files are stored daily and old data cannot be removed means we need to add more disks instead of cleaning existing.
For this blog, hence we will be covering scenario 2, where I added a new 50G disk to my same Ubuntu 20.04 machine.
Step 1
Verify new block details added to system.
root@lxubuntu20:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 252:0 0 50G 0 disk
├─vda1 252:1 0 1M 0 part
├─vda2 252:2 0 1G 0 part /boot
├─vda3 252:3 0 9G 0 part
│ ├─ubuntu--vg-ubuntu--lv--root 253:0 0 14G 0 lvm /
│ ├─ubuntu--vg-ubuntu--lv--var 253:1 0 12G 0 lvm /var
│ └─ubuntu--vg-ubuntu--lv--home 253:2 0 13G 0 lvm /home
└─vda4 252:4 0 40G 0 part
├─ubuntu--vg-ubuntu--lv--root 253:0 0 14G 0 lvm /
├─ubuntu--vg-ubuntu--lv--var 253:1 0 12G 0 lvm /var
└─ubuntu--vg-ubuntu--lv--home 253:2 0 13G 0 lvm /
vdb 252:16 0 50G 0 disk
We can see additional disk is now reflected as vdb in my existing block list. This disk however, is neither mounted nor part of any volume group.
Step 2
We first need to create new partition for this disk using fdisk utility as used in Part 1.
root@lxubuntu20:~# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x3df5387a.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p):
Using default response p.
Partition number (1-4, default 1): 1
First sector (2048-104857599, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-104857599, default 104857599):
Created a new partition 1 of type 'Linux' and of size 50 GiB.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
Verify newly created partition using lsblk again.
root@lxubuntu20:~# lsblk /dev/vdb
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vdb 252:16 0 50G 0 disk
└─vdb1 252:17 0 50G 0 part
Step 3
Next, we need to add this 50G partition from second disk in our existing volume group using vgextend <volume-group> <new-partition>
root@lxubuntu20:~# vgextend ubuntu-vg /dev/vdb1
Physical volume "/dev/vdb1" successfully created.
Volume group "ubuntu-vg" successfully extended
Verify new free space now available in volume group.
root@lxubuntu20:~# vgs
VG #PV #LV #SN Attr VSize VFree
ubuntu-vg 3 3 0 wz--n- <98.99g 59.99g
Step 4
We can now allocate 20G to our three logical volumes viz. var, home and root using lvresize -L +(Size) <logical volume>
root@lxubuntu20:~# lvresize -L +20G /dev/mapper/ubuntu--vg-ubuntu--lv--root
Size of logical volume ubuntu-vg/ubuntu-lv-root changed from <14.00 GiB (3583 extents) to <34.00 GiB (8703 extents).
Logical volume ubuntu-vg/ubuntu-lv-root successfully resized.
root@lxubuntu20:~# lvresize -L +20G /dev/mapper/ubuntu--vg-ubuntu--lv--var
Size of logical volume ubuntu-vg/ubuntu-lv-var changed from 12.00 GiB (3072 extents) to 32.00 GiB (8192 extents).
Logical volume ubuntu-vg/ubuntu-lv-var successfully resized.
root@lxubuntu20:~# lvresize -L +20G /dev/mapper/ubuntu--vg-ubuntu--lv--home
Insufficient free space: 5120 extents needed, but only 5118 available
Check here, we have allocated 20G to /root and /var successfully but faced error for /home. This is not related to method but we actually ran out of blocks for allocations.
Verify from vgs to find out available free space in this volume group.
root@lxubuntu20:~# vgs
VG #PV #LV #SN Attr VSize VFree
ubuntu-vg 3 3 0 wz--n- <98.99g 19.99g
Since we don’t have full 20G free space, we try to allocate 19G to home.
root@lxubuntu20:~# lvresize -L +19G /dev/mapper/ubuntu--vg-ubuntu--lv--home
Size of logical volume ubuntu-vg/ubuntu-lv-home changed from 13.00 GiB (3328 extents) to 32.00 GiB (8192 extents).
Logical volume ubuntu-vg/ubuntu-lv-home successfully resized.
Command executed successfully this time for /home as well.
Step 5
Post Step 4, we re run xfs_growfs for allocations to be added in file system.
root@lxubuntu20:~# xfs_growfs /dev/mapper/ubuntu--vg-ubuntu--lv--var
meta-data=/dev/mapper/ubuntu--vg-ubuntu--lv--var isize=512 agcount=24, agsize=131072 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=3145728, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 3145728 to 8388608
root@lxubuntu20:~# xfs_growfs /dev/mapper/ubuntu--vg-ubuntu--lv--home
meta-data=/dev/mapper/ubuntu--vg-ubuntu--lv--home isize=512 agcount=18, agsize=196608 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=3407872, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 3407872 to 8388608
root@lxubuntu20:~# xfs_growfs /dev/mapper/ubuntu--vg-ubuntu--lv--root
meta-data=/dev/mapper/ubuntu--vg-ubuntu--lv--root isize=512 agcount=15, agsize=261888 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=3668992, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 3668992 to 8911872
Verify new block information and their mount point.
root@lxubuntu20:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 252:0 0 50G 0 disk
├─vda1 252:1 0 1M 0 part
├─vda2 252:2 0 1G 0 part /boot
├─vda3 252:3 0 9G 0 part
│ ├─ubuntu--vg-ubuntu--lv--root 253:0 0 34G 0 lvm /
│ ├─ubuntu--vg-ubuntu--lv--var 253:1 0 32G 0 lvm /var
│ └─ubuntu--vg-ubuntu--lv--home 253:2 0 32G 0 lvm /home
└─vda4 252:4 0 40G 0 part
├─ubuntu--vg-ubuntu--lv--root 253:0 0 34G 0 lvm /
├─ubuntu--vg-ubuntu--lv--var 253:1 0 32G 0 lvm /var
└─ubuntu--vg-ubuntu--lv--home 253:2 0 32G 0 lvm /home
vdb 252:16 0 50G 0 disk
└─vdb1 252:17 0 50G 0 part
├─ubuntu--vg-ubuntu--lv--root 253:0 0 34G 0 lvm /
├─ubuntu--vg-ubuntu--lv--var 253:1 0 32G 0 lvm /var
└─ubuntu--vg-ubuntu--lv--home 253:2 0 32G 0 lvm /home
We can check our three logical volumes mounted on /var, /home and /root across different virtual disks and partitions. Verify new utilization as below,
root@lxubuntu20:~# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-ubuntu--lv--root xfs 34G 2.1G 32G 6% /
/dev/mapper/ubuntu--vg-ubuntu--lv--home xfs 32G 264M 32G 1% /home
/dev/mapper/ubuntu--vg-ubuntu--lv--var xfs 32G 1.1G 31G 4% /var