Lab 15 - Managing LVM Logical Volumes - Exercises
Lab 15 - Managing LVM Logical Volumes - Exercises
4. Once you are back on the fdisk prompt, type t to change the
partition type. Because there is one partition only, fdisk does not ask
which partition to use this partition type on. You may have to select a
partition if you are using a different configuration.
5. The partitioner asks for the partition type you want to use. Type 8e .
Then, press w to write changes to disk and quit fdisk. Listing 15.2
shows an overview of all commands that have been used so far. If you
are getting a message that the partition table could not be updated
while writing the changes to disk, reboot your system.
6. Now that the partition has been created, you need to flag it as an
LVM physical volume. To do this, type pvcreate /dev/sdb1 . You
should now get this prompt: Physical volume “/dev/vbd1” successfully
created.
7. Now type pvs to verify that the physical volume has been created
successfully. Notice that in this listing another physical volume already
exists; that is because RHEL uses LVM by default to organize storage.
Exercise 15.2 Creating the Volume Group and Logical Volumes
In Exercise 15.1, you created a physical volume. In this exercise, you
continue working on that physical volume and assign it to a volume
group. Then you add a logical volume from that volume group. You can
work on this exercise only after successful completion of Exercise 15.1.
1. Open a root shell. Type pvs to verify the availability of physical
volumes on your machine. You should see the /dev/sdb1 physical
volume that was created previously.
2. Type vgcreate vgdata /dev/sdb1 . This will create the volume
group with the physical volume assigned to it.
3. Type vgs to verify that the volume group was created successfully.
Also type pvs . Notice that this command now shows the name of the
physical volumes, with the names of the volume groups they are
assigned to.
4. Type lvcreate -n lvdata -l 50%FREE vgdata . This creates an LVM
logical volume with the name lvdata, which will use 50% of available
disk space in the vgdata volume group.
5. Type lvs to verify that the volume was added successfully.
6. At this point, you are ready to create a file system on top of the
logical volume. Type mkfs.xfs /dev/vgdata/lvdata to create the file
system.
7. Type mkdir /files to create a folder on which the volume can be
mounted.
8. Add the following line to /etc/fstab:
/dev/vgdata/lvdata /files xfs defaults 1 2
9. Type mount -a to verify that the mount works and mount the file
system.
Exercise 15.3 Resizing Logical Volumes
In Exercises 15.1 and 15.2, you have created a physical volume,
volume group, and logical volume. In this exercise, you extend the size
of the logical volume and the file system used on top of it.
1. Type pvs and vgs to show the current physical volume and volume
group configuration.
2. Use fdisk to add another partition with a size of 100M. Do not forget
to flag this partition with the LVM partition type. I’ll assume this new
partition is /dev/sdb2 for the rest of this exercise. Replace this name
with the name used on your configuration. (partprobe /dev/sdb)
3. Type vgextend vgdata /dev/sdb2 to extend vgdata with the total
size of the /dev/sdb2 device.
4. Type vgs to verify that the available volume group size has
increased.
5. Type lvs to verify the current size of the logical volume lvdata.
6. Type df -h to verify the current size of the file system on lvdata.
(If the XFS file system is used, a volume can be increased, but not
decreased, in size.)
End-of-Chapter Labsnd-of-Chapter Labs
To complete the end-of-chapter labs with this chapter, you need a
dedicated disk device. Use a USB thumb drive, or add a new virtual
disk to your virtual environment before starting.
Lab 15.1
1. Create a 500MB logical volume lvgroup. Format it with the XFS file
system and mount it persistently on /groups. Reboot your server to
verify that the mount works.
2. After rebooting, add another 250MB to the lvgroup volume that you
just created. Verify that the file system resizes as well while resizing
the volume.
3. Verify that the volume extension was successful.