Create LVM in EC2 AWS3 min read

Prabhin Prabharkaran Administrator
DevOps Engineer

He is a Technical professional. He is a person who loves to share tricks and tips on the Internet. He Posts what he does!

follow me

Create an LVM in EC2

LVM in EC2


Step1: Launch the AWS instance.
Step2: Attach the EBS volume. Here I’m Ceating 2 EBS Volume and attaching to the AWS machine which I have created.
Step3: Open the console check the volumes are detected or not using the following command.
Fdisk -l

Step4: Initialize devices to use with the LVM .
In order to do this, we need to use the pvcreate command. pvcreate is used to initialize disk or partitions that will be used by LVM. It can either initialize a complete physical disk or a partition on physical disks.

pvcreate /dev/xvdf /dev/xvdg

Step5: Display device attributes


Step6: Create the LVM volume group

vgcreate n2ws /dev/xvdf /dev/xvdg

Note : Here n2ws is the LVM volume group name.

Step7: Once the LVM volume group is created, you can use the vgdisplay command to show its attributes.


Step8: There are also commands like “vgscan”, which scan all disks for LVM volume groups.


Step9: Create Logical Volumes

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

lvcreate –name data –size 10GB n2ws
lvcreate –name backup –size 8GB n2ws

Step10: Once the logical volumes are created, we can view their status using the “lvdisplay” command.


Step11: Format your logical volumes
If you are using the ext4 filesystem:
#mkfs.ext4 <logical-volume-path>
mkfs.ext4 /dev/n2ws/data
mkfs.ext4 /dev/n2ws/backup

Step12: Mount the logical volumes .Once the logical volumes are formatted, you can mount them on your mount directories. Please make sure your mount directories already exist. If not, please create them.
mkdir /data
mkdir /backup

Step13: If you want you mount points to be available after reboot, you can add mount point entries in ‘/etc/fstab’.

root@ip-10-0-0-63:/home/ubuntu# cat /etc/fstab
LABEL=cloudimg-rootfs / ext4 defaults,discard 0 0
/dev/n2ws/data /data ext4 defaults 0 1
/dev/n2ws/backup /backup ext4 defaults 0 2

Step14: To view the status of the mount, use the mount command.



root@ip-10-0-0-63:/home/ubuntu# mount
/dev/xvda1 on / type ext4 (rw,discard)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
none on /sys/fs/cgroup type tmpfs (rw)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
udev on /dev type devtmpfs (rw,mode=0755)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
none on /run/shm type tmpfs (rw,nosuid,nodev)
none on /run/user type tmpfs (rw,noexec,nosuid,nodev,size=104857600,mode=0755)
none on /sys/fs/pstore type pstore (rw)
/dev/mapper/n2ws-data on /data type ext4 (rw)
/dev/mapper/n2ws-backup on /backup type ext4 (rw)
systemd on /sys/fs/cgroup/systemd type cgroup (rw,noexec,nosuid,nodev,none,name=systemd)


© 2018, Techrunnr. All rights reserved.

Questions Answered
Articles Written
Overall Points

Related posts

Leave a Reply