How to Create LVM Volume with Partition

RMK
3 min readJul 6, 2024

--

In this article, I’ll be creating LVM volume with partition using the Linux AMI 2 Operating System.

LVM offers a powerful and flexible framework for managing disk storage in Linux environments. Its ability to dynamically resize volumes, support for hot swapping, and advanced features like snapshots and thin provisioning make it a valuable tool for both server and desktop systems.

Assume that you have already created the EBS volume on your EC2 instance.

Step 1. Partition the volume drive “if needed”.

Use fdisk tool for partition

sudo fdisk /dev/xvdb

Note: /xvdb = volume mount of your AWS EBS volume.

First Partition
Choose “n” > p > default > default > +4GB
Second Partition
Choose “n” > p > default > default > +4GB
Note: +4GB = is the size of the drive you want to partition.

Type “w” to write the changes.

Use lsblk to verify.

sudo lsblk

Step 2. Create Physical Volume using pvcreate command:

sudo pvcreate /dev/xvdb1 /dev/xvdb2

you can use pvs, pvdisplay, pvscan to verify

sudo pvs / 
sudo pvdisplay /
sudo pvscan /

Step 3. Create Volume group using vgcreate command:

sudo vgcreate test1 /dev/sdb1
sudo vgcreate test2 /dev/sdb2

you can use vgs, vgdisplay, vgscan to verify

sudo vgs /
sudo vgscan /
sudo vgdisplay /

Step 4. Create Logical volume using lvcreate command:

sudo lvcreate -L 3.5GB -n ltest1 test1
sudo lvcreate -L 3.5GB -n ltest2 test2

you can use lvs,lvdisplay, lvscan to verify

sudo lvs \
sudo lvdisplay \
sudo lvscan \

Format to desired filesystem

sudo mkfs.ext4 /dev/test1/ltest1
sudo mkfs.ext4 /dev/test2/ltest2

Step 5. Create Mountpoint where you want to mount the drive.

sudo mkdir testfolder /var/data
sudo mkdir testfolder /mnt

Step 6. Mount the drive to your created mountpoint

sudo mount -t ext4 /dev/test1/ltest1 /var/data
sudo mount -t ext4 /dev/test2/ltest2 /mnt

df -hT to confirm

sudo df -hT

Step 7. Permanently Mount the drive to your created mountpoint using fstab

sudo vi /etc/fstab

Enter:
/dev/mapper/test1-ltest1 /var/data ext4 defaults 0 0
/dev/mapper/test2-ltest2 /mnt ext4 defaults 0 0

Or you can use the UUID
UUID=<uuid-of-your-drive> <mount-point> <file-system-type> <mount-option> <dump> <pass>

To save press esc :wq! > Enter

Note: use blkid command to check the UUID of your drive.

Done.

--

--

No responses yet