Chapter 15

Managing Advanced Storage

The following topics are covered in this chapter:

The following RHCSA exam objectives are covered in this chapter:

  • Create and remove physical volumes

  • Assign physical volumes to volume groups

  • Create and delete logical volumes

  • Extend existing logical volumes

In Chapter 14, “Managing Storage,” you learned how to manage partitions on a hard disk. Creating multiple partitions on a disk is useful because it enables you to keep different data types in separate partitions, but it does not offer the flexibility that the advanced storage solutions offer. In this chapter, you learn how to work with advanced storage solutions, including Logical Volume Manager (LVM) and Stratis.

“Do I Know This Already?” Quiz

The “Do I Know This Already?” quiz enables you to assess whether you should read this entire chapter thoroughly or jump to the “Exam Preparation Tasks” section. If you are in doubt about your answers to these questions or your own assessment of your knowledge of the topics, read the entire chapter. Table 15-1 lists the major headings in this chapter and their corresponding “Do I Know This Already?” quiz questions. You can find the answers in Appendix A, “Answers to the ‘Do I Know This Already?’ Quizzes and Review Questions.”

Table 15-1 “Do I Know This Already?” Section-to-Question Mapping

Foundation Topics Section

Questions

Understanding LVM

1–2

Creating LVM Logical Volumes

3–5

Resizing LVM Logical Volumes

6–8

Configuring Stratis

9–10

1. Which of the following is not a standard component in an LVM setup?

  1. Logical volume

  2. File system

  3. Volume group

  4. Physical volume

2. Which of the following is not an LVM feature?

  1. Volume resizing

  2. Hot replacement of failing disk

  3. Copy on write

  4. Snapshots

3. Which partition type do you need on a GPT partition to mark it with the LVM partition type?

  1. 83

  2. 8e

  3. 8300

  4. 8e00

4. Which of the following commands shows correctly how to create a logical volume that uses 50% of available disk space in the volume group?

  1. vgadd -n lvdata -l +50%FREE vgdata

  2. lvcreate lvdata -l 50%FREE vgdata

  3. lvcreate -n lvdata -l 50%FREE vgdata

  4. lvadd -n lvdata -l 50% FREE /dev/vgdata

5. Which commands show an overview of available physical volumes? (Choose two.)

  1. pvshow

  2. pvdisplay

  3. pvs

  4. pvlist

6. Which statement about resizing LVM logical volumes is not true?

  1. The Ext4 file system can be increased and decreased in size.

  2. Use lvextend with the -r option to automatically resize the file system.

  3. The XFS file system cannot be resized.

  4. To increase the size of a logical volume, you need allocatable space in the volume group.

7. You want to remove the physical volume /dev/sdd2 from the volume group vgdata. Which of the following statements about the removal procedure is not true?

  1. The file system must support shrinking.

  2. You need the amount of used extents on /dev/sdd2 to be available on remaining devices.

  3. Before you can use vgreduce, you have to move used extents to the remaining volumes.

  4. Use pvmove to move used extents.

8. You have extended the size of a logical volume without extending the XFS file system it contains. Which of the following solutions can you use to fix it?

  1. Use lvresize again, but this time with the -r option. The command will resize just the file system.

  2. Bring the logical volume back to its original size and then use lvresize -r again.

  3. Use fsresize to resize the file system later.

  4. Use xfs_growfs to grow the file system to the size available in the logical volume.

9. How much storage is used in a Stratis file system for metadata storage?

  1. 527 MiB

  2. 1 GiB

  3. 4 MiB

  4. 4 GiB

10. Which of the following lines correctly shows how a Stratis file system should be mounted through /etc/fstab?

  1. UUID=abcd /stratis xfs defaults 0 0

  2. /dev/stratis/stratis1 /stratis xfs defaults,x-systemd.requires=stratis.service 0 0

  3. UUID=abcd /stratis xfs defaults,x-systemd.requires=stratis.service 0 0

  4. /dev/stratis/stratis1 /stratis xfs defaults 0 0

Foundation Topics

Understanding LVM

In the early days of Linux servers, storage was handled by creating partitions on disks. Even if this approach does work, there are some disadvantages, the most important of which is that partitions are inflexible. That is why the Logical Volume Manager was introduced. Whereas it is not possible to dynamically grow a partition that is running out of disk space, this is possible when working with LVM. LVM offers many other advantages as well, which you learn about in this chapter.

LVM Architecture

In the LVM architecture, several layers can be distinguished. On the lowest layer, the storage devices are used. These can be any storage devices, such as complete disks, partitions, logical units (LUNs) on a storage-area network (SAN), and whatever else is made possible in modern storage topologies. In this chapter you learn how to use partitions as physical volumes, which is recommended practice. By using partitions instead of complete disk devices, it is easy for other tools to recognize that some storage has already been configured on the block device, which makes it less likely that misconfigurations are going to occur.

