What command would you use to resize an LVM volume group to include an additional physical volume?

Last updated: 2022-04-27

How can I use Logical Volume Manager [LVM] to create a logical volume [LV] on my entire Amazon Elastic Block Store [Amazon EBS] volume?

Short description

LVM 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:

  1. Create physical volumes [PV] from your EBS volume.
  2. Create a volume group [VG] and add the physical volumes into the volume group.
  3. Create a logical volume [LV] and mount directory on the LVM.
  4. Create and mount a file system.
  5. Resize the logical volume.

Note: For more information on using LVM with Nitro-based instances, see Chapter 11. LVM [Logical Volume Manager] on the Red Hat Customer Portal website.

Resolution

Note: 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 from your EBS volumes

The 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. You can create a PV on a single EBS volume or multiple EBS volumes.

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 pvcreate command to create a physical volume. The following example uses one volume, /dev/xvdf, to create the physical volume.

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

Use the pvs or pvdisplay command to view the physical volume's details:

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

Create volume groups and add the physical volumes into the volume group

Use the vgcreate command to create a volume group to combine the new physical volumes. The following example uses one physical volume to create the volume group Dock.

$ sudo vgcreate Dock /dev/xvdf Volume group "Dock" successfully created

Use the vgs or vgdisplay to view the new volume group's details:

$ sudo vgs VG #PV #LV #SN Attr VSize VFree Dock 1 0 0 wz--n-

Bài Viết Liên Quan

Chủ Đề