How to Configure LVM in Linux Mint?


LVM (Logical Volume Manager) is a powerful tool to manage multiple physical disks as a single logical unit. This can provide benefits such as flexibility, performance, and security. Logical volumes are partitions that can span across multiple physical disks and can be easily modified without affecting the data on them. LVM also provides features such as snapshots, mirroring, and encryption.

Based on its importance, this article explains the configuration of LVM in Linux Mint. Furthermore, it covers the steps of creating the “physical volume”, “volume group”, and “logical volume”, as well as how to format and mount the logical volume.

Understanding Important Key Terms

Before we begin, some key concepts and terms related to LVM are given below:

Physical Volume (PV): A physical disk or partition that LVM uses. You can have multiple PVs in a system.

Volume Group (VG): A set of PVs that act as a single storage space. You can create multiple VGs in a system.

– Logical Volume (LV): A virtual partition that is created from the free space of a VG. You can create multiple LVs in a VG, and assign them to different mount points or purposes. Users can also move, resize, or delete LVs without modifying the data/information on them.

Note: You will need a Linux Mint installation medium (DVD or USB) or a computer with more than one hard disk. Or an additional disk or partition that you want to use for LVM.

How to Configure LVM in Linux Mint?

With LVM in Linux Mint, users create a physical volume (PV) on each disk that they want to use, then group them into a volume group (VG). Finally, create one or more logical volumes (LV) on the VG. Also, create, resize, merge, split, move, or delete partitions without losing data or affecting the system.

The basic workflow of configuring LVM in Linux Mint is as follows:

  1. Create a PV from the disks or partitions that you want to use for LVM.
  2. Create a VG from the one or more PVs that users want to group.
  3. Create one or more LVs from the free space of the VG, and format them with your desired file system.
  4. Finally, mount the LVs to the appropriate directories.

Let’s begin the step-by-step configuration of LVM in Linux Mint.

Step 1: Install LVM on Linux Mint

On Linux Mint, the LVM package is pre-installed in the system to perform disk tasks. If not installed, users can install the LVM package on the Linux Mint by typing the “lvm2” command with the “install” utility:

sudo apt install lvm2

The output shows that LVM is already installed in the system. If not installed, insert the password and wait for the installation to be completed.

Step 2: Disk Volume/Partition Information

To create a physical volume, users need to know the device name that corresponds to the disk or partition. For this, find out details of disks or partitions using the “lsblk” command:

lsblk

The output lists all the block devices on your system. In our case, our focus to configure LVM in Linux Mint is on “/dev/sdb” and “/dev/sdc”.

Note: Alternatively, use the “fdisk -l” command to list the available disks and partitions on the system.

Additional Note: If users do not have extra partition/partitions, create/remove/extend them using the “fdisk” utility by mentioning the name of the disk. In this case, the “/dev/sdb” is the disk name, and creates a new partition using the “n” keyword. Then, choose the “p” key to set the (default) primary partition. Finally, type “1” to set the first partition in the disk:

sudo fdisk /dev/sdb

It creates the new partition from the disk “/dev/sdb” of “7 GB”.

In addition, users can change the partition type using the “t” keyword and “w” for the write modifications on disk:

Users can create one or more primary as well as extended partitions by following the above procedure. To remove any partition, use the “d” key at the place of “n” in the terminal.

Step 3: Create a Physical Volume

The next step is to create a physical volume on the disk or partition that users want to use for LVM. A physical volume is the basic unit of storage for LVM, and it can be any block device, such as a “hard disk”, a “solid-state drive”, or a “USB” stick.

To do so, utilize the “pvcreate” command with the device name to create a physical volume on it. In our case, “/dev/sdb” is the device name of our disk or partition:

sudo pvcreate /dev/sdb

The output shows that the physical volume “/dev/sdb” has been created successfully.

Verification of Physical Volume

Users can verify that the PVs are created by running the “pvs” command with the “sudo” privileges:

sudo pvs

The output confirms the physical volume of 7GB in the “/dev/sdb” disk.

Note: In the same way, users can create multiple physical volumes with the “pvcreate” command from the disk.

Step 4: Create a Volume Group

To create a volume group, give a name and specify the physical volume that users want to include in it. For instance, name of volume group “vol1” and include “/dev/sdb” and “/dev/sdc” in it via the “vgcreate” command:

sudo vgcreate vol1 /dev/sdb /dev/sdc

Note: Users can add or remove physical volume/s from a volume group as needed. Furthermore, create multiple volume groups on the system.

Verify Volume Groups

You can verify the created volume group by running the “vgs” command with the root access:

sudo vgs

Optional: Create a Volume Group From a Single Physical Volume

To create a volume group from a single physical volume, use the “vgcreate” command by specifying the volume name as “mint-vg” along with device path “/dev/sdb1”:

sudo vgcreate mint-vg /dev/sdb1

Step 5: Create a Logical Volume

The final step is to create a logical volume on the volume group that we just created. A logical volume is a virtual partition (formatted manner) that is mounted on any directory. Users can create multiple logical volumes on a volume group, and resize them without losing data.

To create a logical volume, give a specific name, size, and volume group that users want to create it on. For instance, our logical volume name is “lvol1”, make “9GB” in size on “vol1” by using the “lvcreate” command:

sudo lvcreate -n lvol1 -L 9G vol1

The output shows that logical volume “lvol1” has been created in Linux Mint.

Step 6: Format Logical Volume

Now users need to format logical volume with a file system and mount it in a directory that has already been created. For instance, format the logical volume “lvol1” with the “ext4” file system via the below command:

sudo mkfs.ext4 /dev/vol1/lvol1

Step 7: Mount Logical Volume