The storage devices need to be flagged as physical volumes, which makes them usable in an LVM environment and makes them usable by other utilities trying to gain access to the logical volume. A storage device that is a physical volume can be added to the volume group, which is the abstraction of all available storage. The “abstraction” means that the volume group is not something that is fixed, but it can be resized when needed, which makes it possible to add more space on the volume group level when volumes are running out of disk space. The idea is simple: If you are running out of disk space on a logical volume, you take available disk space from the volume group. And if there is no available disk space in the volume group, you just add it by adding a physical volume.

On top of the volume group are the logical volumes. Logical volumes do not act on disks directly but get their disk space from available disk space in the volume group. That means that a logical volume may consist of available storage from multiple physical volumes, which adds an important layer of additional flexibility to the storage configuration.

Note

It is a good idea to avoid logical volumes from spanning multiple physical volumes; if one of the physical volumes breaks, all files on the LVM file system will become inaccessible.

The actual file systems are created on the logical volumes. Because the logical volumes are flexible with regard to size, that makes the file systems flexible as well. If a file system is running out of disk space, it is relatively easy to extend the file system or to reduce it if the file system allows that. Note that in order to resize file systems when logical volumes are resized, the file systems must offer support for that.

Figure 15-1 gives an overview of the LVM architecture.

An icon reads, Key Topic.
A figure shows the LVM Architecture Overview.

Figure 15-1 LVM Architecture Overview

LVM Features

There are several reasons why LVM is great. The most important reason is that LVM offers a flexible solution for managing storage. Volumes are no longer bound to the restrictions of physical hard drives. If additional storage space is needed, the volume group can easily be extended by adding a new physical volume, so that disk space can be added to the logical volumes. It is also possible to reduce the size of a logical volume, but only if the file system that was created on that volume supports the feature of reducing the size of the file system. Ext4 supports growing and shrinking; XFS size can only be increased.

Another important reason why administrators like using LVM is the support for snapshots. A snapshot keeps the current state of a logical volume and can be used to revert to a previous situation or to make a backup of the file system on the logical volume if the volume is open. Using snapshots is essential in backup strategies.

LVM snapshots are created by copying the logical volume administrative data (the metadata) that describes the current state of files to a snapshot volume. As long as nothing changes, from the LVM snapshot metadata the original blocks in the original volume are addressed. When blocks are modified, the blocks containing the previous state of the file are copied over to the snapshot volume, which for that reason will grow. Using this method ensures that, by accessing an LVM snapshot volume, the exact state of the files as they were when the snapshot was created can be accessed. Because the snapshot will grow when files on the original volume change, when planning for snapshots, you should make sure that a sufficient amount of disk space is available. Also, snapshots are supposed to be temporary: once a snapshot has served its purpose, it can be removed.

A third important advantage of using LVM logical volumes is the option to replace failing hardware easily. If a hard disk is failing, data can be moved within the volume group (through the pvmove command), the failing disk can then be removed from the volume group, and a new hard disk can be added dynamically, without requiring any downtime for the logical volume itself.

Creating LVM Logical Volumes

Creating LVM logical volumes involves creating the three layers in the LVM architecture. You first have to convert physical devices, such as disks or partitions, into physical volumes (PVs); then you need to create the volume group (VG) and assign PVs to it. As the last step, you need to create the logical volume (LV) itself. In this section, you learn what is involved in creating these three layers.

Different utilities exist for creating LVM logical volumes. This chapter focuses on using the command-line utilities. They are relatively easy to use, and they are available in all environments (whether you are running a graphical interface or not).

Tip

You absolutely do not need to memorize the commands discussed in this chapter for the RHCSA exam. All you really need to remember are pv, vg, and lv. Open a command line, type pv, and press the Tab key twice. This will show all commands that start with pv, which are all commands that are used for managing physical volumes. After you have found the command you need, run this command with the --help option. This shows a usage summary that lists everything you must do to create the element you need. Example 15-1 shows an example of the pvcreate --help command (which is explained in the next subsection).

Example 15-1 Requesting Help for the pvcreate Command

