Managing Advanced Storage

Nov 13, 2025

Advanced Storage Solutions

Creating a Logical Volume

  1. Create a partition of type lvm
  2. Create physical volume with pvcreate /dev/partition
  3. Create volume group with vgcreate {vgroup} /dev/partition
    • Use the -s option to define a non standard extent size
  4. Create logical volume with lvcreate -n {lv} -L 1G {vgroup}
    • Use -l instead of -L to specify the number of extents
  5. Create a filesystem
  6. Use vgdisplay to get UUID and mount in fstab
    • Alternatively, use /dev/lvgname/lvname, as these don’t change like device names

Device Mapper and LVM Device Names

Wikipedia

Resizing LVM Logical Volumes

  • Use vgs to verify that the volume group has unused disk space
  • Use vgextend to add one or more PVs to the VG
  • Use lvextend -r -L +1G to grow the logical volume, including the filesystem it’s hosting (-r)
    • resize2fs is a resize utility for ext filesystems
    • xfs_growfs can be used to grow an XFS filesystem
    • lvextend -r -l +50%FREE will use half the available free extents
  • If the volume is mounted df -h will show the newly available space
    • Or vgs or vgdisplay

Reducing a Volume Group

RHEL

  • Use pvs to ensure that PFree > 0
  • Use pvmove to moved extents from the volume being removed to the remaining volumes(s)
  • Use vgreduce to complete the removal

Exercise

  1. Use fdisk to create 2 partitions, p1 and p2 for reference, with a size of 1G each and set the type to lvm
  2. Create a volume group, demo, including only the first partition, p1
  3. Add a logical volume, vol1, of 500M to the group
  4. Add the second partition, p2, to the volume group
  5. Extend the logical volume, vol1, using extents from the second partition
  6. Put an ext4 filesystem on the logical volume
  7. Mount vol1 to /mnt and use df -h to view
  8. Use dd if=/dev/zero of=/mnt/bigfile bs=1M count=1100 to ensure data is on both physical volumes
  9. Move all used extents from partition p2 to p1
  10. Print information for the physical volumes. Ensure that p2 is now unused.
  11. Remove p2 from the volume group
Solution
  1. fdisk
  2. vgcreate vgdemo /dev/p1
  3. lvcreate -n vol1 -L 500M
  4. vgextend vgdemo /dev/p2
  5. lvextend -n /dev/vgdemo/vol1 -L 250M /dev/p2
  6. mkfs.ext4 /dev/vgdemo/vol1
  7. mount /dev/vgdemo/vol1 /mnt
  8. dd if=/dev/zero of=/mnt/bigfile bs=1M count=550
  9. pvmove -v /dev/p2 /dev/p1
    • -v is for verbose, not required
  10. pvs
  11. vgreduce vgdemo /dev/p1

Stratis Pools

dnf install stratisd stratis-cli
systemctl enable --now stratisd
stratis pool create mypool /dev/partition1
stratis pool list
stratis pool add-data mypool /dev/partition2
stratis blockdev list
stratis fs create mypool myfs
stratis fs list
mkdir /myfs
lsblk --output=UUID /dev/stratis/mypool/myfs >> /etc/fstab

Modify /etc/fstab

UUID=... /myfs xfs defaults,x-systemd.requires=stratisd.service 0 0"

Stratis Snapshots

dd if=/dev/zero of=/myfs/bigfile bs=1M count=2000
stratis pool list
stratis fs list
stratis fs snapshot mypool myfs myfs-snap
stratis fs list
rm /myfs/bigfile
mkdir /myfs-snap
mount /dev/stratis/mypool/myfs-snap /myfs-snap
ls -l /myfs-snap
umount /myfs-snap
stratis fs destroy mypool myfs-snap

Knowledge Check

  1. What is the minimal size of a stratis volume?
  2. What filesystem must a stratus volume have?
  3. Is a stratis snapshot a backup?
  4. What is contained in a stratis snapshot?
  5. If a volume group contains 1 physical volume of size 1G, is it possible to create a logical volume of size 1G in that group? Why or why not?
Answers
  1. 4G
  2. XFS
  3. No, a snapshot is a metadata copy that allows you to access the state of the snapshot at any time. It differs from a backup in that if the original volume is destroyed, the snapshot is also lost.
  4. Metadata
  5. No. One extent will be used for metadata in the logical volume. If it is specified that the logical volume should be 1G (255 extents), then the underlying physical volume needs at least 256 extents. So create a physical volume slightly larger than 1G, eg 1028M, for a logical volume of exactly 1G.

Lab Exercise: LVM

  1. Create a logical volume 1G in size with the name lvdata.
  2. Format lvdata with the XFS filesystem and mount it persistently on /mounts/lvdata
  3. Increase the size of lvdata by 100 extents
  4. Add another physical volume to the volume group that lvdata belongs and add a second 500M logical volume, lvfiles
  5. Put an ext4 filesystem on lvfiles and mount it persistently to /mounts/lvfiles
  6. Copy all files from /etc/ that have a name starting with b, c, or g to /mounts/files
  7. Create a snapshot of lvfiles and delete all files from /mounts/lvfiles
  8. Verify that you can still access these files from the snapshot
  9. Recover the lvfiles volume from its snapshot
Solution
  1. vgcreate vgroup /dev/sdb1
    lvcreate vgroup -L 1G -n lvdata
  2. mkfs.xfs /dev/vgroup/lvdata
    # get UUID and add to /etc/fstab
  3. lvextend -r -l +100 -n vgroup/lvdata
  4. lvextend vgroup /dev/sdb2
    lvcreate vgroup -L 500M -n lvdata
  5. mkfs.ext4 /dev/vgroup/lvfiles
    # get UUID and add to /etc/fstab
  6. cp /etc/[bcg]* /mounts/lvfiles
  7. lvcreate --snapshot -L 500M -n lvfiles-snap vgroup/lvfiles
    rm -rf /mounts/lvfiles/*
  8. mount /dev/vgroup/lvfiles-snap /mnt
    ls -l /mnt
  9. umount /mounts/lvfiles
    umount /mnt
    lvconvert --merge /dev/vgroup/lvfiles-snap
    mount -a
    ls -l /mounts/lvfiles

Lab Exercise: Stratis

To perform these tasks, attach a 20G disk to your lab virtual machine

  • Create a 10G stratis pool with the attached disk, spool, containing 3 filesystems: files, programs, and stuff
  • Mount these filesystems persistently on /mounts/files, /mounts/programs/, and /mounts/stuff
  • Copy all files from /etc/ that have a name starting with b, c, or g to /mounts/files
  • Create a snapshot of the files filesystem
  • Delete all files from /mounts/files
  • Verify that you can still access these files from the snapshot

- Clint Jordan