This documentation will show you how to create an LVM partition on an AWS EBS volume.
LVM is a storage virtualization technology that offers a flexible way to manage disk space. Using LVM we can have multiple virtual partitions on a physical volume or a single virtual partition over numerous physical volumes.
1. Deploy an EC2 instance
- Login to your AWS management console and search for EC2.
- On the EC2 dashboard, click Launch Instance to deploy a virtual machine.
- Provide an instance name and choose the OS image, key pair, instance type, etc.
- Review the configuration, storage, tagging, and security settings selected for your instance.
- And click on the Launch button at the bottom of the page.
2. Create Elastic Block Store-EBS volume and attach it to the EC2 instance.
- On your EC2 dashboard, select the option “Volumes” under “Elastic Block Store”
- Click on the button “Create volume”.
- Choose the volume type, size, availability zone, and other required settings. Make sure you choose the same availability zone where your instance resides.
- Click on the create button
- Now choose the volume created and attach it to the EC2 instance.
3. Verify that the EC2 instance recognizes the attached volume.
- Login to the EC2 instance using SSH
- Execute lsblk command and verify that the attached volume is available.
4. Create a Physical Volume – PV from the EBS volume
Set up the device to use the LVM. To do this, we can use the pvcreate command. The pvcreate command is used to initialize the disk or partitions that will be used by the LVM. It can either initialize a complete physical disk or a partition on a physical disk.
- Here we use the volume /dev/xvdf to create the physical volume.
- Use pvdisplay command to the physical volume details.
5. Create a Volume Group (VG) and add physical volume to the volume group.
- Use the command vgcreate to create a volume group and add a physical volume to it.
- Use the command vgdisplay to display the volume group details.
6. Create a Logical Volume and mount the directory
- Use the command lvcreate to create a logical volume from the volume group.
- Use the command lvdisplay to see the logical volume details
- Create a mount point using mkdir command
# mkdir mnt1
- Use mkfs -t command to create the file system.
#mkfs -t xfs /dev/volume-group/logical-volume1
- Run lsblk -f command to verify the file system.
- Run mount command to mount the file system to the mount directory.
# mount /dev/volume-group/logical-volume1 /mnt1
You can verify the volume mounted to the directory using df -h command.
Upon successful creation and mounting of the Logical Volume Manager (LVM), it can be utilized as a conventional volume. Notably, the LVM offers various benefits to business operations, including improved performance and the ability to expand as required. By dispersing data across multiple Elastic Block Store (EBS) volumes using LVM, companies can leverage the dedicated network throughput between Amazon Web Services (AWS) Elastic Compute Cloud (EC2) and EBS, resulting in superior network throughput compared to a single network channel between EC2 instances and EBS volumes. Additionally, companies can effortlessly expand their volume by adding more EBS volumes to the existing LVM volumes, instead of creating an EBS volume snapshot and subsequently expanding it.