[root@server1 ~]# pvcreate --help
  pvcreate - Initialize physical volume(s) for use by LVM

  pvcreate PV ...
        [ -f|--force ]
        [ -M|--metadatatype lvm2 ]
        [ -u|--uuid String ]
        [ -Z|--zero y|n ]
        [    --dataalignment Size[k|UNIT] ]
        [    --dataalignmentoffset Size[k|UNIT] ]
        [    --bootloaderareasize Size[m|UNIT] ]
        [    --labelsector Number ]
        [    --pvmetadatacopies 0|1|2 ]
        [    --metadatasize Size[m|UNIT] ]
        [    --metadataignore y|n ]
        [    --norestorefile ]
        [    --setphysicalvolumesize Size[m|UNIT] ]
        [    --reportformat basic|json ]
        [    --restorefile String ]
        [ COMMON_OPTIONS ]

  Common options for lvm:
        [ -d|--debug ]
        [ -h|--help ]
        [ -q|--quiet ]
        [ -v|--verbose ]
        [ -y|--yes ]
        [ -t|--test ]
        [    --commandprofile String ]
        [    --config String ]
        [    --driverloaded y|n ]
        [    --nolocking ]
        [    --lockopt String ]
        [    --longhelp ]
        [    --profile String ]
        [    --version ]
        [    --devicesfile String ]
        [    --devices PV ]
        [    --nohints ]
        [    --journal String ]

  Use --longhelp to show all options and advanced commands.

Creating the Physical Volumes

Before you can use the LVM tools to create physical volumes (PVs), you should create a partition marked as the LVM partition type. This is basically the same procedure as described in Chapter 14, with the only difference being that before writing changes to disk, you need to change the partition type.

In fdisk and gdisk, you can use t from the menu to change the type. If you are using an MBR disk, the partition type is 8e. If you are using a GUID disk, use the partition type 8e00. In fdisk you can also just type lvm as the partition type to use, as the RHEL 9 version of fdisk supports using aliases. If you are using parted to create partitions, you need to use the set n lvm on command from within the parted interface (where n is the number of the partition you want to mark for use with LVM).

After creating the partition and flagging it as an LVM partition type, you need to use pvcreate to mark it as a physical volume. This writes some metadata to the partition, which allows it to be used in a volume group. The entire procedure is summarized in Exercise 15-1, in which you create a physical volume. Also see Example 15-2 for an overview of this procedure.

Exercise 15-1 Creating 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 to add a new hard disk in your virtual machine environment. In this exercise, I use a clean /dev/sdd device to create the partition. You may have to change the device name to match your configuration.

  1. Open a root shell and type fdisk /dev/sdd

  2. Type p. This will show the current partition table layout. There should be none at this point.

  3. Type g to create a GPT partition table.

  4. Type n to create a new partition. Press Enter when asked for the partition number, as well as when asked for the first sector.

  5. When prompted for the last sector, type +1G to create a 1-GiB partition.

  6. Type t to change the partition type. As you only have one partition at the moment, this partition is automatically selected. When prompted for the partition type, enter lvm.

  7. Press p to verify the partition was created successfully.

  8. Repeat this procedure to create three other 1-GiB LVM partitions for future use.

  9. Press w to write the new partitions to disk and quit fdisk.

  10. Use the lsblk command to verify that the new partitions were created successfully.

  11. Type pvcreate /dev/sdd1 to mark the new partition as an LVM physical volume (see Example 15-3).

  12. Type pvs to verify that the physical volume was created successfully.

Example 15-2 Creating an LVM Partition in fdisk

[root@
[root@server1 ~]# fdisk /dev/sdd

Welcome to fdisk (util-linux 2.37.4).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): g
Created a new GPT disklabel (GUID:
  3BCE8E49-EFDF-9144-ACD5-290F4FCCDA07).

Command (m for help): n
Partition number (1-128, default 1):
First sector (2048-41943006, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-41943006, default
  41943006): +1G

Created a new partition 1 of type 'Linux filesystem' and of size 1
GiB.

Command (m for help): t
Selected partition 1
Partition type or alias (type L to list all): lvm
Changed type of partition 'Linux filesystem' to 'Linux LVM'.

Command (m for help): p
Disk /dev/sdd: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 3BCE8E49-EFDF-9144-ACD5-290F4FCCDA07

Device     Start      End Sectors Size Type
/dev/sdd1   2048 2099199 2097152   1G Linux LVM

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Example 15-3 Verifying the Physical Volume

[root@server1 ~]# pvcreate /dev/sdd1
  Physical volume "/dev/sdd1" successfully created.
[root@server1 ~]# pvs
  PV         VG   Fmt  Attr PSize   PFree
  /dev/sda2  rhel lvm2 a--  <19.00g    0
  /dev/sdd1       lvm2 ---    1.00g 1.00g

As an alternative to the pvs command, which shows a summary of the physical volumes and their attributes, you can use the pvdisplay command to show more details. Example 15-4 shows an example of the output of this command.

Example 15-4 Sample pvdisplay Command Output

[root@server1 ~]# pvdisplay /dev/sdd1
  "/dev/sdd1" is a new physical volume of "1.00 GiB"
  --- NEW Physical volume ---
  PV Name                /dev/sdd1
  VG Name
  PV Size                1.00 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               cjdhpJ-bRh9-fg3B-KlPh-XQzD-unXV-ycVK36

