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:
2. Create disk partition using fdisk utility. Enter the fdisk interactive menu:
# fdisk [device]
n create new partition.
p creates primary partition, use default partition number (1). To set disk allocation size, leave the first sector to their default value, set your preferred size on the Last Sector (see above).
t Create partition system ID, use the code 8e for “Linux LVM” partition type.
w Commit the changes in the partition table and exit fdisk tool.
3. Verify if the partition has been created:
2. Creating Volume Group
1. Create Volume Group:
# vgcreate [volume group name] [device]
2. Verify if Volume Group has been created successfully:
3. Create Logical Volume
1. Create Logical Volume:
# lvcreate -L [size] [volume group name]
2. Verify if the logical volume has been created:
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