Using Linux LVM on Amazon EC2 Ubuntu Server

This article covers the basics of Linux LVM: initialise physical partitions, create a volume group, create logical volumes in a newly created volume group, build and mount filesystems, add to fstab for automount on boot. 

The Plan

Below is the LVM schema we’re going to use for this article.

Installation

We’re working with Ubuntu¬†Saucy Salamander today:

# cat /etc/issue
Ubuntu 13.10 \n \l

Install LVM suite:

# apt-get update && apt-get install lvm2

We have the partitions prepared (types set to 0x8e):

# fdisk -l 2>/dev/null | grep dev.*LVM
 /dev/xvdg1 2048 20971519 10484736 8e Linux LVM
 /dev/xvdh1 2048 41943039 20970496 8e Linux LVM
 /dev/xvdi1 2048 62914559 31456256 8e Linux LVM

Configuration

Initialise Physical Volumes for LVM

Initialise the partitions for use by LVM:

# pvcreate /dev/xvdg1 /dev/xvdh1 /dev/xvdi1
  Physical volume "/dev/xvdg1" successfully created
  Physical volume "/dev/xvdh1" successfully created
  Physical volume "/dev/xvdi1" successfully created

Check attributes of physical volumes:

# pvdisplay
  "/dev/xvdg1" is a new physical volume of "10.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/xvdg1
  VG Name               
  PV Size               10.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               kcRHJq-zPTP-0Vld-J3Ut-AAYl-MY62-J0R0Dq
   
  "/dev/xvdh1" is a new physical volume of "20.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/xvdh1
  VG Name               
  PV Size               20.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               LWHp3K-9IwJ-WfYC-Jr6X-TeTw-yyRm-MMaIS5
   
  "/dev/xvdi1" is a new physical volume of "30.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/xvdi1
  VG Name               
  PV Size               30.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               wQ2CwT-EiRp-uHEq-epjd-v49t-3o0e-nkrmb4

Create Volume Group

We will use proftpd named volume group:

# vgcreate proftpd /dev/xvdg1 /dev/xvdh1 /dev/xvdi1
  Volume group "proftpd" successfully created

Check attributes of proftpd volume group:

# vgdisplay
  --- Volume group ---
  VG Name               proftpd
  System ID             
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               59.99 GiB
  PE Size               4.00 MiB
  Total PE              15357
  Alloc PE / Size       0 / 0   
  Free  PE / Size       15357 / 59.99 GiB
  VG UUID               zFMSvn-fd92-OZKx-1rxp-7JBq-16pg-oD5UQX
# vgdisplay -s
  "proftpd" 59.99 GiB [0         used / 59.99 GiB free]
# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "proftpd" using metadata type lvm2

Create Logical Volumes

We will now create 3 logical volumes, data (40GB), anon (10GB) and backup (2GB), in the proftpd volume group :

# lvcreate --name ftpdata --size 40G proftpd
  Logical volume "ftpdata" create
# lvcreate --name anon --size 10G proftpd
  Logical volume "anon" created
# lvcreate --name backup --size 2G proftpd
  Logical volume "backup" created

Check attributes of logical volumes:

# lvdisplay
  --- Logical volume ---
  LV Path                /dev/proftpd/ftpdata
  LV Name                ftpdata
  VG Name                proftpd
  LV UUID                xJkNq4-nIrf-EevW-i73u-MV5s-PpFO-yDR1MU
  LV Write Access        read/write
  LV Creation host, time ubuntu, 2014-04-26 17:29:56 +0000
  LV Status              available
  # open                 0
  LV Size                40.00 GiB
  Current LE             10240
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0
   
  --- Logical volume ---
  LV Path                /dev/proftpd/anon
  LV Name                anon
  VG Name                proftpd
  LV UUID                xodYjm-1tVo-lChO-R1FU-otIC-QAr3-CK7esb
  LV Write Access        read/write
  LV Creation host, time ubuntu, 2014-04-26 17:30:23 +0000
  LV Status              available
  # open                 0
  LV Size                10.00 GiB
  Current LE             2560
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:1
   
  --- Logical volume ---
  LV Path                /dev/proftpd/backup
  LV Name                backup
  VG Name                proftpd
  LV UUID                mjMAPZ-VSPZ-XYtu-Prkg-4bjx-0DKw-eOgkGX
  LV Write Access        read/write
  LV Creation host, time ubuntu, 2014-04-26 17:30:45 +0000
  LV Status              available
  # open                 0
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:2
# lvdisplay -C
  LV      VG      Attr      LSize  Pool Origin Data%  Move Log Copy%  Convert
  anon    proftpd -wi-a---- 10.00g                                           
  backup  proftpd -wi-a----  2.00g                                           
  ftpdata proftpd -wi-a---- 40.00g
# lvscan
  ACTIVE            '/dev/proftpd/ftpdata' [40.00 GiB] inherit
  ACTIVE            '/dev/proftpd/anon' [10.00 GiB] inherit
  ACTIVE            '/dev/proftpd/backup' [2.00 GiB] inherit

Create Filesystems and Mountpoints

Create ext4 filesystems on all logical volumes:

# mkfs.ext4 /dev/proftpd/ftpdata
# mkfs.ext4 /dev/proftpd/anon
# mkfs.ext4 /dev/proftpd/backup

Create mountpoints:

# mkdir -p /ftp/ftpdata /ftp/anon /ftp/backup

Mount logical volumes:

# mount /dev/proftpd/ftpdata /ftp/ftpdata
# mount /dev/proftpd/anon /ftp/anon
# mount /dev/proftpd/backup /ftp/backup

Check:

# df -h | grep ftp
/dev/mapper/proftpd-ftpdata   40G   48M   38G   1% /ftp/ftpdata
/dev/mapper/proftpd-anon     9.8G   23M  9.2G   1% /ftp/anon
/dev/mapper/proftpd-backup   2.0G  3.0M  1.8G   1% /ftp/backup

Add Logical Volumes to /etc/fstab

We want logical volumes mounted automatically when the system boots:

# echo "/dev/proftpd/ftpdata /ftp/ftpdata ext4 defaults 0 0" >>/etc/fstab
# echo "/dev/proftpd/anon /ftp/anon ext4 defaults 0 0" >>/etc/fstab
# echo "/dev/proftpd/backup /ftp/backup ext4 defaults 0 0" >>/etc/fstab

Related Posts

Extend an ext4 LVM root Volume

Leave a Reply

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