If you want a compact overview of the current storage configuration on your server, you might also like the lsblk command. As shown in Example 15-5, this command gives a hierarchical overview of which disks and partitions are used in what LVM volume groups and logical volumes.

Example 15-5 Using lsblk for a Compact Overview of the Current Storage Configuration

[root@server1 ~]# lsblk
NAME          MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda             8:0    0  20G  0 disk
├─sda1          8:1    0   1G  0 part /boot
└─sda2          8:2    0  19G  0 part
  ├─rhel-root 253:0    0  17G  0 lvm  /
  └─rhel-swap 253:1    0   2G  0 lvm  [SWAP]
sdb             8:16   0  20G  0 disk
├─sdb1          8:17   0   1G  0 part
├─sdb2          8:18   0   1K  0 part
├─sdb5          8:21   0   1G  0 part
└─sdb6          8:22   0   1G  0 part
sdc             8:32   0  20G  0 disk
└─sdc1          8:33   0   1G  0 part /exercise
sdd             8:48   0  20G  0 disk
└─sdd1          8:49   0   1G  0 part
sr0            11:0    1   8G  0 rom  /repo
nvme0n1       259:0    0  20G  0 disk

Creating the Volume Groups

Now that the physical volume has been created, you can assign it to a volume group (VG). It is possible to add a physical volume to an existing volume group (which is discussed later in this chapter), but here you learn how to create a new volume group and add the physical volume to it. This is a simple one-command procedure. Just type vgcreate followed by the name of the volume group you want to create and the name of the physical device you want to add to it. So, if the physical volume name is /dev/sdd1, the complete command is vgcreate vgdata /dev/sdd1. You are completely free in your choice of name for the volume group. I like to start all volume group names with vg, which makes it easy to find the volume groups if there are many, but you are free to choose anything you like.

Between the previous section and the preceding paragraph, you have learned how to create a volume group in a two-step procedure where you first create the physical volume with the pvcreate command and then add the volume group using the vgcreate command. You can do this in a one-step procedure as well (where using a separate pvcreate command will not be necessary).

The one-step procedure is particularly useful for adding a complete disk device). If you want to add the disk /dev/sdc, for instance, just type vgcreate vgdata /dev/sdc to create a volume group vgdata that contains the /dev/sdc device. When you are doing this to add a device that has not been marked as a physical volume yet, the vgcreate utility will automatically flag it as a physical volume so that you can see it while using the pvs command.

When you’re creating volume groups, a physical extent size is used. The physical extent size defines the size of the building blocks used to create logical volumes. A logical volume always has a size that is a multiple of the physical extent size. If you need to create huge logical volumes, it is more efficient to use a big physical extent size. If you do not specify anything, a default extent size of 4 MiB is used. The physical extent size is always specified as a multiple of 2 MiB, with a maximum size of 128 MiB. Use the vgcreate -s option to specify the physical extent size you want to use.

Note

When you’re working with LVM, you need to consider the physical extent size. This is the size of the basic building blocks used in the LVM configuration. When you’re working with an ext4 file system, logical extents are used. The extent sizes on LVM are in no way related to the extent sizes that are used on the file systems.

After creating the volume group, you can request details about the volume group using the vgs command for a short summary, or the vgdisplay command to get more information. Example 15-6 shows an example of the output of the vgdisplay command.

Example 15-6 Showing Current Volume Group Properties

[root@server1 ~]# vgdisplay vgdata
  --- Volume group ---
  VG Name                vgdata
  System ID
  Format                 lvm2
  Metadata Areas        1
  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                 1
  Act PV                 1
  VG Size                1020.00 MiB
  PE Size                4.00 MiB
  Total PE               255
  Alloc PE / Size       0 / 0
  Free  PE / Size       255 / 1020.00 MiB
  VG UUID               KrzkCo-QUFs-quJm-Z6pM-qMh0-ZchJ-c677c2

Creating the Logical Volumes and File Systems

Now that the volume group has been created, you can start creating one or more logical volumes (LVs) from it. This procedure is slightly more complicated than the creation of physical volumes or volume groups because there are more choices to be made. While creating the logical volume, you must specify a volume name and a size.

The volume size can be specified as an absolute value using the -L option. Use, for instance, -L 5G to create an LVM volume with a 5-GiB size. Alternatively, you can use relative sizes with the -l option. For instance, use -l 50%FREE to use half of all available disk space. You can also use the -l option to specify the number of extents that you want the logical volume to be. You’ll further need to specify the name of the volume group that the logical volume is assigned to, and optionally (but highly recommended), you can use -n to specify the name of the logical volume. For instance, use lvcreate -n lvdata -l 100 vgdata to create a logical volume with the name lvdata and a size of 100 extents and add that to the vgdata volume group. Once the logical volume has been created, you can use the mkfs utility to create a file system on top of it.

