Click on each book below to review & buy on Amazon.
As an Amazon Associate, I earn from qualifying purchases.
RHCSA - Create & Configure File Systems: Extend Existing Logical Volumes
Extending Logical Volumes Overview
Logical Volume Management (LVM) is a flexible and powerful system for managing disk storage. It allows you to create, resize, and manage logical volumes (LVs) independently of the underlying physical storage devices. Extending logical volumes refers to the process of increasing the size of an existing logical volume to accommodate growing storage needs without disrupting data or applications.
Lesson Setup
To actively participate in the exercises, make sure to attach an additional empty disk to your system. While the exercises assume that the additional disk is 1G in size, feel free to use whatever disk size is available to you.
Do not use a disk with data on as following the exercises will mean that data will be deleted.
Once the disk is attached, you should be able to see it by running the lsblk
command, which in this example shows as the sdb
device:
After rebooting, the disk may not retain the same device name, making it essential to always run lsblk
to verify that you are working with the correct disk.
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 600M 0 part /boot/efi
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 17G 0 part
├─os_vg-root 253:0 0 15G 0 lvm /
└─os_vg-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 1G 0 disk
You will now need to create a volume group using the /dev/sdb
device, followed by creating a logical volume.
Wipe the /dev/sdb
disk clean if it has been used in previous lesson:
sudo wipefs --all /dev/sdb*
sudo dd if=/dev/zero of=/dev/sdb bs=1M
sudo sed -i '/\/dev\/sdb/d' /etc/lvm/devices/system.devices
Create volume group extend_vg
using disk /dev/sdb
:
sudo vgcreate extend_vg /dev/sdb
Physical volume "/dev/sdb" successfully created.
Volume group "extend_vg" successfully created
Confirm the volume group exists:
sudo vgs
VG #PV #LV #SN Attr VSize VFree
extend_vg 1 0 0 wz--n- 1020.00m 1020.00m
Create a logical volume of size 100MB called extend_lv
within volume group extend_vg
:
sudo lvcreate -L 100MB -n extend_lv extend_vg
Logical volume "extend_lv" created.
Confirm the logical volume was created using lvs
:
sudo lvs
The output shows the volume group of the logical volume and the size of the logical volume:
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
extend_lv extend_vg -wi-a----- 100.00m
Create an xfs
filesystem on, and mount the logical volume:
Create xfs
filesystem on logical volume extend_lv
:
sudo mkfs.xfs /dev/mapper/extend_vg-extend_lv
Mount logical volume to /mnt/extend
:
sudo mkdir -p /mnt/extend
sudo mount /dev/mapper/extend_vg-extend_lv /mnt/extend
Extending Logical Volumes
Volume Group Unallocated Space
Extending a logical volume requires available free space within the corresponding volume group. Begin by identifying the volume group housing the targeted logical volume, which can be accomplished using the lvs
command. Subsequently, utilize the vgs
command to ascertain whether the volume group possesses sufficient space to accommodate the extension.
Gather information on the logical volume and volume group:
Determine what volume group the extend_lv
logical volume resides in:
sudo lvs
Output shows that the extend_lv
logical volume belongs to volume group extend_vg
:
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
extend_lv extend_vg -wi-a----- 100.00m
Check there is free space in the extend_vg
volume group:
sudo vgs extend_vg
In this example, output shows 920.00m
free:
VG #PV #LV #SN Attr VSize VFree
extend_vg 1 1 0 wz--n- 1020.00m 920.00m
If, in your setup, you do not have any free space, follow lesson Assign Physical Volumes to Volume Groups which will show you how to extend the volume group.
Extending Logical Volume
Extending a logical volume involves the utilization of the lvextend
command. While some guides might suggest subsequent usage of dedicated resizing tools like resize2fs
for ext4 or xfs_growfs
for xfs file systems, a more streamlined approach can be adopted. By incorporating the -r
flag within the lvextend
command, you can optimize efficiency as it will automatically invoke the appropriate utility.
When utilizing the lvextend
command, the -L
option is employed to indicate sizes in bytes (K, M, G, etc.), while the -l
option is used for extents or percentages. Adding the +
symbol increments the size by the specified amount, whereas excluding it sets the logical volume to the exact size provided. In the forthcoming exercises, the focus will be on utilizing the -L
flag.
Extend logical volume just using lvextend
:
First, check df
output to see current size of the mounted logical volume:
df -h /mnt/extend
Output should show size of 95M:
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/extend_vg-extend_lv 95M 6.0M 89M 7% /mnt/extend
To extend a logical volume by 100M and resize the filesystem at the same time:
sudo lvextend -r -L +100M /dev/mapper/extend_vg-extend_lv
In the command output you can see that the command finds an xfs
filesystem and runs the appropriate resize utility, xfs_growfs
:
extend_lv
Size of logical volume extend_vg/extend_lv changed from 100.00 MiB (25 extents) to 200.00 MiB (50 extents).
File system xfs found on extend_vg/extend_lv mounted at /mnt/extend.
Extending file system xfs to 200.00 MiB (209715200 bytes) on extend_vg/extend_lv...
xfs_growfs /dev/extend_vg/extend_lv
meta-data=/dev/mapper/extend_vg-extend_lv isize=512 agcount=4, agsize=6400 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1 bigtime=1 inobtcount=1
data = bsize=4096 blocks=25600, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=1368, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 25600 to 51200
xfs_growfs done
Extended file system xfs on extend_vg/extend_lv.
Logical volume extend_vg/extend_lv successfully resized.
Confirm with df
that the extending of the logical volume was successful:
df -h /mnt/extend
This now displays 195M for the size:
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/extend_vg-extend_lv 195M 6.9M 188M 4% /mnt/extend
Extend logical volume using lvextend
then resize separately using xfs_growfs
:
First, check df
output to see current size of the mounted logical volume:
df -h /mnt/extend
Output should show size of 195M:
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/extend_vg-extend_lv 195M 6.9M 188M 4% /mnt/extend
To extend a logical volume by 50M, without resizing the filesystem:
sudo lvextend -L +50M /dev/mapper/extend_vg-extend_lv
The output shows logical volume being resized by now filesystem resizing:
Rounding size to boundary between physical extents: 52.00 MiB.
Size of logical volume extend_vg/extend_lv changed from 200.00 MiB (50 extents) to 252.00 MiB (63 extents).
Logical volume extend_vg/extend_lv successfully resized.
Confirm this by running df
again:
df -h /mnt/extend
Output should show size of 195M:
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/extend_vg-extend_lv 195M 6.9M 188M 4% /mnt/extend
Grow the filesystem using xfs_growfs
:
sudo xfs_growfs /mnt/extend
Output should show:
meta-data=/dev/mapper/extend_vg-extend_lv isize=512 agcount=8, agsize=6400 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1 bigtime=1 inobtcount=1
data = bsize=4096 blocks=51200, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=1368, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 51200 to 64512
Confirm the filesystem has now grown by 50M:
df -h /mnt/extend
Output should show:
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/extend_vg-extend_lv 247M 7.5M 240M 4% /mnt/extend
Lesson Tidy Up
So your attached drive can be used in future lessons, perform the following to wipe it clean:
Wipe the /dev/sdb
disk clean:
sudo vgremove -y extend_vg
sudo wipefs --all /dev/sdb*
sudo dd if=/dev/zero of=/dev/sdb bs=1M
sudo sed -i '/\/dev\/sdb/d' /etc/lvm/devices/system.devices
Support DTV Linux
Click on each book below to review & buy on Amazon. As an Amazon Associate, I earn from qualifying purchases.
NordVPN ®: Elevate your online privacy and security. Grab our Special Offer to safeguard your data on public Wi-Fi and secure your devices. I may earn a commission on purchases made through this link.