Lesson 4.4: Create and delete logical volumes
Create a Logical Volume (LV) inside the VG
Method I: Defining LV Size in MB, GB ...
[root@server dev]# lvcreate -n eduloan -L 400M loanvg Logical volume "eduloan" created. # Shortcut View of logical volume [root@server dev]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root cs -wi-ao---- 16.41g swap cs -wi-ao---- 2.00g eduloan loanvg -wi-a----- 400.00m # Full View of Logical volume eduloan [root@server dev]# lvdisplay /dev/loanvg/eduloan --- Logical volume --- LV Path /dev/loanvg/eduloan LV Name eduloan VG Name loanvg LV UUID IuJ01L-Vsxw-Tnz3-3YX7-0G3A-YCBV-hoFM0M LV Write Access read/write LV Creation host, time server, 2024-04-10 15:28:23 +0545 LV Status available # open 0 LV Size 400.00 MiB Current LE 25 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:2
Method I: Defining LV Size in terms of Number of PE's
[root@server dev]# lvcreate -n homeloan -l 50 loanvg Logical volume "homeloan" created. [root@server dev]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root cs -wi-ao---- 16.41g swap cs -wi-ao---- 2.00g eduloan loanvg -wi-a----- 400.00m homeloan loanvg -wi-a----- 800.00m
Format the newly created LV's with appropriate filesystem
# You can use mkfs -t xfs /dev/loanvg/eduloan also for this command [root@server dev]# mkfs.xfs /dev/loanvg/eduloan meta-data=/dev/loanvg/eduloan isize=512 agcount=4, agsize=25600 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=1, sparse=1, rmapbt=0 = reflink=1 bigtime=1 inobtcount=1 nrext64=0 data = bsize=4096 blocks=102400, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0, ftype=1 log =internal log bsize=4096 blocks=16384, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@server dev]# mkfs.xfs /dev/loanvg/vehicalloan Filesystem should be larger than 300MB. Log size should be at least 64MB. Support for filesystems like this one is deprecated and they will not be supported in future releases. meta-data=/dev/loanvg/vehicalloan isize=512 agcount=4, agsize=15360 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=1, sparse=1, rmapbt=0 = reflink=1 bigtime=1 inobtcount=1 nrext64=0 data = bsize=4096 blocks=61440, 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 [root@server dev]# mkfs.xfs /dev/loanvg/homeloan meta-data=/dev/loanvg/homeloan isize=512 agcount=4, agsize=51200 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=1, sparse=1, rmapbt=0 = reflink=1 bigtime=1 inobtcount=1 nrext64=0 data = bsize=4096 blocks=204800, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0, ftype=1 log =internal log bsize=4096 blocks=16384, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0
Mount the LV's
Temporary mounting the LV's
[root@server ~]# vim /etc/fstab # Insert the below line to make it permanent mount /dev/loanvg/eduloan /loans/edu xfs defaults 0 0 /dev/loanvg/vehicalloan /loans/vehical xfs defaults 0 0 /dev/loanvg/homeloan /loans/home xfs defaults 0 0 # Update the changes [root@server ~]# mount -a mount: (hint) your fstab has been modified, but systemd still uses the old version; use 'systemctl daemon-reload' to reload. [root@server ~]# systemctl daemon-reload [root@server ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sr0 11:0 1 1024M 0 rom nvme0n1 259:0 0 20G 0 disk ├─nvme0n1p1 259:1 0 600M 0 part /boot/efi ├─nvme0n1p2 259:2 0 1G 0 part /boot └─nvme0n1p3 259:3 0 18.4G 0 part ├─cs-root 253:0 0 16.4G 0 lvm / └─cs-swap 253:1 0 2G 0 lvm [SWAP] nvme0n2 259:4 0 5G 0 disk ├─nvme0n2p1 259:5 0 50M 0 part /data1 ├─nvme0n2p2 259:6 0 100M 0 part /data2 └─nvme0n2p3 259:7 0 1G 0 part [SWAP] nvme0n3 259:8 0 6G 0 disk ├─loanvg-eduloan 253:2 0 400M 0 lvm /loans/edu ├─loanvg-homeloan 253:3 0 800M 0 lvm /loans/home └─loanvg-vehicalloan 253:4 0 240M 0 lvm /loans/vehical
Extending an LV
[root@server ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sr0 11:0 1 1024M 0 rom nvme0n1 259:0 0 20G 0 disk ├─nvme0n1p1 259:1 0 600M 0 part /boot/efi ├─nvme0n1p2 259:2 0 1G 0 part /boot └─nvme0n1p3 259:3 0 18.4G 0 part ├─cs-root 253:0 0 16.4G 0 lvm / └─cs-swap 253:1 0 2G 0 lvm [SWAP] nvme0n2 259:4 0 5G 0 disk ├─nvme0n2p1 259:5 0 50M 0 part /data1 ├─nvme0n2p2 259:6 0 100M 0 part /data2 └─nvme0n2p3 259:7 0 1G 0 part [SWAP] nvme0n3 259:8 0 6G 0 disk ├─loanvg-eduloan 253:2 0 400M 0 lvm /loans/edu ├─loanvg-homeloan 253:3 0 800M 0 lvm /loans/home └─loanvg-vehicalloan 253:4 0 240M 0 lvm /loans/vehical # Checking the Free Space for VG [root@server ~]# vgs VG #PV #LV #SN Attr VSize VFree cs 1 2 0 wz--n- 18.41g 0 loanvg 1 3 0 wz--n- 5.98g <4.58g
If sufficient VG is free then , extending the LV
Method I : lvextend -L +<new size> <LV Name>
[root@server ~]# lvextend -L 300M /dev/loanvg/vehicalloan Rounding size to boundary between physical extents: 304.00 MiB. Size of logical volume loanvg/vehicalloan changed from 240.00 MiB (15 extents) to 304.00 MiB (19 extents). Logical volume loanvg/vehicalloan successfully resized. [root@server ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root cs -wi-ao---- 16.41g swap cs -wi-ao---- 2.00g eduloan loanvg -wi-ao---- 400.00m homeloan loanvg -wi-ao---- 800.00m vehicalloan loanvg -wi-ao---- 304.00m
Method II : lvextend -L +<size to be added> <LV Name>
[root@server ~]# lvextend -L +200M /dev/loanvg/vehicalloan Rounding size to boundary between physical extents: 208.00 MiB. Size of logical volume loanvg/vehicalloan changed from 304.00 MiB (19 extents) to 512.00 MiB (32 extents). Logical volume loanvg/vehicalloan successfully resized. [root@server ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root cs -wi-ao---- 16.41g swap cs -wi-ao---- 2.00g eduloan loanvg -wi-ao---- 400.00m homeloan loanvg -wi-ao---- 800.00m vehicalloan loanvg -wi-ao---- 512.00m
If the VG does not have sufficient space available then extend the VG by creating a new PV and extending VG
[root@server ~]# gdisk /dev/nvme0n2 GPT fdisk (gdisk) version 1.0.7 Partition table scan: MBR: protective BSD: not present APM: not present GPT: present Found valid GPT with protective MBR; using GPT. Command (? for help): p Disk /dev/nvme0n2: 10485760 sectors, 5.0 GiB Model: VMware Virtual NVMe Disk Sector size (logical/physical): 512/512 bytes Disk identifier (GUID): FA72ACD0-02EC-4442-B381-1BB02D112EAD Partition table holds up to 128 entries Main partition table begins at sector 2 and ends at sector 33 First usable sector is 34, last usable sector is 10485726 Partitions will be aligned on 2048-sector boundaries Total free space is 8081341 sectors (3.9 GiB) Number Start (sector) End (sector) Size Code Name 1 2048 104447 50.0 MiB 8300 Linux filesystem 2 104448 309247 100.0 MiB 8300 Linux filesystem 3 309248 2406399 1024.0 MiB 8200 Linux swap Command (? for help): n Partition number (4-128, default 4): First sector (34-10485726, default = 2406400) or {+-}size{KMGTP}: Last sector (2406400-10485726, default = 10485726) or {+-}size{KMGTP}: Current type is 8300 (Linux filesystem) Hex code or GUID (L to show codes, Enter = 8300): 8e00 Changed type of partition to Linux LVM Command (? for help): p Disk /dev/nvme0n2: 10485760 sectors, 5.0 GiB Model: VMware Virtual NVMe Disk Sector size (logical/physical): 512/512 bytes Disk identifier (GUID): FA72ACD0-02EC-4442-B381-1BB02D112EAD Partition table holds up to 128 entries Main partition table begins at sector 2 and ends at sector 33 First usable sector is 34, last usable sector is 10485726 Partitions will be aligned on 2048-sector boundaries Total free space is 2014 sectors (1007.0 KiB) Number Start (sector) End (sector) Size Code Name 1 2048 104447 50.0 MiB 8300 Linux filesystem 2 104448 309247 100.0 MiB 8300 Linux filesystem 3 309248 2406399 1024.0 MiB 8200 Linux swap 4 2406400 10485726 3.9 GiB 8E00 Linux LVM Command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): y OK; writing new GUID partition table (GPT) to /dev/nvme0n2. Warning: The kernel is still using the old partition table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) The operation has completed successfully. [root@server ~]# pvs PV VG Fmt Attr PSize PFree /dev/nvme0n1p3 cs lvm2 a-- 18.41g 0 /dev/nvme0n2p4 lvm2 --- 3.85g 3.85g /dev/nvme0n3 loanvg lvm2 a-- 5.98g 4.31g [root@server ~]# vgs VG #PV #LV #SN Attr VSize VFree cs 1 2 0 wz--n- 18.41g 0 loanvg 1 3 0 wz--n- 5.98g 4.31g # Extending the VG [root@server ~]# vgextend loanvg /dev/nvme0n2p4 Volume group "loanvg" successfully extended [root@server ~]# pvs PV VG Fmt Attr PSize PFree /dev/nvme0n1p3 cs lvm2 a-- 18.41g 0 /dev/nvme0n2p4 loanvg lvm2 a-- 3.84g 3.84g /dev/nvme0n3 loanvg lvm2 a-- 5.98g 4.31g [root@server ~]# vgs VG #PV #LV #SN Attr VSize VFree cs 1 2 0 wz--n- 18.41g 0 loanvg 2 3 0 wz--n- <9.83g <8.16g # Extended [root@server ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root cs -wi-ao---- 16.41g swap cs -wi-ao---- 2.00g eduloan loanvg -wi-ao---- 400.00m homeloan loanvg -wi-ao---- 800.00m vehicalloan loanvg -wi-ao---- 512.00m [root@server ~]# lvextend +100M /dev/loanvg/vehicalloan Volume group "+100M" not found Cannot process volume group +100M [root@server ~]# lvextend -L +100M /dev/loanvg/vehicalloan Rounding size to boundary between physical extents: 112.00 MiB. Size of logical volume loanvg/vehicalloan changed from 512.00 MiB (32 extents) to 624.00 MiB (39 extents). Logical volume loanvg/vehicalloan successfully resized. [root@server ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root cs -wi-ao---- 16.41g swap cs -wi-ao---- 2.00g eduloan loanvg -wi-ao---- 400.00m homeloan loanvg -wi-ao---- 800.00m vehicalloan loanvg -wi-ao---- 624.00m
Here you can see that eduloan, homeloan and vehicalloan LV size has been extended using the lvextend
command but still the df -h
does not show the actual size in the process.
So, we need to do _growfs
[root@server ~]# lvextend -L +100M /dev/loanvg/eduloan Rounding size to boundary between physical extents: 112.00 MiB. Size of logical volume loanvg/eduloan changed from 512.00 MiB (32 extents) to 624.00 MiB (39 extents). Logical volume loanvg/eduloan successfully resized. [root@server ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 4.0M 0 4.0M 0% /dev tmpfs 1.8G 0 1.8G 0% /dev/shm tmpfs 717M 9.4M 708M 2% /run /dev/mapper/cs-root 17G 5.8G 11G 35% / /dev/nvme0n2p1 42M 14K 39M 1% /data1 /dev/nvme0n2p2 89M 14K 82M 1% /data2 /dev/nvme0n1p2 960M 481M 480M 51% /boot /dev/nvme0n1p1 599M 7.0M 592M 2% /boot/efi tmpfs 359M 100K 359M 1% /run/user/1000 /dev/mapper/loanvg-eduloan 448M 24M 425M 6% /loans/edu /dev/mapper/loanvg-vehicalloan 619M 17M 602M 3% /loans/vehical /dev/mapper/loanvg-homeloan 944M 39M 906M 5% /loans/home [root@server ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root cs -wi-ao---- 16.41g swap cs -wi-ao---- 2.00g eduloan loanvg -wi-ao---- 624.00m homeloan loanvg -wi-ao---- 1008.00m vehicalloan loanvg -wi-ao---- 624.00m # If filesystem is in xfs use xfs_growfs , else use resize2fs [root@server ~]# xfs_growfs /dev/loanvg/eduloan meta-data=/dev/mapper/loanvg-eduloan isize=512 agcount=6, agsize=25600 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=1, sparse=1, rmapbt=0 = reflink=1 bigtime=1 inobtcount=1 nrext64=0 data = bsize=4096 blocks=131072, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0, ftype=1 log =internal log bsize=4096 blocks=16384, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 131072 to 159744 [root@server ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 4.0M 0 4.0M 0% /dev tmpfs 1.8G 0 1.8G 0% /dev/shm tmpfs 717M 9.4M 708M 2% /run /dev/mapper/cs-root 17G 5.8G 11G 35% / /dev/nvme0n2p1 42M 14K 39M 1% /data1 /dev/nvme0n2p2 89M 14K 82M 1% /data2 /dev/nvme0n1p2 960M 481M 480M 51% /boot /dev/nvme0n1p1 599M 7.0M 592M 2% /boot/efi tmpfs 359M 100K 359M 1% /run/user/1000 /dev/mapper/loanvg-eduloan 560M 25M 536M 5% /loans/edu /dev/mapper/loanvg-vehicalloan 619M 17M 602M 3% /loans/vehical /dev/mapper/loanvg-homeloan 944M 39M 906M 5% /loans/home
Properly unmounting and removing lv and vg
# Unmount [root@sanjeeb ~]# umount /dev/loanvg/eduloanlv [root@sanjeeb ~]# umount /dev/loanvg/vehicalloanlv [root@sanjeeb ~]# umount /dev/loanvg/homeloanlv # LV Remove [root@sanjeeb ~]# lvremove /dev/loanvg/eduloanlv Do you really want to remove active logical volume loanvg/eduloanlv? [y/n]: y Logical volume "eduloanlv" successfully removed. [root@sanjeeb ~]# lvremove /dev/loanvg/vehicalloanlv Do you really want to remove active logical volume loanvg/vehicalloanlv? [y/n]: y Logical volume "vehicalloanlv" successfully removed. [root@sanjeeb ~]# lvremove /dev/loanvg/homeloanlv Do you really want to remove active logical volume loanvg/homeloanlv? [y/n]: y Logical volume "homeloanlv" successfully removed. # VG Remove [root@sanjeeb ~]# vgremove loanvg Volume group "loanvg" successfully removed # Delete all the partitions of a disk using gdisk # Before deleting also check if it has files or not. # Also check if it is for a SWAP space. If swap, then swapoff it and remove # Then use wipefs -all <partition name> , to remove all it's cache. [root@sanjeeb ~]# wipefs --all /dev/nvme0n2 /dev/nvme0n2: 8 bytes were erased at offset 0x00000200 (gpt): 45 46 49 20 50 41 52 54 /dev/nvme0n2: 8 bytes were erased at offset 0x13ffffe00 (gpt): 45 46 49 20 50 41 52 54 /dev/nvme0n2: 2 bytes were erased at offset 0x000001fe (PMBR): 55 aa /dev/nvme0n2: calling ioctl to re-read partition table: Success
STRATIS
Install Required Package
# List the stratis packages [root@server ~]# yum list *stratis* Last metadata expiration check: 0:00:16 ago on Sun 14 Apr 2024 05:36:50 PM +0545. Available Packages stratis-cli.noarch 3.6.0-1.el9 appstream stratisd.aarch64 3.6.2-1.el9 appstream stratisd-dracut.aarch64 3.6.2-1.el9 appstream stratisd-tools.aarch64 3.6.2-1.el9 appstream # Install stratis-cli & stratisd [root@server ~]# yum install stratis-cli [root@server ~]# yum install stratisd
Start the stratis service
[root@server ~]# systemctl start stratisd [root@server ~]# systemctl status stratisd ● stratisd.service - Stratis daemon Loaded: loaded (/usr/lib/systemd/system/stratisd.service; enabled; preset: enabled) Active: active (running) since Sun 2024-04-14 17:40:04 +0545; 9s ago Docs: man:stratisd(8) Main PID: 42323 (stratisd) Tasks: 6 (limit: 22580) Memory: 1.8M CPU: 20ms CGroup: /system.slice/stratisd.service └─42323 /usr/libexec/stratisd --log-level debug Apr 14 17:40:04 server systemd[1]: Starting Stratis daemon... Apr 14 17:40:04 server stratisd[42323]: [2024-04-14T11:55:04Z INFO stratisd::stratis::run] stratis daemon version 3.6.2 st> Apr 14 17:40:04 server stratisd[42323]: [2024-04-14T11:55:04Z INFO stratisd::stratis::run] Using StratEngine Apr 14 17:40:04 server stratisd[42323]: [2024-04-14T11:55:04Z INFO stratisd::engine::strat_engine::liminal::identify] Begi> Apr 14 17:40:04 server systemd[1]: Started Stratis daemon. Apr 14 17:40:04 server stratisd[42323]: [2024-04-14T11:55:04Z INFO stratisd::stratis::ipc_support::dbus_support] D-Bus API> lines 1-17/17 (END) [root@server ~]# systemctl enable stratisd
Creaitng Stratis pool & Stratis file system (Thin-Provisioned File System)
# Creating a stratis pool named loanpool [root@server ~]# stratis pool create loanpool /dev/nvme0n5 # Listing the created pool [root@server ~]# stratis pool list Name Total / Used / Free Properties UUID Alerts loanpool 5 GiB / 526 MiB / 4.49 GiB ~Ca,~Cr, Op aee99185-7f55-4e1c-85b0-61754749d3d4 WS001 # Increasing space in stratis pool [root@server ~]# stratis pool add-data loanpool /dev/nvme0n6 [root@server ~]# stratis pool list Name Total / Used / Free Properties UUID Alerts loanpool 7 GiB / 530 MiB / 6.48 GiB ~Ca,~Cr, Op aee99185-7f55-4e1c-85b0-61754749d3d4
Create Thin-Provisioned stratis file system
# Listing the filesystems [root@server ~]# stratis filesystem list Pool Filesystem Total / Used / Free / Limit Created Device UUID # Creating the filesystems for loanpool # No need to specify the size as it is thin-provisioned and automatically grows [root@server ~]# stratis filesystem create loanpool eduloanfs [root@server ~]# stratis filesystem create loanpool homeloanfs # Listing the filesystems [root@server ~]# stratis filesystem list Pool Filesystem Total / Used / Free / Limit Created Device UUID loanpool eduloanfs 1 TiB / 546 MiB / 1023.47 GiB / None Apr 14 2024 19:58 /dev/stratis/loanpool/eduloanfs aae43f0d-6a4a-4bc8-b1ca-aafece6dd2f6 loanpool homeloanfs 1 TiB / 546 MiB / 1023.47 GiB / None Apr 14 2024 19:58 /dev/stratis/loanpool/homeloanfs 91b8c1d5-30ee-4b73-bf8e-cddbf8b26ad2 # In the above we can see total 1TiB, this is the maximum limitation of the filesystem
The built-in filesystem in the stratis filesystem is XFS
Mounting the stratis filesystem
# Temporary Mounting [root@server ~]# mount /dev/stratis/loanpool/eduloanfs /loans/stratis/eduloan [root@server ~]# mount /dev/stratis/loanpool/homeloanfs /loans/stratis/homeloan/ [root@server ~]# df -h Filesystem Size Used Avail Use% Mounted on ... /dev/mapper/stratis-1-aee991857f554e1c85b061754749d3d4-thin-fs-aae43f0d6a4a4bc8b1caaafece6dd2f6 1.0T 7.2G 1017G 1% /loans/stratis/eduloan /dev/mapper/stratis-1-aee991857f554e1c85b061754749d3d4-thin-fs-91b8c1d530ee4b73bf8ecddbf8b26ad2 1.0T 7.2G 1017G 1% /loans/stratis/homeloan # Permanent Mounting [root@sanjeeb ~]# cat /etc/fstab /dev/stratis/loanpool/eduloanfs /root/stratis/edu xfs defaults,x-systemd.requires=stratisd.service 0 0 /dev/stratis/loanpool/homeloanfs /root/stratis/home xfs defaults,x-systemd.required=stratisd.service 0 0 [root@sanjeeb ~]# systemctl daemon-reload [root@sanjeeb ~]# mount -a
Removing the stratis filesystem & stratis pool
# Removing the stratis filesystem [root@server ~]# stratis fs destroy loanpool eduloanfs [root@server ~]# stratis fs destroy loanpool homeloanfs # Removing the stratis pool [root@server ~]# stratis pool destroy loanpool