Understanding LVM Device Naming

Now that the logical volume has been created, you can start using it. To do this, you need to know the device name. LVM volume device names can be addressed in multiple ways. The simple method is to address the device as /dev/vgname/lvname. So, for example, if you have created a volume with the name lvdata, which gets its available disk space from the vgdata volume group, the device name would be /dev/vgdata/lvdata, which is in fact a symbolic link to the device mapper name (which is explained next).

For naming LVM volumes, another system plays a role: device mapper. The device mapper (abbreviated as dm) is a generic interface that the Linux kernel uses to address storage devices. The device mapper is used by multiple device types, such as LVM volumes, but also by software RAID and advanced network storage devices such as multipath devices.

Device mapper devices are generated on detection and use names that are generated while booting, like /dev/dm-0 and /dev/dm-1. To make these devices easier to access, the device mapper creates symbolic links in the /dev/mapper directory that point to these meaningless device names. The symbolic links follow the naming structure /dev/mapper/vgname-lvname.

So, the device /dev/vgdata/lvdata would also be known as /dev/mapper/vgdata-lvdata. When working with LVM logical volumes, you can use either of these device names. Example 15-7 shows an overview of the different LVM device names as provided by the device mapper. In Exercise 15-2, you learn how to create a volume group and logical volumes.

Example 15-7 LVM Device Name Overview

[root@server1 ~]# ls -l /dev/mapper/vgdata-lvdata /dev/vgdata/lvdata
lrwxrwxrwx. 1 root root 7 Sep 16 11:34 /dev/mapper/vgdata-lvdata ->
  ../dm-2
lrwxrwxrwx. 1 root root 7 Sep 16 11:34 /dev/vgdata/lvdata -> ../dm-2

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/sdd1 physical volume that was created previously.

  2. Type vgcreate vgdata /dev/sdd1. 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.ext4 /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 the bottom of /etc/fstab:

    /dev/vgdata/lvdata /files ext4 defaults 0 0
  9. Type mount -a to verify that the mount works and mount the file system.

  10. Use lsblk to verify that the partition was mounted successfully.

Table 15-2 summarizes the relevant commands for creating logical volumes.

An icon reads, Key Topic.

Table 15-2 LVM Management Essential Commands

Command

Explanation

pvcreate

Creates physical volumes

pvs

Shows a summary of available physical volumes

pvdisplay

Shows a list of physical volumes and their properties

pvremove

Removes the physical volume signature from a block device

vgcreate

Creates volume groups

vgs

Shows a summary of available volume groups

vgdisplay

Shows a detailed list of volume groups and their properties

vgremove

Removes a volume group

lvcreate

Creates logical volumes

lvs

Shows a summary of all available logical volumes

lvdisplay

Shows a detailed list of available logical volumes and their properties

lvremove

Removes a logical volume

Resizing LVM Logical Volumes

One of the major benefits of using LVM is that LVM volumes are easy to resize, which is very useful if your file system is running out of available disk space. If the XFS file system is used, a volume can be increased, but not decreased, in size. Other file systems such as Ext4 support decreasing the file system size also. You can decrease an Ext4 file system offline only, which means that you need to unmount it before you can resize it. In this section, you learn how to increase the size of an LVM logical volume. To increase the size of a logical volume, you need to have disk space available in the volume group, so we address that first.

Resizing Volume Groups

The most important feature of LVM flexibility lies in the fact that it is so easy to resize the volume groups and the logical volumes that are using disk space from the volume groups. The vgextend command is used to add storage to a volume group, and the vgreduce command is used to take physical volumes out of a volume group. The procedure to add storage to a volume group is relatively easy:

  1. Make sure that a physical volume or device is available to be added to the volume group.

  2. Use vgextend to extend the volume group. The new disk space will show immediately in the volume group.

After extending a volume group, you can use the vgs command to verify that a physical volume has been added to the volume group. In Example 15-8, you can see that the vgdata VG contains two physical volumes, as indicated in the #PV column.

Example 15-8 Verifying VG Resize Operations with vgs

[root@server1 ~]# vgs
  VG      #PV  #LV  #SN   Attr     VSize        VFree
  centos    1    2    0   wz--n-   <19.00g      0
  vgdata    2    1    0   wz--n-   1020.00m     512.00m

Resizing Logical Volumes and File Systems

