- Lab
-
Libraries: If you want this lab, consider one of these libraries.
- Cloud
Working with Logical Volume Management
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.
Lab Info
Table of Contents
-
Challenge
Create Linux LVM Type Partitions on /dev/xvdb and /dev/xvdc to Use All Space
Start an interactive
rootshell withsudo. Usefdiskto create a new default partition of type 8e on/dev/xvdband/dev/xvdc. Create the first:sudo -i fdisk /dev/xvdbUse the
ncommand 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 defaultUse the
tcommand 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
wcommand to write the changes to the partition table and exit:Command (m for help): wNow create the second:
fdisk /dev/xvdcUse the
ncommand 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 defaultUse the
tcommand 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
wcommand to write the changes to the partition table and exit.The result is that the
/dev/xvdb1and/dev/xvdc1partitions of type 8e have been created. -
Challenge
Create Physical Volumes with the LVM Partitions /dev/xvdb1 and /dev/xvdc1, and Create the Volume Group volgroup Using /dev/xvdb1
Initialize the
/dev/xvdb1and/dev/xvdc1LVM partitions as Physical Volumes withpvcreate. Inspect the Physical Volumes withpvsandpvdisplay:pvcreate /dev/xvdb1 /dev/xvdc1 pvs pvdisplayUse
vgcreateto create thevolgroupVolume Group using the/dev/xvdb1Physical Volume. Inspectvolgroupwithvgsandvgdisplay:vgcreate volgroup /dev/xvdb1 vgs vgdisplay -
Challenge
Create the Logical Volume datavol Using 3GB of Space and tempvol Using 1GB of Space
Use the
lvcreatecommand to create two Logical Volumes, a 3 GB nameddatavoland a 1 GB namedtempvol. Inspect them usinglvsandlvdisplaycommands:lvcreate -n datavol -L3G volgroup lvcreate -n tempvol -L1G volgroup lvs lvdisplay -
Challenge
Remove /dev/volgroup/tempvol, Extend volgroup with /dev/xvdc1, and Then Resize /dev/volgroup/datavol to Use All Space in the Volume Group
Use
lvremoveto get rid of thetempvol, then runvgextendto expand the volume group. Create an ext4 filesystem on/dev/volgroup/datavoland mount it on/mnt/data. Uselvresizeto extend thedatavolLogical Volume and filesystem to the maximum size possible. Check everything afterward using thedfandvgscommands: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 -
Challenge
Configure the /dev/volgroup/datavol Logical Volume to Mount on /mnt/data Persistently
Unmount the
/mnt/datadirectory with theumountcommand:umount /mnt/dataAdd the following line to
/etc/fstab:/dev/volgroup/datavol /mnt/data ext4 defaults 0 1Use an editor like
vimto add the line to the file:vim /etc/fstabMount the device with the
mountcommand. Usedfto verify it mounted:mount -a df -h /mnt/data
About the author
Real skill practice before real-world application
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Learn by doing
Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.
Follow your guide
All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.
Turn time into mastery
On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.