Step-by-Step Guide to Creating an LVM Partition on Linux

Logical Volume Manager (LVM) provides flexibility and manageability for disk storage on Linux systems. It allows for easy management of storage volumes, such as creating logical partitions that can be dynamically resized.

You can create an LVM partition on Linux and leverage the flexibility and manageability provided by Logical Volume Manager. LVM allows you to dynamically manage storage volumes, making it easier to resize, extend, and manage disk space as your needs evolve. Take advantage of LVM's capabilities to optimize your storage management in Linux.
In this step-by-step guide, I will walk through the process of creating an LVM partition on Linux.

Step 1: Check Available Disks

To begin, check the available disks on your system using the lsblk or fdisk -l command. Identify the disk you want to use for creating the LVM partition.

Example :

Let's take /dev/sdb as the disk

Step 2: Partition the Disk

Use a partitioning tool like fdisk or parted to create a new partition on the selected disk. Launch the partitioning tool and select the appropriate disk. Create a new partition of the desired size, making sure to set the partition type as Linux LVM (type code 8e). It is not mandatory to create the partition if we want to use he whole disk for LVM. I am not partitioning in this article

Step 3: Create a Physical Volume

After partitioning the disk, initialise the newly created partition as an LVM physical volume using the pvcreate command. For example, if the partition is /dev/sdb, run the following command:

sudo pvcreate /dev/sdb

Step 4: Create a Volume Group

Next, create a volume group that will encompass the physical volume. Use the vgcreate command followed by the desired volume group name and the physical volume device. For example:

sudo vgcreate myvg /dev/sdb

Step 5: Create a Logical Volume

Now it's time to create a logical volume within the volume group. Use the lvcreate command, specifying the volume group name, logical volume name, and the desired size. For example:

sudo lvcreate -L 10G -n mylv myvg

Step 6: Format the Logical Volume

Once the logical volume is created, you need to format it with a filesystem. Choose the appropriate filesystem type and use the relevant formatting command. For example, to format the logical volume with ext4/xfs filesystem, run respectively:

sudo mkfs.ext4 /dev/myvg/mylv

sudo mkfs.ext4 /dev/myvg/mylv

Step 7: Mount the Logical Volume

Create a mount point directory and mount the logical volume using the mount command. For example:

sudo mkdir /u01 sudo mount /dev/myvg/mylv /u01

Step 8: Configure Persistent Mounting and add in /etc/fstab

If you want the logical volume to be automatically mounted at system startup, you can configure it in the /etc/fstab file. Add an entry with the relevant details, such as the device, mount point, filesystem type(ext4 or xfs), and mount options.

/dev/myvg/mylv /u01 ext4 defaults 0 0

/dev/myvg/mylv /u01 xfs defaults 0 0

We Have successfully completed the activity !!

If you like please follow and comment