Like volume groups can be extended with the vgextend command, logical volumes can be extended with the lvextend command. This command has a very useful option -r to take care of extending the file systems on the logical volume at the same time; it is recommended to use this option and not the alternative approach that separately extends the logical volumes and the file systems on top of the logical volumes. Most file system resizing operations can be done online if the file system needs to be extended without unmounting it.

To grow the logical volume size, use lvextend or lvresize, followed by the -r option to resize the file system used on it. Then specify the size you want the resized volume to be. The easiest and most intuitive way to do that is by using -L followed by a + sign and the amount of disk space you want to add, as in lvresize -L +1G -r /dev/vgdata/lvdata. An alternative way to resize the logical volume is by using the -l option. This option is followed either by the number of extents that are added to the logical volume or by the absolute or relative percentage of extents in the volume group that will be used. You can, for example, use the following commands to resize the logical volume:

An icon reads, Key Topic.
  • lvresize -r -l 75%VG /dev/vgdata/lvdata Resizes the logical volume so that it will take 75% of the total disk space in the volume group. Notice that if currently the logical volume is using more than 75% of the volume group disk space, this command will try to reduce the logical volume size!

  • lvresize -r -l +75%VG /dev/vgdata/lvdata Tries to add 75% of the total size of the volume group to the logical volume. This will work only if currently at least 75% of the volume group is unused. (Notice the difference with the previous command.)

  • lvresize -r -l +75%FREE /dev/vgdata/lvdata Adds 75% of all free disk space to the logical volume.

  • lvresize -r -l 75%FREE /dev/vgdata/lvdata Resizes the logical volume to a total size that equals 75% of the amount of free disk space, which may result in an attempt to reduce the logical volume size. (Notice the difference with the previous command.)

A logical extent is the logical building block used when creating logical volumes, and it maps to a physical extent, the size of which can be specified when creating a volume group. All resize operations need to match complete logical extents. You will sometimes notice that the resize size is rounded up or down to the logical extent size. You can also specify the number of logical extents that need to be added or removed directly by using the -l option with the lvresize command.

As you can see, resizing a logical volume has many options, and you need to take care to use the right options because it is easy to make a mistake! In Exercise 15-3, you learn how to resize logical volumes and the file systems used on top of them.

Note

The size of an XFS file system cannot be decreased; it can only be increased. If you need a file system that can be shrunk in size, use Ext4, not XFS.

Exercise 15-3 Resizing Logical Volumes

In Exercises 15-1 and 15-2, you 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 lsblk to verify that you have an unused partition available that can be added to the volume group. In Exercise 15-1 you created the partition /dev/sdd2 for this purpose.

  3. Type vgextend vgdata /dev/sdd2 to extend vgdata with the total size of the /dev/sdd2 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.

Reducing Volume Groups

If a volume group consists of multiple PVs, a PV can be removed from the VG if the remaining PVs have sufficient free space to allocate the extents it currently uses. This procedure will not work if the remaining PVs are fully used already. Removing a PV from a VG is a two-step procedure. First, use pvmove to move used extents from the PV that you want to remove to any of the remaining volumes. Next, use vgreduce to complete the PV removal. In Exercise 15-4 you can practice this.

Exercise 15-4 Removing a VG from a PV

  1. Use fdisk to create two partitions with a size of 2 GiB each, and set the type to lvm. In the remainder of this exercise, I’ll assume you’re using the partitions /dev/sdd3 and dev/sdd4 for this purpose.

  2. Use vgcreate vgdemo /dev/sdd3 to create a volume group.

  3. Type lvcreate -L 1G -n lvdemo /dev/vgdemo to create a logical volume with a size of 1 GiB. Notice that it is essential not to use all of the available disk space!

  4. Type vgextend vgdemo /dev/sdd4 to extend the volume group.

  5. Use pvs to verify extent usage on /dev/sdd3 and /dev/sdd4. You should see that sdd3 is using about half of its extents, and all extents on /dev/sdd4 are still unused.

  6. Now type lvextend -L +500M /dev/vgdemo/lvdemo /dev/sdd4 to grow the lvdemo logical volume. Notice that you have to add /dev/sdd4 to ensure that free extents will be taken from the sdd4 device.

  7. Type pvs to verify current extent usage on the devices.

  8. Create a file system, using mkfs.ext4 /dev/vgdemo/lvdemo

  9. Temporarily mount the logical volume, using mount /dev/vgdemo/lvdemo /mnt

  10. Use df -h to verify disk space usage.

  11. Use dd if=/dev/zero of=/mnt/bigfile bs=1M count=1100. The size ensures that file data is on both PVs.

  12. Now you can prepare sdd4 for removal. As a first step, you need to move all extents it uses to unused extents on sdd1. Type the following to do so: pvmove -v /dev/sdd4 /dev/sdd3. This can take a minute or two to complete.

  13. Type pvs, which will show that /dev/sdd4 is now unused.

  14. At this point you can remove the unused physical volume, using vgreduce vgdemo /dev/sdd4

