Work With LVM - 1513366044
Work With LVM - 1513366044
Review 6
Add and Remove Volumes, Partition Disks, and Work with LVM Linux Academy + Cloud Assessments
In this lab, we use Logical Volume Manager (LVM) and gdisk to take two disks, partition them,
and combine them into a single volume group. From here, we want to create a logical volume
for use as log storage. When finished, we review how to remove logical and physical volumes,
as well as volume groups.
Add Partitions
Log in to the lab using the credentials provided on the Hands-on Lab page. Switch to the root
user (sudo su -).
Two additional devices have been added to this lab for use with LVM. To see what these devices
are called, run:
Now we can use gdisk to partition and format one of our provided drives. We’ll start with /dev/
xvdf:
This drops us into the gdisk configuration prompt, wherein we’ll be asked to specify the settings
we want to use for our disk. In this instance, we want to create a new partition, set the partition
number to 1, partition the entire provided device, set the file system type to LVM (8e00), and
write the changes to the disk. Many of these settings are the default.
We can now partition our second device. We again want to do this with gdisk:
As before, we want to create a new partition using the defaults for partition number, first sector,
and last section. We also want to continue using the Linux file system for our file system type.
Write the changes and proceed:
-2-
Add and Remove Volumes, Partition Disks, and Work with LVM Linux Academy + Cloud Assessments
OVERWRITE EXISTING
PARTITIONS!!
Confirm that the volumes have been created, and review their settings:
[root@LinuxAcademy ~]#pvdisplay
"/dev/xvdf1" is a new physical volume of "20.00 GiB"
--- NEW Physical volume ---
PV Name /dev/xvdf1
VG Name
PV Size 20.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID k8gf50-dtIT-29Yp-RMPd-eH6E-x2J3-LyQJnx
Here we can see that both 20 GB volumes, /dev/xvdf1 and /dev/xvdj1 are available as
physical volumes for LVM to use.
We can now create our volume group, comprised of both physical volumes. We called our
-3-
Add and Remove Volumes, Partition Disks, and Work with LVM Linux Academy + Cloud Assessments
[root@LinuxAcademy ~]#vgdisplay
--- Volume group ---
VG Name log_vg
System ID
Format lvm2
Metadata Areas 2
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 2
Act PV 2
VG Size 39.99 GiB
PE Size 4.00 MiB
Total PE 10238
Alloc PE / Size 0 / 0
Free PE / Size 10238 / 39.99 GiB
VG UUID x8X7D6-RIHL-Oot9-1asA-UZ1Z-X4rA-NssgU1
Notice that the size of our volume group is about 40 GB – a combination of the two 20 GB
volumes we included in the group.
Now we can create our logical volume from this volume group. To do this, we use the lvcreate
command:
The -n flag denotes that we’re naming the logical volume log_lv, while the -L flag sets the
volume size – in this case, 10 GB. log_vg references back to the volume group we are working
from.
[root@LinuxAcademy ~]#lvdisplay
--- Logical volume ---
LV Path /dev/log_vg/log_lv
LV Name log_lv
VG Name log_vg
-4-
Add and Remove Volumes, Partition Disks, and Work with LVM Linux Academy + Cloud Assessments
LV UUID WYTPo1-6Gk9-lgxh-Q8Rl-PhpW-INGI-PMmHBM
LV Write Access read/write
LV Creation host, time LinuxAcademy, 2017-12-14 10:37:38 -0500
LV Status available
# open 0
LV Size 10.00 GiB
Current LE 2560
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
From here, we can see our logical volume’s path (/dev/log_vg/log_lv), as well as general
information about the logical volume itself, including name, size, write access, creation host,
and more. Copy the LV path.
[root@LinuxAcademy ~]#
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvde1 5.8G 1.5G 4.1G 26% /
tmpfs 270M 0 270M 0% /dev/shm
/dev/mapper/log_vg-log_lv
9.9G 151M 9.2G 2% /mnt/log_files
However, this fails, outputting the error Logical volume log_vg/log_lv contains a
filesystem in use.. This is because our file system is still mounted. Unmount the file system:
Finally, we can rerun the vgremove command to remove the volume group:
Although we’ve removed the volume group, we do still have the two physical volumes left over.
We can remove these, too, using the pvremove command:
Review
We have now walked through the process of setting up physical volumes, volume groups, and
logical volumes using a series of Logical Volume Manager commands, as well as how to remove
these volumes and groups when finished with them. With LVM, we can merge physical disks
into single volumes, easily resize our devices, and —if needed— manage large farms of disks.
-6-