Creating a Logical Volume in LVM

Background

I wanted to upgrade from Fedora 24 to Fedora 25 using the dnf upgrade utility. Before doing that, I wanted to take a backup in case any issue occurs. While installing Fedora 24 I chose LVM partioning scheme which I felt would help in case I needed to resize my drives without having shrink and expand other drives, which I was doing earlier.

Prerequisites

The volume group that was created as part of installation had already used up all the space of the underlying physical volume. There was nearly half of the HDD space still unallocated, I had the following options:

  • Create a new physical volume and add it to the existing volume group
  • Create a new physical volume and add it to a new volume group
  • Extend the existing physical volume

Creating the partition

I felt it would be better to take option 2 from the above. I looked at some tutorials online like a crash course kind of stuff in playing around with LVM. So, the first step was to create a physical partion and for that I chose cfdisk which is an ncurses version of the fdisk utility. The process is as follows:

  • Launch the program with sudo cfdisk
  • The program showed the list of partitions and free space available
  • Choose Freespace from list of devices and select [ New ]
  • Give the partition size like Partition size: 100G and press Enter
  • It will ask if the partion is [ primary ] [ extended ] and I chose [ primary ]
  • The partition table will be listed with a new device for ex: /dev/sda2 (nothing is saved yet)
  • Choose [ Type ] and select 8e Linux LVM
  • Finally, choose [ Write ] to persist the changes

Creating Physical Volume

Check for the new device using lsblk or anyother equivalent command. Now its time to create the physical volume,

sudo pvcreate /dev/sda2

Check if the physical volume is created using the following command,

sudo pvdisplay

Creating Volume Group

Use the following command to create the volume group. The command used below takes the name for the volume group and space separated physical volumes that this volume group will handle.

sudo vgcreate <volume_group_name> /dev/sda3

Check if the volume group is created using the following command,

sudo vgdisplay

Creating Logical Volume

Use the following command to create the logical volume. The command below takes the size & name of the logical volume and name of the volume group which this logical volume will be a part of.

sudo lvcreate -L 149G -n <logical_volume_name> <volume_group_name>

Check if the logical volume is created using the following command,

sudo lvdisplay

Creating a disk out of the logical volume

Now that we have a logical volume, its time to create a drive out of it like /, /home, /boot, etc. Use the following command to create an ext4 partition,

sudo mkfs.ext4 /dev/<volume_group_name>/<logical_volume_name>

Check if the disk is created using either lsblk or sudo fdisk -l

Finally

A drive is now ready to backup the files or use it for any purpose. There are lots of ways and configurations available and I only picked ones which I needed at this particular moment.