Configuring Stratis

In RHEL 9, Red Hat is offering Stratis as an advanced storage solution. Stratis is a so-called volume-managing file system, and it introduces advanced storage features that were not available prior to RHEL 8. By doing so, Red Hat intends to offer an alternative to the Btrfs and ZFS file systems that are used in other environments. The following features are offered by Stratis:

  • Thin provisioning: This feature enables a Stratis file system to present itself to users as much bigger than it really is. This is useful in many environments, such as virtual desktops, where each user may see 20 GiB of available storage in total although a much lower amount is actually provisioned to each user.

  • Snapshots: A Stratis snapshot allows users to take a “picture” of the current state of a file system. This snapshot makes it easy to revert to the previous state of a file system, rolling back any changes that have been made.

  • Cache tier: Cache tier is a Ceph storage feature that ensures that data can be stored physically closer to the Ceph client, which makes data access faster.

  • Programmatic API: The programmatic API ensures that storage can easily be configured and modified through API access. This is particularly interesting in cloud environments, where setting up storage directly from cloud-native applications is extremely useful.

  • Monitoring and repair: Whereas older file systems need tools like fsck to verify the integrity of the file system, Stratis has built-in features to monitor the health of the file system and repair it if necessary.

Understanding Stratis Architecture

The lowest layer in the Stratis architecture is the pool. From a functional perspective, the Stratis pool is comparable to an LVM volume group. A pool represents all the available storage and consists of one or more storage devices, which in a Stratis environment are referred to as blockdev. These block devices may not be thin provisioned at the underlying hardware level. Stratis creates a /dev/stratis/poolname directory for each pool.

From the Stratis pool, XFS file systems are created. Note that Stratis only works with XFS, and the XFS file system it uses is integrated with the Stratis volume. When a file system is created, no size is specified, and each file system can grow up to the size of all the available storage space in the pool. Stratis file systems are always thin provisioned. The thin volume automatically grows as more data is added to the file system.

Creating Stratis Storage

Creating Stratis volumes is a multistep process. This section provides a high-level overview, and then Exercise 15-5 in the following section guides you through the procedure. You start by creating a pool. Once the pool has been added, you can create file systems from it. Before you begin, make sure that the block devices you’re going to use in Stratis have a minimal size of 5 GiB. Each Stratis file system occupies a minimum of 527 MiB of disk space, even if no data has been copied to the file system.

  1. Install the Stratis software using dnf by installing the stratis-cli and stratisd packages.

  2. Start and enable the user-space daemon, using systemctl enable --now stratisd.

  3. Once the daemon is running, use the stratis pool create command to create the pool that you want to work with. For instance, use stratis pool create mypool /dev/sde to create a pool that is based on the block device /dev/sdd. You can add additional block devices later, using stratis pool add-data poolname blockdevname, as in stratis pool add-data mypool /dev/sde.

  4. Once you have created the pool, add a file system using stratis fs create poolname fsname.

  5. To verify that all was created successfully, use the stratis fs list command.

  6. After creating the file system, you can mount it. To mount a Stratis file system through /etc/fstab, you must use the UUID; using the device name is not supported. Also, when mounting the Stratis volume through /etc/fstab, include the mount option x-systemd.requires=stratisd.service to ensure that the Systemd waits to activate this device until the stratisd service is loaded. Without this option you won’t be able to boot your system anymore.

Managing Stratis

After creating the Stratis file system, you can perform several different management tasks. To start with, you can dynamically extend the pool, using stratis pool add-data. Also, you need to monitor Stratis volumes using Stratis-specific tools, as the traditional Linux tools cannot handle the thin-provisioned volumes. The following commands are available:

  • stratis blockdev: Shows information about all block devices that are used for Stratis.

  • stratis pool: Gives information about Stratis pools. Note in particular the Physical Used parameter, which should not come too close to the Physical Size parameter.

  • stratis filesystem: Enables you to monitor individual file systems.

Another Stratis feature that you may want to manage is the snapshot. A snapshot contains the state of the file system at the moment the snapshot was created. After creation, the snapshot can be modified. It’s also good to know that the snapshot and its origin are not linked, which allows the snapshot to live longer than the file system it was created from. This is fundamentally different from, for instance, LVM snapshots, which cannot stay alive if the volume they are linked to is removed.

In Exercise 15-5, you set up an environment with Stratis volumes.

Exercise 15-5 Managing Stratis Volumes