Now, mount this volume on the “/mnt/lvol1” directory after creating via the “mkdir” Linux utility. Then, assign a path “/mnt/lvol” via the below commands:

sudo mkdir /mnt/lvol
sudo mount /dev/vol1/lvol1 /mnt/lvol1

Verification

Users can verify that the logical volume “/dev/vol1/lvol1” is mounted by using the “df -h” command. It shows the disk usage of the file systems:

df -h

You have successfully configured LVM in Linux Mint. You can now use your logical volume as a normal partition, and modify it as needed using the LVM commands.

Advanced Tip: Create Multiple LVs

To create multiple (e.g. three) LVs named “root”, “swap”, and “home” from the free space of any volume (such as “volgrp_name”), with sizes of 40 GB, 8 GB, and 100 GB respectively:

sudo lvcreate -n root -L 40G volgrp_name # Create Three LVs
sudo lvcreate -n swap -L 8G volgrp_name
sudo lvcreate -n home -l 100%FREE volgrp_name

Note: The -l option specifies the size as a percentage of the remaining free space in the VG.

After that, format the LVs based on the file system. For instance, use “ext4” (file system) for “root” and “home”, and “swap” for swap by mentioning their accurate path:

sudo mkfs.ext4 /dev/volgrp_name/root # Format LVs
sudo mkfs.ext4 /dev/volgrp_name/home
sudo mkswap /dev/volgrp_name/swap

To mount the LVs, create the mount points and use the “mount” command. For example, if you want to mount root to /, home to /home, and swap to swap, run the following commands:

sudo mkdir /mnt/root # Create Mount Points of LVs
sudo mkdir /mnt/home
sudo mount /dev/volgrp_name/root /mnt/root
sudo mount /dev/volgrp_name/home /mnt/home
sudo swapon /dev/volgrp_name/swap

To make the changes persistent, users need to update the “/etc/fstab” file with the UUIDs of the LVs. You can find the UUIDs by running the “blkid” command. Finally, users can now “reboot” the system and enjoy the benefits of LVM.

How to Configure LVM During Installation of Linux Mint?

To configure LVM during the installation of Linux Mint, choose the option “Erase disk and install Linux Mint” in the “Installation type” screen. Then, click on “Advanced features” to customize the LVM settings, such as the size of the root and swap partitions, the volume group name, and the encryption password. Finally, hit the “Install Now” button as highlighted below:

It erases all the data on your disk and creates a new partition scheme with LVM.

Now, insert the strong password/security key to protect the file/files in the Linux Mint system and hit the “Install Now” button:

After finishing the LVM configuration, users can move forward to the other steps of installation as usual.

How to Use/Manage LVM in Linux Mint?

To use/manage LVM in Linux Mint, use “pvcreate”, “vgcreate”, and “lvcreate”, command-line tools for creating disk tasks. In addition, users can increase as well as decrease the logical volume size using the “lvresize” command. This command allows users to specify the new size of the logical volume in absolute or relative terms. Users can also remove/format these created volumes:

Let’s perform some basic actions after the configuration of LVM in Linux Mint.

  1. Increase Logical Volume Size

To increase the size of a logical volume named “lvol1” by 2GB, use the “lvresize” command along with the path “/dev/vol1/lvol1”:

sudo lvresize -L +2G /dev/vol1/lvol1

  1. Decrease Logical Volume Size

To decrease the size of a logical volume named “lvol1” by 1 GB, you can use the below command:

sudo lvresize -L -1G /dev/vol1/lvol1

Note that before decreasing the size of a logical volume, users need to make sure that the filesystem on it can be resized to a smaller size.

  1. Delete Logical Volume

To delete a logical volume, use the “lvremove” command with the volume path as “/dev/vol1/lvol1”. It asks to confirm the operation before proceeding:

sudo lvremove /dev/vol1/lvol1

It removes the logical volume.

Verification

To check the status of the logical volume and see how much free space is available after deleting the logical volume, use the “lvdisplay” command:

sudo lvdisplay

  1. Delete a Volume Group

Users make sure the volume group is not in use by any logical volumes or mounted partitions. To delete the volume group, use the command “vgremove <vgname>”, where “<vgname>” is the name of the volume group that users want to delete:

sudo vgremove vol1

It confirms that the volume group has been deleted from Linux Mint.

Verification

Then, use the command “vgdisplay” to list the existing volume groups and their names:

sudo vgdisplay

Note: Deleting a volume group will erase all the data on it, so make sure you have a backup before proceeding.

  1. Delete Physical Volume

Make sure any logical volume or volume group does not use the physical volume. To delete it, use the “pvremove” command with the device name as an argument, such as “/dev/sdb”:

sudo pvremove /dev/sdb

The output confirms that the physical volume has been deleted from Linux Mint.

Note: Repeat the same command for any other disk that users want to delete for LVM.

Verification

To check the status of the physical volume, use the command “pvdisplay” command:

sudo pvdisplay

  1. Delete a Partition

To delete a partition, users can utilize the “mkfs” command with the disk type (such as “ext4”) along with the partition/disk name as “/dev/sdb1”:

sudo mkfs -t ext4 /dev/sdb1

In this way, the created partition has been deleted including all its content.

Note: So, make sure you have backed up your important files before proceeding.

Conclusion

To configure LVM in Linux Mint, follow these steps: 1) Create a physical volume on disk or partition. 2) Create a volume group comprising one/multiple physical volume/s. 3) Create one or more logical volumes that are located in the volume group. 4) Format and mount the logical volumes as desired. 5) Use the “lvcreate”, “lvresize”, “lvremove”, and other commands to manage your logical volumes as needed. 6) Enjoy the benefits of LVM in Linux Mint.

 

Print Friendly, PDF & Email
Categories