0% found this document useful (0 votes)
28 views11 pages

Lab 15 - Managing LVM Logical Volumes - Exercises

Uploaded by

Thien Duong
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views11 pages

Lab 15 - Managing LVM Logical Volumes - Exercises

Uploaded by

Thien Duong
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Exercise 15.

1 Creating the Physical Volume


In this exercise, you create a physical volume. To do this exercise, you
need a hard disk that has free (unpartitioned) disk space available. The
recommended method to make disk space available is by adding a
new hard disk in your virtual machine environment.
In this exercise, I use a clean /dev/sdb device to create the partition.
You may have to change the device name to match your configuration.
If you do not have a dedicated hard disk available to create this
configuration, you might want to consider attaching a USB key to your
machine.
Type dd if=/dev/sdb of=/root/diskfile bs=1M count=1 . (If your disk is
/dev/sdb, change the disk name accordingly.) Using this command allows you
to create a backup of the first megabyte of raw blocks and write that to the file
/root/diskfile. This file allows you to easily revert to the situation that existed at
the start of this exercise.
1. Open a root shell and type fdisk /dev/sdb
2. Type n to create a new partition. Select p to make it a primary
partition, and use the partition number that is suggested as a default.
If you are using a clean device, this will be partition number 1.
3. Press Enter when asked for the first sector and type +100M to
accept the last sector.

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.

7. Type lvextend -r -l +50%FREE /dev/vgdata/lvdata to extend


lvdata with 50% of all available disk space in the volume group.
8. Type lvs and df -h again to verify that the added disk space has
become available.

9. Type lvreduce -r -L -50M /dev/vgdata/lvdata . This shrinks the


lvdata volume with 50MB. Notice that while doing this the volume is
temporarily unmounted, which happens automatically.

(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.

You might also like