Effective storage management is a constant challenge in any enterprise environment. The ability to react quickly to increasing storage needs without disrupting the current configuration is key. In this activity, we will set up Logical Volume Manager (LVM) storage utilities to address this challenge.
We will partition a disk for use with LVM, and then create Physical Volumes, Volume Groups, and Logical Volumes. We will also delete a Logical Volume, and extend a Volume Group to be able to provide additional space in a Logical Volume. Learning how to use the flexibility of LVM makes us more effective at storage management.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Create Linux LVM Type Partitions on /dev/xvdb and /dev/xvdc to Use All Space
Start an interactive
root
shell withsudo
. Usefdisk
to create a new default partition of type 8e on/dev/xvdb
and/dev/xvdc
. Create the first:sudo -i fdisk /dev/xvdb
Use the
n
command and choose all the defaults to create a new partition:Command (m for help): n Partition Type: p Partition number (1-4, default 1): Press Enter to accept the default First sector: Press Enter to accept the default Last sector: Press Enter to accept the default
Use the
t
command to change to 8e (Linux LVM):Command (m for help): t Selected partition 1 Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM'
Use the
w
command to write the changes to the partition table and exit:Command (m for help): w
Now create the second:
fdisk /dev/xvdc
Use the
n
command and choose all the defaults to create a new partition:Command (m for help): n Partition Type: p Partition number (1-4, default 1): Press Enter to accept the default First sector: Press Enter to accept the default Last sector: Press Enter to accept the default
Use the
t
command to change to 8e (Linux LVM):Command (m for help): t Selected partition 1 Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM'
Use the
w
command to write the changes to the partition table and exit.The result is that the
/dev/xvdb1
and/dev/xvdc1
partitions of type 8e have been created.- Create Physical Volumes with the LVM Partitions /dev/xvdb1 and /dev/xvdc1, and Create the Volume Group volgroup Using /dev/xvdb1
Initialize the
/dev/xvdb1
and/dev/xvdc1
LVM partitions as Physical Volumes withpvcreate
. Inspect the Physical Volumes withpvs
andpvdisplay
:pvcreate /dev/xvdb1 /dev/xvdc1 pvs pvdisplay
Use
vgcreate
to create thevolgroup
Volume Group using the/dev/xvdb1
Physical Volume. Inspectvolgroup
withvgs
andvgdisplay
:vgcreate volgroup /dev/xvdb1 vgs vgdisplay
- Create the Logical Volume datavol Using 3GB of Space and tempvol Using 1GB of Space
Use the
lvcreate
command to create two Logical Volumes, a 3 GB nameddatavol
and a 1 GB namedtempvol
. Inspect them usinglvs
andlvdisplay
commands:lvcreate -n datavol -L3G volgroup lvcreate -n tempvol -L1G volgroup lvs lvdisplay
- Remove /dev/volgroup/tempvol, Extend volgroup with /dev/xvdc1, and Then Resize /dev/volgroup/datavol to Use All Space in the Volume Group
Use
lvremove
to get rid of thetempvol
, then runvgextend
to expand the volume group. Create an ext4 filesystem on/dev/volgroup/datavol
and mount it on/mnt/data
. Uselvresize
to extend thedatavol
Logical Volume and filesystem to the maximum size possible. Check everything afterward using thedf
andvgs
commands:lvremove /dev/volgroup/tempvol Type 'y' and Enter to confirm vgs vgextend volgroup /dev/xvdc1 vgs vgdisplay mkfs -t ext4 /dev/volgroup/datavol mkdir /mnt/data mount /dev/volgroup/datavol /mnt/data df -h /mnt/data lvresize -r -L 9.99G /dev/volgroup/datavol df -h
- Configure the /dev/volgroup/datavol Logical Volume to Mount on /mnt/data Persistently
Unmount the
/mnt/data
directory with theumount
command:umount /mnt/data
Add the following line to
/etc/fstab
:/dev/volgroup/datavol /mnt/data ext4 defaults 0 1
Use an editor like
vim
to add the line to the file:vim /etc/fstab
Mount the device with the
mount
command. Usedf
to verify it mounted:mount -a df -h /mnt/data