Logical Volume Management (LVM) is a powerful and flexible storage management solution used in Linux distributions like Rocky Linux. LVM allows users to manage multiple physical storage devices as a single logical unit, providing increased ease of management and better performance. This blog post will guide you through the process of how to manage LVM volumes on Rocky Linux, covering essential concepts, creation, and management of LVM volumes.
What is LVM?
LVM is a storage management tool that simplifies the process of managing disk partitions. It provides a more flexible and efficient way of managing storage compared to traditional partitioning methods. LVM allows you to create, resize, and delete logical volumes without rebooting the system, and it also supports advanced features such as snapshots and mirroring.
How to Manage LVM Volumes on Rocky Linux
Creating LVM Volumes
Before we dive into LVM management, let’s take a look at the basic structure of LVM volumes:
- Physical Volumes (PVs): Physical storage devices, such as hard disks or SSDs, are divided into PVs.
- Volume Groups (VGs): PVs are combined to form VGs, which act as storage pools.
- Logical Volumes (LVs): You can create LVs from the available space in VGs, and these LVs are used as filesystems or swap partitions.
Now that we’ve covered the basics, let’s create an LVM volume.
Create Physical Volumes
First, identify the disks you want to include in your LVM volume using the lsblk
command. Then, create a physical volume on each disk using the pvcreate
command:
sudo pvcreate /dev/sdb /dev/sdc
Create a Volume Group
Next, create a volume group using the vgcreate
command. In this example, we’ll create a VG called “my_vg” using the physical volumes we just created:
sudo vgcreate my_vg /dev/sdb /dev/sdc
Create Logical Volumes
Finally, create a logical volume within the volume group using the lvcreate
command. In this example, we’ll create a 100GB LV called “my_lv”:
sudo lvcreate -L 100G -n my_lv my_vg
Managing LVM Volumes
Now that we’ve created our LVM volume, let’s look at some common management tasks.
Resizing Logical Volumes
You can easily resize LVs using the lvresize
command. For example, to increase the size of “my_lv” by 50GB, run:
sudo lvresize -L +50G my_vg/my_lv
Don’t forget to resize the filesystem as well, using the resize2fs
command:
sudo resize2fs /dev/my_vg/my_lv
Removing LVM Volumes
To remove an LV, first unmount the filesystem:
sudo umount /dev/my_vg/my_lv
Then, use the lvremove
command to delete the LV:
sudo lvremove my_vg/my_lv
Monitoring LVM Volumes
LVM provides several commands for monitoring the status of your volumes:
pvs
: Display information about physical volumesvgs
: Display information about volume groupslvs
: Display information about logical volumes
Managing Snapshots
Snapshots are point-in-time copies of your logical volumes. They allow you to revert your system to a previous state in case of data loss or corruption. To create a snapshot, use the lvcreate
command with the -s
flag:
sudo lvcreate -L 5G -s -n myvolume_snapshot /dev/myvg/myvolume
This command creates a 5GB snapshot named “myvolume_snapshot” of the “myvolume” logical volume.
To revert a logical volume to a snapshot, first, unmount the filesystem and use the lvconvert
command:
sudo umount /dev/myvg/myvolume
sudo lvconvert --merge /dev/myvg/myvolume_snapshot
Mount the filesystem again after the merge is complete.
Conclusion
Managing LVM volumes on Rocky Linux is a straightforward process, thanks to the powerful LVM command-line tools. With these commands in your arsenal, you can efficiently create, resize, remove, and manage snapshots of your logical volumes.
For more tips on optimizing your Linux environment, check out these articles: