Difference between revisions of "Adding Storage to a RHEL Volume Group and Logical Volume"

From Techotopia
Jump to: navigation, search
(Created page with "{{#pagetitle: Adding Storage to a RHEL 8 Volume Group and Logical Volume }} <table border="0" cellspacing="0" width="100%"><tr> <td width="20%">Adding a New Disk Drive to a...")
 
(An Overview of Logical Volume Management (LVM))
(2 intermediate revisions by the same user not shown)
Line 26: Line 26:
 
=== Volume Group (VG) ===
 
=== Volume Group (VG) ===
  
+
The Volume Group is the high level container which holds one or more logical volumes and physical volumes.
The Volume Group is the high level container which holds one or more logical volumes and physical volumes.  
+
 
+
 
=== Physical Volume (PV)  ===
 
=== Physical Volume (PV)  ===
  
 
 
A physical volume represents a storage device such as a disk drive or other storage media.  
 
A physical volume represents a storage device such as a disk drive or other storage media.  
+
 
 
=== Logical Volume (LV)  ===
 
=== Logical Volume (LV)  ===
 
 
 
 
A logical volume is the equivalent to a disk partition and, as with a disk partition, can contain a file system.  
 
A logical volume is the equivalent to a disk partition and, as with a disk partition, can contain a file system.  
 
 
 
=== Physical Extent (PE)  ===
 
=== Physical Extent (PE)  ===
 
+
+
 
Each physical volume (PV) is divided into equal size blocks known as physical extents.  
 
Each physical volume (PV) is divided into equal size blocks known as physical extents.  
 
 
 
=== Logical Extent (LE)  ===
 
=== Logical Extent (LE)  ===
  
 
 
Each logical volume (LV) is divided into equal size blocks called logical extents.  
 
Each logical volume (LV) is divided into equal size blocks called logical extents.  
 
 
 
Suppose we are creating a new volume group called VolGroup001. This volume group needs physical disk space in order to function so we allocate three disk partitions ''/dev/sda1'', ''/dev/sdb1'' and ''/dev/sdb2''. These become physical volumes in VolGroup001. We would then create a logical volume called LogVol001 within the volume group made up of the three physical volumes.  
 
Suppose we are creating a new volume group called VolGroup001. This volume group needs physical disk space in order to function so we allocate three disk partitions ''/dev/sda1'', ''/dev/sdb1'' and ''/dev/sdb2''. These become physical volumes in VolGroup001. We would then create a logical volume called LogVol001 within the volume group made up of the three physical volumes.  
 
 
If we run out of space in LogVol001 we simply add more disk partitions as physical volumes and assign them to the volume group and logical volume.  
+
If we run out of space in LogVol001 we simply add more disk partitions as physical volumes and assign them to the volume group and logical volume.
+
 
 
== Getting Information about Logical Volumes  ==
 
== Getting Information about Logical Volumes  ==
  

Revision as of 20:53, 10 June 2019

PreviousTable of ContentsNext
Adding a New Disk Drive to a RHEL 8 SystemAdding and Managing RHEL 8 Swap Space


You are reading a sample chapter from the Red Hat Enterprise Linux 8 (RHEL 8) Essentials book.

Purchase a full copy of Red Hat Enterprise Linux 8 (RHEL 8) Essentials in eBook ($24.99) or Print ($36.99) format

Red Hat Enterprise Linux 8 Essentials Print and eBook (ePub/PDF/Kindle) editions contain 31 chapters and over 250 pages

Buy Print Preview Book


In the previous chapter we looked at adding a new disk drive to a RHEL 8 system, creating a partition and file system and then mounting that file system so that the disk can be accessed. An alternative to creating fixed partitions and file systems is to use Logical Volume Management (LVM) to create logical disks made up of space from one or more physical or virtual disks or partitions. The advantage of using LVM is that space can be added to or removed from logical volumes as needed without the need to spread data over multiple file systems.

Let us take, for example, the root (/home) file system of a RHEL 8-based server. Without LVM this file system would be created with a certain size when the operating system is installed. If a new disk drive is installed there is no way to allocate any of that space to the /home file system. The only option would be to create new file systems on the new disk and mount them at particular mount points. In this scenario you would have plenty of space on the new file system but the /home file system would still be nearly full. The only option would be to move files onto the new file system. With LVM, the new disk (or part thereof) can be assigned to the logical volume containing the root file system thereby dynamically extending the space available.

In this chapter we will look at the steps necessary to add new disk space to both a volume group and a logical volume for the purpose of adding additional space to the root file system of a RHEL 8 system.




An Overview of Logical Volume Management (LVM)

LVM provides a flexible and high level approach to managing disk space. Instead of each disk drive being split into partitions of fixed sizes onto which fixed size file systems are created, LVM provides a way to group together disk space into logical volumes which can be easily resized and moved. In addition, LVM allows administrators to carefully control disk space assigned to different groups of users by allocating distinct volume groups or logical volumes to those users. When the space initially allocated to the volume is exhausted the administrator can simply add more space without having to move the user files to a different file system.

LVM consists of the following components:

Volume Group (VG)

The Volume Group is the high level container which holds one or more logical volumes and physical volumes.


Physical Volume (PV)

A physical volume represents a storage device such as a disk drive or other storage media.

Logical Volume (LV)

A logical volume is the equivalent to a disk partition and, as with a disk partition, can contain a file system.

Physical Extent (PE)

Each physical volume (PV) is divided into equal size blocks known as physical extents.

Logical Extent (LE)

Each logical volume (LV) is divided into equal size blocks called logical extents.

Suppose we are creating a new volume group called VolGroup001. This volume group needs physical disk space in order to function so we allocate three disk partitions /dev/sda1, /dev/sdb1 and /dev/sdb2. These become physical volumes in VolGroup001. We would then create a logical volume called LogVol001 within the volume group made up of the three physical volumes.

If we run out of space in LogVol001 we simply add more disk partitions as physical volumes and assign them to the volume group and logical volume.

Getting Information about Logical Volumes

As an example of using LVM with RHEL 8 we will work through an example of adding space to the / file system of a standard RHEL 8 installation. Anticipating the need for flexibility in the sizing of the root partition, RHEL 8 sets up the / file system as a logical volume (called root) within a volume group called rhel. Before making any changes to the LVM setup, however, it is important to first gather information.

Running the mount command will output information about a range of mount points, including the following entry for the root filesystem:

/dev/mapper/rhel-root on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota) 

Information about the volume group can be obtained using the vgdisplay command:

# vgdisplay
  --- Volume group ---
  VG Name               rhel
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <189.67 GiB
  PE Size               4.00 MiB
  Total PE              48555
  Alloc PE / Size       48555 / <189.67 GiB
  Free  PE / Size       0 / 0   
  VG UUID               RasoLO-Ibja-WBYz-tZLW-zAgO-9uCw-QQRHaE

As we can see in the above example, the rhel volume group has a physical extent size of 4.00MB and has a total of 189.67GB available for allocation to logical volumes. Currently 48555 physical extents are allocated equaling the total 189.67GB capacity. If we want to increase the space allocated to any logical volumes in the rhel volume group, therefore, we will need to add one or more physical volumes. The vgs tool is also useful for displaying a quick overview of the space available in the volume groups on a system:

# vgs
  VG   #PV #LV #SN Attr   VSize   VFree 
  rhel   2   3   0 wz--n- 197.66g 96.00m

Information about logical volumes in a volume group may similarly be obtained using the lvdisplay command:

# lvdisplay
  --- Logical volume ---
  LV Path                /dev/rhel/swap
  LV Name                swap
  VG Name                rhel
  LV UUID                fwOZsF-ROwu-6eLe-2KDR-JZ0d-Pn4o-K5B0Vb
  LV Write Access        read/write
  LV Creation host, time rhel80desktop, 2019-02-14 11:12:07 -0500
  LV Status              available
  # open                 2
  LV Size                <3.98 GiB
  Current LE             1018
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/rhel/home
  LV Name                home
  VG Name                rhel
  LV UUID                PxuxY5-Zups-dUrD-g74j-3wjF-2e12-hO6YsZ
  LV Write Access        read/write
  LV Creation host, time rhel80desktop, 2019-02-14 11:12:07 -0500
  LV Status              available
  # open                 1
  LV Size                135.69 GiB
  Current LE             34737
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2
   
  --- Logical volume ---
  LV Path                /dev/rhel/root
  LV Name                root
  VG Name                rhel
  LV UUID                Ee19Br-aCkG-u5gy-HlMY-PBtB-PMFf-kY302H
  LV Write Access        read/write
  LV Creation host, time rhel80desktop, 2019-02-14 11:12:07 -0500
  LV Status              available
  # open                 1
  LV Size                50.00 GiB
  Current LE             12800
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

As shown in the above example 50 GiB of the space in volume group rhel is allocated to logical volume root (for the / file system), 135.69 GiB to the home volume group (for /home) and 3.98 GiB to swap (for swap space).

Now that we know what space is being used it is often helpful to understand which devices are providing the space (in other words which devices are being used as physical volumes). To obtain this information we need to run the pvdisplay command:

# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               rhel
  PV Size               189.67 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              48555
  Free PE               0
  Allocated PE          48555
  PV UUID               ANrf7v-lSzK-peFM-0mq0-6lOh-JhYx-3Z5dlO

Clearly the space controlled by logical volume rhel is provided via a physical volume located on /dev/sda2.

Now that we know a little more about our LVM configuration we can embark on the process of adding space to the volume group and the logical volume contained within.

Adding Additional Space to a Volume Group from the Command-Line

Just as with the previous steps to gather information about the current Logical Volume Management configuration of a RHEL 8 system, changes to this configuration can be made from the command-line.

In the remainder of this chapter we will assume that a new disk has been added to the system and that it is being seen by the operating system as /dev/sdb. We shall also assume that this is a new disk that does not contain any existing partitions. If existing partitions are present they should be backed up and then the partitions deleted from the disk using the fdisk utility. For example, assuming a device represented by /dev/sdb containing two partitions as follows:

# fdisk -l /dev/sdb
Disk /dev/sdb: 8 GiB, 8589934592 bytes, 16777216 sectors
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: dos
Disk identifier: 0xbd09c991
 
Device     Boot   Start      End  Sectors  Size Id Type
/dev/sdb1          2048  5678545  5676498  2.7G 83 Linux
/dev/sdb2       5679104 16777215 11098112  5.3G 83 Linux

Once the filesystems on these partitions have been unmounted, they can be deleted as follows:

# fdisk /dev/sdb
 
Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
 
Command (m for help): d
Partition number (1,2, default 2): 1
 
Partition 1 has been deleted.
 
Command (m for help): d
Selected partition 2
Partition 2 has been deleted.
 
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Before moving to the next step, be sure to remove any entries in the /etc/fstab file for these filesystems so that the system does not attempt to mount them on the next reboot.

Once the disk is ready, the next step is to convert this disk into a pvcreate command (also wiping the dos signature if one exists):

# pvcreate /dev/sdb
WARNING: dos signature detected on /dev/sdb at offset 510. Wipe it? [y/n]: y
  Wiping dos signature on /dev/sdb.
  Physical volume "/dev/sdb" successfully created.

If the creation fails with a message that reads “Device /dev/<device> excluded by a filter”, it may be necessary to wipe the disk using the wipefs command before creating the physical volume:

# wipefs -a /dev/sdb
/dev/sdb: 8 bytes were erased at offset 0x00000200 (gpt): 45 46 49 20 50 41 52 54
/dev/sdb: 8 bytes were erased at offset 0x1fffffe00 (gpt): 45 46 49 20 50 41 52 54
/dev/sdb: 2 bytes were erased at offset 0x000001fe (PMBR): 55 aa
/dev/sdb: calling ioctl to re-read partition table: Success

With the physical volume created we now need to add it to the volume group (in this case rhel) using the vgextend command:

