AlmaLinux is a free, open-source Linux distribution based on the Red Hat Enterprise Linux (RHEL) operating system. Logical Volume Management (LVM) is a powerful storage management tool that allows you to create and manage logical volumes on top of physical volumes. In this tutorial, we will walk through the steps to configure and manage storage devices in AlmaLinux using LVM.
Step 1: Check for new disks
First, we need to check if there are any new disks available on the system. You can use the following command to list all the disks available on your system.
sudo fdisk -l
If you see any new disks listed, take note of their device names (e.g. /dev/sdb).
Step 2: Partition the disks
Once you have identified the new disks, you need to partition them using the fdisk command. Here’s an example command to partition /dev/sdb:
sudo fdisk /dev/sdb
Follow the prompts to create a new partition on the disk.
Step 3: Create physical volumes
Once you have partitioned the disks, you need to create physical volumes (PVs) on them using the pvcreate
command. Here’s an example command to create a physical volume on /dev/sdb1:
sudo pvcreate /dev/sdb1
Repeat this command for each new partition that you created in Step 2.
Step 4: Create a volume group
Next, you need to create a volume group (VG) using the vgcreate
command. Here’s an example command to create a volume group named “my_vg” using the physical volume we created in Step 3:
sudo vgcreate my_vg /dev/sdb1
You can add multiple physical volumes to a volume group by specifying their device names after the volume group name.
Step 5: Create logical volumes
Finally, you can create logical volumes (LVs) on the volume group using the lvcreate
command. Here’s an example command to create a logical volume named “my_lv” with a size of 10GB on the “my_vg” volume group:
sudo lvcreate -L 10G -n my_lv my_vg
You can create multiple logical volumes on a single volume group.
Step 6: Format the logical volumes
Now that you have created logical volumes, you need to format them with a filesystem using the mkfs
command. Here’s an example command to format the “my_lv” logical volume with the ext4 filesystem:
sudo mkfs.ext4 /dev/my_vg/my_lv
Step 7: Mount the logical volumes
Finally, you can mount the logical volumes to a directory on your system using the mount
command. Here’s an example command to mount the “my_lv” logical volume to the /mnt/my_lv directory:
sudo mount /dev/my_vg/my_lv /mnt/my_lv
To make the mount persistent across reboots, you can add an entry to the /etc/fstab file. For example:
/dev/my_vg/my_lv /mnt/my_lv ext4 defaults 0 0
That’s it! You have now configured and managed storage devices in AlmaLinux using LVM.