You need one dedicated disk with a minimal size of 5 GiB to perform the steps in this exercise. In this exercise, the disk name /dev/sde is used as an example. Replace this name with the disk device name that is presented on your hardware.

  1. Type dnf install stratisd stratis-cli to install all the required packages.

  2. Type systemctl enable --now stratisd to enable the Stratis daemon.

  3. Type stratis pool create mypool /dev/sde to add the entire disk /dev/sde to the storage pool.

  4. Type stratis pool list to verify successful creation of the pool.

  5. Type stratis fs create mypool stratis1 to create the first Stratis file system. Note that you don’t have to specify a file system size.

  6. Type stratis fs list to verify the creation of the file system.

  7. Type mkdir /stratis1 to create a mount point for the Stratis file system.

  8. Type stratis fs list to find the Stratis volume UUID.

  9. Add the following line to /etc/fstab to enable the volume to be mounted automatically. Make sure to use the UUID name that is used by your Stratis file system.

    UUID=xxx /stratis1 xfs defaults,x-systemd.requires=stratisd.
    service   0 0
  10. Type mount -a to mount the Stratis volume. Use the mount command to verify that this procedure worked successfully.

  11. Type cp /etc/[a-f]* /stratis1 to copy some files to the Stratis volume.

  12. Type stratis filesystem snapshot mypool stratis1 stratis1-snap to create a snapshot of the volume you just created. Note that this command may take up to a minute to complete.

  13. Type stratis filesystem list to get statistics about current file system usage.

  14. Type rm -f /stratis1/a* to remove all files that have a name starting with a.

  15. Type mount /dev/stratis/mypool/stratis1-snap /mnt and verify that the files whose names start with a are still available in the /mnt directory.

  16. Reboot your server. After reboot, verify that the Stratis volume is still automatically mounted.

Summary

In this chapter, you learned how to work with advanced storage on RHEL 9. First, you read how LVM is used to bring flexibility to storage. By using LVM, you get the advantages of volumes that can be resized easily and multidevice logical volumes. Next, you were introduced to Stratis, the volume-managing file system. Stratis brings next-generation storage features to RHEL 9, and by default creates thin-provisioned file systems.

Exam Preparation Tasks

As mentioned in the section “How to Use This Book” in the Introduction, you have several choices for exam preparation: the end-of-chapter labs; the memory tables in Appendix C; Chapter 27, “Final Preparation”; and the practice exams.

Review All Key Topics

Review the most important topics in the chapter, noted with the Key Topic icon in the margin of the page. Table 15-3 lists a reference for these key topics and the page number on which each is found.

An icon reads, Key Topic.

Table 15-3 Key Topics for Chapter 15

Key Topic Element

Description

Page

Figure 15-1

LVM Architecture Overview

347

Table 15-2

LVM Management Essential Commands

357

List

LVM lvresize commands

359

Complete Tables and Lists from Memory

Print a copy of Appendix C, “Memory Tables” (found on the companion website), or at least the section for this chapter, and complete the tables and lists from memory. Appendix D, “Memory Tables Answer Key,” includes completed tables and lists to check your work.

Define Key Terms

Define the following key terms from this chapter and check your answers in the glossary:

snapshot

physical volume (PV)

volume group (VG)

physical extent

logical volume (LV)

device mapper

logical extent

Stratis

Review Questions

The questions that follow are meant to help you test your knowledge of concepts and terminology and the breadth of your knowledge. You can find the answers to these questions in Appendix A.

1. Which partition type is used on a GUID partition that needs to be used in LVM?

2. Which command enables you to create a volume group with the name vgroup that contains the physical device /dev/sdb3 and uses a physical extent size of 4 MiB?

3. Which command shows a short summary of the physical volumes on your system as well as the volume group to which these belong?

4. What do you need to do to add an entire hard disk /dev/sdd to the volume group vgroup?

5. Which command enables you to create a logical volume lvvol1 with a size of 6 MiB?

6. Which command enables you to add 100 MB to the logical volume lvvol1, assuming that the disk space is available in the volume group?

7. Which two commands do you use to remove a physical volume from a volume group?

8. When working with Stratis, what line would you add to /etc/fstab to mount the Stratis volume?

9. Which command do you use to create a Stratis pool that is based on the block device /dev/sdd?

10. How do you format a Stratis volume with the Ext4 file system?

End-of-Chapter Labs

To complete the following end-of-chapter labs, you need a dedicated disk device. Either use a USB thumb drive or add a new virtual disk to your virtual environment before starting.

Lab 15.1

  1. Create a 500-MB logical volume named 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 250 MB 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.

Lab 15.2

  1. Create a Stratis pool with a size of 5 GiB. In this pool, create two Stratis file systems and ensure that they are automatically mounted.

  2. Add an additional block device to the Stratis pool and verify that the size of the pool was successfully extended.

  3. Ensure that the new Stratis device is automatically mounted on the directory /stratis while rebooting.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset