Linux & LVM (Part 2): Usage
Logical Volume Management (LVM) is a popular method of managing storage on Linux operating systems. It allows administrators to create and manage logical volumes, which can span multiple physical disks and can be resized on-the-fly. In this blog post, we will walk through the process of configuring LVM on Linux.
LVM Series
- Linux & LVM (Part 1): What is LVM?
Linux & LVM (Part 2): Usage
Install LVM Tools
The first step is to make sure that the LVM tools are installed on your Linux system. Most Linux distributions come with the LVM tools pre-installed, but you can make sure of it by running the following command:
Now that you have it installed let's start creating multiple PVs and then add them to a VG.
Create Physical Volumes
LVM operates on physical volumes (PVs), which can be disks or disk partitions. Before creating logical volumes, you need to create one or more physical volumes. For example, if you have a new disk attached to your system, you can create a physical volume on it using the following command:
This command creates a physical volume on the /dev/sdb
device. By the same command we will create the second Physical Volume on /dev/sdc
.
Create Volume Groups
A volume group (VG) is a collection of one or more physical volumes. You can create a volume group using the following command:
This command creates a volume group named vg1
that contains the physical volumes /dev/sdb
and /dev/sdc
. And you can now see your volume group by vgs
or vgdisplay
command:
Resizing Volume Groups
If you want to add a new physical volume to a volume group you may extend it by using the following command:
You can also remove a physical volume from volume group with vgreduce
command:
Create Logical Volumes
A logical volume (LV) is a virtual partition that resides within a volume group. You can create a logical volume using the following command:
This command creates a logical volume named lv1
that is 10GB in size and resides within the volume group vg1
.
Format and Mount Logical Volumes
Once you have created a logical volume, you need to format it with a file system and mount it. You can format a logical volume with a file system using the following command:
This command formats the logical volume lv1
, which resides in the volume group vg1
, with the ext4
file system.
You can mount the logical volume to a directory like this:
This command mounts the logical volume lv1
, which resides in the volume group vg1
, to the directory /mnt/lv1
.
Resizing Logical Volumes
One of the benefits of using LVM is that you can resize logical volumes on-the-fly. To resize a logical volume, you can use the following command:
This command increases the size of the logical volume lv1
by 5GB.