Introduction:
LVM (Logical Volume Manager) is a widely used tool in Linux distributions to manage storage devices. It provides a flexible way of managing the storage devices by allowing users to create, resize, move, and delete logical volumes. In this article, we will learn how to configure and manage storage devices in Fedora using LVM.
Step 1: Check Available Storage Devices
Before configuring LVM, we need to check the available storage devices on the system. We can use the following command to list all the storage devices:
sudo fdisk -l
This command will display all the available storage devices along with their partitions.
Step 2: Install LVM Package
If LVM is not installed on your system, you can install it using the following command:
sudo dnf install lvm2
Step 3: Create Physical Volumes
The first step in configuring LVM is to create physical volumes. A physical volume is a storage device or partition that is used by LVM. To create a physical volume, we can use the following command:
sudo pvcreate /dev/sdb
Here, /dev/sdb
is the storage device on which we want to create a physical volume.
Step 4: Create Volume Groups
After creating the physical volumes, we need to create volume groups. A volume group is a collection of one or more physical volumes. To create a volume group, we can use the following command:
sudo vgcreate myvg /dev/sdb
Here, myvg
is the name of the volume group, and /dev/sdb
is the physical volume that we created in the previous step.
Step 5: Create Logical Volumes
After creating the volume groups, we need to create logical volumes. A logical volume is a virtual partition that is created inside a volume group. To create a logical volume, we can use the following command:
sudo lvcreate -L 10G -n mylv myvg
Here, -L 10G
specifies the size of the logical volume, mylv
is the name of the logical volume, and myvg
is the name of the volume group.
Step 6: Format Logical Volumes
After creating the logical volumes, we need to format them with a file system. To format a logical volume, we can use the following command:
sudo mkfs.ext4 /dev/myvg/mylv
Here, /dev/myvg/mylv
is the path to the logical volume that we want to format, and mkfs.ext4
is the command to format the volume with the ext4 file system.
Step 7: Mount Logical Volumes
After formatting the logical volumes, we need to mount them on the file system. To mount a logical volume, we can use the following command:
sudo mkdir /mnt/mylv
sudo mount /dev/myvg/mylv /mnt/mylv
Here, /mnt/mylv
is the mount point for the logical volume, and /dev/myvg/mylv
is the path to the logical volume that we want to mount.
Step 8: Resizing Logical Volumes
If we need to resize a logical volume, we can use the following command:
sudo lvresize -L +5G /dev/myvg/mylv
Here, -L +5G
specifies the amount by which we want to increase the size of the logical volume.
Step 9: Removing Logical Volumes
If we need to remove a logical volume, we can use the following command:
sudo umount /mnt/mylv
sudo lvremove /dev/myvg/mylv
Step 10: Removing Volume Groups and Physical Volumes
If we need to remove a volume group, we can use the following command:
sudo vgremove myvg
Here, myvg
is the name of the volume group that we want to remove.
If we need to remove a physical volume, we can use the following command:
sudo pvremove /dev/sdb
Here, /dev/sdb
is the physical volume that we want to remove.
Conclusion:
LVM is a powerful tool that can help us manage storage in a flexible way. By creating physical volumes, volume groups, and logical volumes, we can create virtual partitions that can be resized and moved easily. We can also format and mount logical volumes to use them as regular partitions. In this article, we learned how to configure storage devices in Fedora using LVM.