This is a simple manual to set up LVM, it says for EC2 but it can also be used with non-ec2 servers, the difference is that you won’t create a new volume and attach to the instance, you will have to add a physical disc on your server and do all the procedure.

Creating the disk

  • Create a new volume (it MUST be in the same Availability Zone as the EC2)
  • Attach the volume to the instance i.e. “/dev/sdb”

Setting up the disk

  • Connect to the server and run:
fdisk -l
  • with the name of the new disk, run:
fdisk /dev/xvdb
  • then should do those commands in this order:
n
p
1
enter
enter
t
8e
w

now you have the disk created and ready.

Creating the LVM

  • Create a Physical Volume
pvcreate /dev/xvdb1
  • Create a Volume Group
vgcreate lvm00 /dev/xvdb1
  • Create a Logical Volume
    If you want to use the whole disk, run:
lvcreate -l 100%FREE -n <name of logical volume> <colume group> (lvcreate -l 100%FREE -n pack lvm00)

if you don’t, run:

lvcreate -n <name of logical volume> -L <size must be an integer>G <volume group> 
(lvcreate -n pack -L 50G lvm00)
  • Create the filesystem
mkfs.ext4 /dev/mapper/lvm00-pack

Now you have your LVM ready.

Mounting your folder

  • First create the folder
mkdir /pack
  • Mount the folder on the partition
mount /dev/mapper/lvm00-pack /pack
  • Add the new partition to fstab
vim /etc/fstab
  • Add the line with your partition
/dev/mapper/lvm00-pack /pack ext4 defaults 0 0

If it’s a new server, reboot to check if everything is working well or you can just mount directly from the /etc/fstab:

mount -a

Leave a Reply

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