# vgextend rhel /dev/sdb
  Volume group "rhel" successfully extended

The new physical volume has now been added to the volume group and is ready to be allocated to a logical volume. To do this we run the lvextend tool providing the size by which we wish to extend the volume. In this case we want to extend the size of logical volume home by 7 GB. Note that we need to provide the path to the logical volume which can be obtained from the lvdisplay command (in this case /dev/rhel/home):

# lvextend -L+7G /dev/rhel/home 
  Size of logical volume rhel/home changed from 135.69 GiB (34737 extents) to 142.69 GiB (36529 extents).
  Logical volume rhel/home successfully resized.

The last step in the process is to resize the file system residing on the logical volume so that it uses the additional space. Since we are assuming a default RHEL 8 installation using the XFS filesystem, this can be achieved using the xfs_growfs utility:

# xfs_growfs /home
meta-data=/dev/mapper/rhel-home  isize=512    agcount=4, agsize=8892672 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=35570688, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=17368, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 35570688 to 37405696 

If, on the other hand, the filesystem is of type ext2, ext3, or ext4, the resize2fs utility should be used instead when performing the filesystem resize:

# resize2fs /dev/rhel/home

Once the resize completes, the file system will have been extended to use the additional space provided by the new disk drive. All this has been achieved without moving a single file or even having to restart the server. As far as any users on the system are concerned nothing has changed (except, of course, that there is now more disk space).

Adding Additional Space to a Volume Group using Cockpit

In addition to the command-line utilities outlined so far in this chapter, it is also possible to access information about logical volumes and make volume group and logical volume changes from within the Cockpit web interface using the Storage page as shown in Figure 30-1:


Rhel 8 cockpit storage.png


Figure 30-1

If the Storage option is not listed, the cockpit-storaged package will need to be installed and the cockpit service restarted as follows:

# dnf install cockpit-storaged
# systemctl restart cockpit.socket

Once the Cockpit service has restarted, log back into the Cockpit interface at which point the Storage option should now be visible.

To add a new disk drive to an existing volume group from within the Cockpit console, start at the above Storage page and click on a filesystem associated with the volume group to be extended from the list marked A above.

On the resulting screen, click on the + button highlighted in Figure 30-2 below to add a physical volume:


Rhel 8 cockpit storage add physical volume.png


Figure 30-2

Select the new drive to be added to the volume group and click on the Add button:


Rhel 8 cockpit storage add device.png


Figure 30-3

On returning to the volume group screen, scroll down to the logical volume that is to be extended and click on it to unfold additional information. Figure 30-4, for example, shows details of the home logical volume:


Rhel 8 cockpit storage home lv.png


Figure 30-4

To extend the logical volume using the new space, click on the Grow button and use the slider in the resulting dialog to select how much space should be added to the volume. Click the Grow button to commit the change (the available space can be shared among different volume groups if required):


Rhel 8 cockpit storage grow volume.png


Figure 30-5

Once these steps are complete, the volume group will have been configured to use the newly added space.

Summary

Volume groups and logical volumes provide an abstract layer on top of the physical storage devices on a RHEL 8 system to provide a flexible way to allocate the space provided by multiple disk drives. This allows disk space allocations to be made and changed dynamically without the need to repartition disk drives and move data between filesystems. This chapter has outlined the basic concepts of volume groups, logical volumes, physical volumes and demonstrated how to manage these using both command-line tools and the Cockpit web interface.


You are reading a sample chapter from the Red Hat Enterprise Linux 8 (RHEL 8) Essentials book.

Purchase a full copy of Red Hat Enterprise Linux 8 (RHEL 8) Essentials in eBook ($24.99) or Print ($36.99) format

Red Hat Enterprise Linux 8 Essentials Print and eBook (ePub/PDF/Kindle) editions contain 31 chapters and over 250 pages

Buy Print Preview Book



PreviousTable of ContentsNext
Adding a New Disk Drive to a RHEL 8 SystemAdding and Managing RHEL 8 Swap Space