How to Create LVM filesystem using disk partitions in Linux

Running out of disk space and having to provision new storage is something that cannot be overlooked in infrastructure management. To make this process simpler, volume management was introduced. Although there are a lot of proprietary products out there to do this job, the default Linux volume management tool or LVM is an excellent choice to get started, and a lot of critical production infrastructure relies on this tool. This post explains how to create a filesystem in an LVM environment using a disk partition.

1. Creating disk partition

1. List initial disks and partitions:

# lsblk

2. Create disk partition using fdisk utility. Enter the fdisk interactive menu:

# fdisk [device]

3. Verify if the partition has been created:

# lsblk

2. Creating Volume Group

1. Create Volume Group:

# vgcreate [volume group name] [device]

2. Verify if Volume Group has been created successfully:

# vgs

3. Create Logical Volume

1. Create Logical Volume:

# lvcreate -L [size] [volume group name]

2. Verify if the logical volume has been created:

# lsblk

3. Creating filesystem and mounting

1. Proceed with formatting the logical volume:

# mk2fs -t [filesystem] [logical volume name]

2. Create a mountpoint for the filesystem. Navigate to the preferred directory and create a mountpoint directory:

# mkdir [mount name]

3. Mount the logical volumes into the mountpoint:

# mount -t [filesystem] [logical volume name] [mountpoint name]

4. Obtain the logical volume’s UUID:

# lsblk -f

5. Insert a new entry into the /etc/fstab configuration file for each logical volume:

# vi /etc/fstab
/dev/disk/by-uuid/[UUID] [mountpoint] [filesystem type] defaults,nofail,noatime,nodiratime 0 2

6. Perform mount for all filesystem:

# mount -a