Question: How do I create an LVM logical volume on a partition created on an EBS volume?

How can I use Logical Volume Manager (LVM) to create a logical volume (LV) on a partition created on my Amazon Elastic Block Store (Amazon EBS) volume?Short descriptionLVM allows you to allocate disk space and strip, re-mirror, and resize logical volumes. Using LVM, you can allocate an EBS volume or a set of EBS volumes to one or more physical volumes.To use LVM on your EBS volume and extend the partitions, follow these steps:Create physical volumes (PV) from your EBS volume.Create a volume group (VG), and then add the physical volumes into the volume group.Create a logical volume (LV), and then mount the directory on the LVM.Create and mount a file system.Resize the logical volume.

ResolutionNote: If you already created LVM on your volume and mounted it for use, then follow the instructions beginning at Extend the logical volume.Create physical volumes on the partition of your EBS volumeThe underlying physical storage unit of an LVM logical volume is a block device, such as a partition of an EBS volume or an entire EBS volume.Note: Nitro-based instances expose volumes as NVMe devices. The block device names follow the pattern /dev/nvme1n1, /dev/nvme2n1, /dev/nvme3n1, and so on. If you're using a Nitro-based instance, then replace the device names in the following steps with the appropriate device name. For more information on device naming, see Device names on Linux instances.1.    Open the Amazon Elastic Compute Cloud (Amazon EC2) console.2.    Create your EBS volume and then attach the volume to your instance.3.    Use the gdisk command to create a partition. For the variable Hex code or GUID, enter 8e00. The following example creates the partition /dev/xvdh1 on /dev/xvdh.$ sudo gdisk /dev/xvdhCommand (? for help): nPartition number (1-1218, default 1): 1First sector (34-20971486, default = 2048) or {+-}size{KMGTP}:Last sector (2048-20971486, default = 20971486) or {+-}size{KMGTP}:Current type is 'Linux filesystem'Hex code or GUID (L to show codes, Enter = 8300): 8e00        Changed type of partition to 'Linux LVM'...OK; writing new GUID partition table (GPT) to /dev/xvdh.The operation has completed successfully.Use the lsblk command to confirm creation of the partition:$ lsblkNAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINTxvda    202:0    0   8G  0 disk└─xvda1 202:1    0   8G  0 part /xvdh    202:80   0  10G  0 disk└─xvdh1 202:81   0  10G  0 part4.    Use the pvcreate command to create a physical volume from the partition. The following example, creates a physical volume from /dev/xvdh1:$ sudo pvcreate /dev/xvdh1  Physical volume "/dev/xvdh1" successfully created.Create volume groups and add the physical volumes into the volume groupUse the vgcreate command to create a volume group to combine the new physical volumes. The following example uses one physical volume to create volume group examplegroup1:$ sudo vgcreate examplegroup1 /dev/xvdh1      Volume group "examplegroup1" successfully createdUse the vgs or vgdisplay to view the volume group details:$ sudo vgs  VG             #PV #LV #SN Attr   VSize  VFree  examplegroup1   1   0   0 wz--n- <10.00g <10.00gCreate a logical volume (LV) and a mount directory1.    Use the lvcreate command to create logical volumes (partitions) from your volume group. The following example creates one 9GB logical volume, lvexample1 from the examplegroup1 volume group:$ sudo lvcreate -n lvexample1 -L 9G examplegroup1  Logical volume "lvexample1" createdUse the lvs or lvdisplay command to view the logical volume details:$ sudo lvs  LV          VG   Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert                                   lvexample1 examplegroup1 -wi-a----- 9.00g2.    Use the mkdir command to create a mount directory. The following example creates the directory /mnt1:$ sudo mkdir /mnt1Create and mount a file system1.    Use the following commands to create a file system and mount the partitions for use.Run the mkfs -t command to create the file system. Note: Replace xfs with your file system type, if different. For example, use ext2, ext3, or ext4.$ sudo mkfs -t xfs /dev/examplegroup1/lvexample1Run the lsblk -f command to verify creation of the new file system. Note: The file system type that you created in the previous step appears under FSTYPE.$ lsblk -fNAME                         FSTYPE      LABEL UUID                                   MOUNTPOINTxvda                                                                            ├─xvda1                                                                         └─xvda2                      xfs               66e5e079-770e-4359-a9da-5205c3d8d5af   /xvdh                                                                            └─xvdh1                      LVM2_member       0UnOic-e2ng-XxH5-z0UW-7aTh-RxQK-KMrDqo  └─examplegroup1-lvexample1 xfs              5db36052-81d5-4762-8502-6986ff3964e7Run the mount command to mount the file system on the mount directory that you created in the previous step:$ sudo mount /dev/examplegroup1/lvexample1 /mnt12.    Edit the mount options in the /etc/fstab file so that the new mount persists after reboot./dev/examplegroup1/lvexample1 /mnt1   xfs     defaults,nofail   0   0Note: If your file system type is not xfs, then replace xfs with the type in the /etc/fstab file.Extend the logical volumeThere are two options for extending logical volumes:Option 1: Increase the size of the existing EBS volume.Option 2: Add additional EBS volumes to your volume group.Option 1: Increase the size of the existing EBS volumeNote: When increasing the size of your existing volume, size changes usually take effect within seconds when the volume enters the optimizing state. The volume's performance is affected while in the optimizing state, but doesn't fall below the source configuration specification. Depending on your volume type, performance changes might take from a few minutes to a few hours. For more information, see Monitor the progress of volume modifications.1.    Modify the size of the existing EBS volume.2.    Install the growpart utility:$ sudo yum install cloud-utils-growpartNote: Use the following command to install the growpart utility on Debian or Ubuntu-based systems:$ sudo apt install -y cloud-guest-utils3.    Run the growpart command to extend the partition, and then run the pvresize command to resize the PV. In the following example, partition /dev/xvdh1 is extended:$ sudo growpart /dev/xvdh 1                      CHANGED: disk=/dev/xvdh partition=1: start=2048 old: size=20971519,end=16777182 new: size=41940958,end=41943006$ sudo pvresize /dev/xvdh1                         Physical volume "/dev/xvdh1" changed  1 physical volume(s) resized or updated / 0 physical volume(s) not resizedUse the pvs or pvdisplay to view the physical volume details:$ sudo pvs  PV         VG            Fmt  Attr PSize   PFree  /dev/xvdh1 examplegroup1 lvm2 a--  <20.00g <13.00gUse the vgs or vgdisplay to view the volume group details:$ sudo vgs  VG            #PV #LV #SN Attr   VSize   VFree  examplegroup1   1   1   0 wz--n- <20.00g <13.00g4.    Run the lvextend command to extend the logical volume:$ sudo lvextend -L 19G /dev/examplegroup1/lvexample1Use the lvs or lvdisplay command to view the logical volume details:$ sudo lvs  LV        VG            Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert  lvexample1 examplegroup1 -wi-a----- 19.00g5.    Extend the file system:Note: Make sure that you enter the correct file system type in the /etc/fstab entry.Ext2, Ext3, and Ext4 file systems:$ sudo resize2fs /dev/examplegroup1/lvexample1XFS file systems:$ sudo yum install x    rogs$ sudo xfs_growfs /dev/examplegroup1/lvexample1Option 2: Add additional EBS volumes to the volume group1.    Create another EBS volume of 10 GB, and then attach the volume to the instance. Create a partition on the device /dev/xvdi following step 3 of Create physical volumes on the partition of your EBS volume. Then run the pvcreate command. In the following example, the volume's block device name is /dev/xvdi1.$ sudo pvcreate /dev/xvdi1Physical volume "/dev/xvdi1" successfully created.2.    Use the vgextend command to extend the volume group and add the new volume. The following example extends the volume group examplegroup1 to include the volume /dev/xvdi1:$ sudo vgextend examplegroup1 /dev/xvdi1  Volume group "examplegroup2" successfully extendedTo confirm the extension, run the vgs or vgdisplay command. The following example shows that there are now two PVs in the examplegroup1 volume group:$ sudo vgs  VG                       #PV #LV #SN Attr   VSize   VFree  examplegroup1            2   1   0 wz--n-  29.99g   20.99g3.    Run the lvextend command to extend the logical volume:$ sudo lvextend -L 29G /dev/examplegroup1/lvexample14.    Resize the file system:Note: Depending on your use case, follow the steps for XFS or Ext2, Ext3, and Ext4 file systems.Ext2, Ext3, and Ext4 file systems:$ sudo resize2fs /dev/examplegroup1/lvexample1XFS file systems:$ sudo xfs_growfs /dev/examplegroup1/lvexample1Related informationHow do I create an LVM logical volume on an entire EBS volume?