Bobcares

wesupport

CLIENT AREACall Us 1-800-383-5193
Bobcares

wesupport

Call Us 1-800-383-5193
Bobcares

wesupport

Call Us 1-800-383-5193

Need help?

Our experts have had an average response time of 13.52 minutes in October 2021 to fix urgent issues.

We will keep your servers stable, secure, and fast at all times for one fixed price.

How to create an LVM logical volume on an entire EBS volume

by | Aug 16, 2021

Wondering how to create an LVM logical volume on an entire EBS volume? We will help you!

Here, at Bobcares, we often receive similar AWS queries from our customers as a part of our AWS Support Services.

Today, let’s see the steps followed by our Support Techs to create an LVM logical volume on an entire EBS volume.

Create an LVM logical volume on an entire EBS volume

Logical Volume Managers (LVMs), is a storage virtualization technology that offers a more flexible way to managing disk space. This is a tool for logical volume management which includes allocating disks, striping, mirroring, and resizing logical volumes. If we are using logical volumes on the Amazon EBS volume, we must use LVM to extend the logical volume.

Now let’s see the steps followed by our Support Techs to use LVM on an EBS volume and extend the partitions.

  1. At first, we need to create physical volumes (PV) from our EBS volume.
  2. Create a volume group (VG) and then add the physical volume that we created into the volume group.
  3. Then create a logical volume (LV) and mount the directory on the LVM.
  4. Then we need to create and mount a file system.
  5. Finally, resize the logical volume.

 

Creating physical volumes from the EBS volume

1. At first, log in to the AWS Management console and then open the Amazon EC2 console.

2. Then we should create the EBS volume, and then attach the volume to the instance.

3. To create a physical volume, run the pvcreate command.  For example, here we use one volume, /dev/sdf, to create the physical volume.

$ sudo pvcreate /dev/sdf
Physical volume "/dev/sdf" successfully created.

4. Then, to view the physical volume details, we can use the pvs or pvdisplay command as follows.

$ sudo pvs
PV VG Fmt Attr PSize PFree
/dev/sdf lvm2 --- 10.00g 10.00g

Also note that if we are using Nitro-based instance, the block device name are like /dev/nvme1n1, /dev/nvme2n1, etc. So we need to replace the device names in the following steps with the correct device name.

Creating volume groups and adding the physical volumes into the volume group

 

  1. To create a volume group to add the new physical volume we can use the vgcreate command.

Syntax: $ sudo vgcreate <volume-name> <device-1> <device-2> <device-3>

Here in the following example uses one physical volume to create the volume group NewVG.

$ sudo vgcreate NewVG /dev/sdf
Volume group "NewVG" successfully created

2. To see the new volume group’s details, we can use the vgs or vgdisplay command.

$ sudo vgs
VG #PV #LV #SN Attr VSize VFree
NewVG 1 0 0 wz--n- <10.00g <10.00g

 

Creating a logical volume and mounting the directory on LVM

 

  1. To create a logical volume from the volume group, we can use the lvcreate command.

Syntax: sudo lvcreate -n <logical-volume-name> -L <size-of-volume> <lvm-volume-name>

$ sudo lvcreate -n newLV -L 9G NewVG
Logical volume "newLV" created.

The example creates one 9 GB logical volume, newLV, from the NewVG volume group.

2. To view the logical volume’s details, we can use the lvs or lvdisplay command.

$ sudo lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
newLV newVG -wi-a----- 9.00g

3. Then using the mkdir command we can create a mount directory. The following example creates the directory /mnt1.

$ sudo mkdir /dev/newVG/newLV /mnt1

For example, here we created the directory /mnt1.

Creating and mounting the file system

 

  1. To create a file system and mount the partitions, use the following commands.

We can use the mkfs -t command to create the file system.

$ sudo mkfs -t xfs /dev/newVG/newLV

Replace xfs with the correct file system type.

2. Then use the lsblk -f command to verify the creation of the new file system.

$ lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
sda
├─sda1
└─sda2 xfs 66e5e079-770e-4359-a9da-5205c3d8d5af /
sdf LVM2_member YeDuj5-YHmY-U0Hx-xJyt-R1BP-SPIj-3uCcGF
└─newVG-newLV xfs Feiuj5-kH9Y-UxHx-zJ9t-R7cP-5PIY-7ugcuM

3. Then run the mount command to mount the file system on the mount directory:

$ sudo mount /dev/newVG/newLV /mnt1

4. Then edit the mount options in the /etc/fstab file so that the new mount persists after reboot.

/dev/newVG/newLV /mnt1 xfs defaults,nofail 0 0

 

Resize the logical volume

There are two options for extending logical volumes:

  1. By increasing the size of the existing EBS volume.
  2. Adding additional EBS volumes to the volume group.

 

By increasing the size of the existing EBS volume

1. Change the size of the existing EBS volume.

2. Then run the pvresize command to resize the physical volume.

$ sudo pvresize /dev/sdf
Physical volume "/dev/sdf" changed
1 physical volume(s) resized / 0 physical volume(s) not resized

3. We can use the pvs or pvdisplay to view the physical volume details.

$ sudo pvs
PV VG Fmt Attr PSize PFree
/dev/sdf newVG lvm2 a-- <20.00g <11.00g

4. To view the volume group’s details, use the vgs or vgdisplay command.

$ sudo vgs
VG #PV #LV #SN Attr VSize VFree
newVG 1 1 0 wz--n- <20.00g <11.00g

5. Then run the lvextend command to extend the logical volume:

$ sudo lvextend -L 19G /dev/newVG/newLV

6.To view the logical volume’s details, use the lvs or lvdisplay command.

$ sudo lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
newLV newVG -wi-a----- 19.00g

7. Then extend the file system.

For XFS file systems:

$ sudo yum install xfsprogs
$ sudo xfs_growfs /dev/newVG/newLV

For Ext4 file systems:

$ sudo resize2fs /dev/newVG/newLV

When increasing the size of the volume, size changes usually take effect within a few 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. Performance changes may take from a few minutes to a few hours depending on the volume type.

Adding additional EBS volume to the volume group

 

  1. First, we need to create another EBS volume of 10 GB and then attach the volume to the instance.
$ sudo pvcreate /dev/sdi

2. To extend the volume group, use the vgextend command and then add the new volume.

$ sudo vgextend newVG /dev/sdi
Physical volume "/dev/sdi" successfully created.
Volume group "newVG" successfully extended

The following example shows that there are now two PV in the newVG volume group.

$ sudo vgs
VG #PV #LV #SN Attr VSize VFree
newVG 2 1 0 wz--n- 29.99g 20.99g

3. We can use the lvextend command to extend the logical volume:

$ sudo lvextend -L 29G /dev/newVG/newLV

4. Then resize the file system.

For XFS file systems:

$ sudo xfs_growfs /dev/newVG/newLV

For Ext4 file systems:

$ sudo resize2fs /dev/newVG/newLV

Note: If we have already created LVM on the volume and mounted it, then we need to follow the steps at Extend the logical volume

[Need help with more AWS queries? We’d be happy to assist]

Conclusion

To conclude, today we discussed the steps followed by our Support Engineers to help our customers to create an LVM logical volume on an entire EBS volume.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *