Adding a New Disk to an AlmaLinux Volume Group and Logical Volume

In the previous chapter, we looked at adding a new disk drive to an AlmaLinux 9 system, creating a partition and file system, and then mounting that file system to access the disk. An alternative to creating fixed partitions and file systems is to use Logical Volume Management (LVM) to create logical disks comprising 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 without spreading data over multiple file systems.

Let us take, for example, the file system of an AlmaLinux 9-based server. Without LVM, this file system would be created with a specific 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 / 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 / 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 home 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 to add additional space to the home file system of an AlmaLinux 9 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 disk space into logical volumes that 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 add more space without moving 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 with one or more logical and physical volumes.

 

You are reading a sample chapter from AlmaLinux 9 Essentials. Buy the full book now in eBook format.

Full book includes 34 chapters and 290 pages. Learn more.

Preview  Buy eBook 

 

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 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-sized blocks known as physical extents.

Logical Extent (LE)

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

Suppose we are creating a new volume group called VolGroup001. This volume group needs physical disk space 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 comprising the three physical volumes.

 

You are reading a sample chapter from AlmaLinux 9 Essentials. Buy the full book now in eBook format.

Full book includes 34 chapters and 290 pages. Learn more.

Preview  Buy eBook 

 

If we run out of space in LogVol001, we 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 AlmaLinux 9, we will work through an example of adding space to the / file system of a standard AlmaLinux 9 installation. Anticipating the need for flexibility in the sizing of the partition, AlmaLinux 9 sets up the / file system as a logical volume (called ) within a volume group called almalinux. Before making any changes to the LVM setup, however, it is essential first to gather information.

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

/dev/mapper/almalinux-home on /home type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota)
Code language: plaintext (plaintext)

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

# vgdisplay
  --- Volume group ---
  VG Name               almalinux
  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               296.50 GiB
  PE Size               4.00 MiB
  Total PE              75904
  Alloc PE / Size       75904 / 296.50 GiB
  Free  PE / Size       0 / 0   
  VG UUID               HSp6WF-NrHn-KHrv-NbI8-jDhe-WTpc-Lb1CNa
Code language: plaintext (plaintext)

As we can see in the above example, the almalinux volume group has a physical extent size of 4.00MiB and has a total of 296.50GB available for allocation to logical volumes. Currently, 75904 physical extents are allocated, equaling the total capacity. Therefore, we must add one or more physical volumes to increase the space allocated to any logical volumes in the almalinux volume group. The vgs tool is also helpful for displaying a quick overview of the space available in the volume groups on a system:

 

You are reading a sample chapter from AlmaLinux 9 Essentials. Buy the full book now in eBook format.

Full book includes 34 chapters and 290 pages. Learn more.

Preview  Buy eBook 

 

# vgs
  VG        #PV #LV #SN Attr   VSize   VFree
  almalinux   1   3   0 wz--n- 296.50g    0
Code language: plaintext (plaintext)

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

# lvdisplay
  --- Logical volume ---
  LV Path                /dev/almalinux/swap
  LV Name                swap
  VG Name                almalinux
  LV UUID                GwyCy4-JjCg-Nj1l-cmWf-GttL-MHwJ-YmaDYV
  LV Write Access        read/write
  LV Creation host, time demoserver, 2023-08-17 15:48:07 -0500
  LV Status              available
  # open                 2
  LV Size                3.75 GiB
  Current LE             961
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/almalinux/home
  LV Name                home
  VG Name                almalinux
  LV UUID                lFAhky-CV0Z-Wc4Z-fqco-dGmM-10dk-veFJj9
  LV Write Access        read/write
  LV Creation host, time demoserver, 2023-08-17 15:48:07 -0500
  LV Status              available
  # open                 1
  LV Size                <222.75 GiB
  Current LE             57023
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2
   
  --- Logical volume ---
  LV Path                /dev/almalinux/root
  LV Name                root
  VG Name                almalinux
  LV UUID                rGk5UZ-X0sJ-Lb3x-Lhe8-je8e-EWoo-609AfW
  LV Write Access        read/write
  LV Creation host, time demoserver, 2023-08-17 15:48:09 -0500
  LV Status              available
  # open                 1
  LV Size                70.00 GiB
  Current LE             17920
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
Code language: plaintext (plaintext)

As shown in the above example, 70 GiB of the space in volume group almalinux is allocated to logical volume root (for the / file system), approximately 222 GiB to the home volume group (for / home), and 3.75 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               almalinux
  PV Size               296.50 GiB / not usable 4.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              75904
  Free PE               0
  Allocated PE          75904
  PV UUID               GboISU-O0WH-fdEU-3sre-mHr0-T1X9-ObypcWCode language: plaintext (plaintext)

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

Now that we know more about our LVM configuration, we can add space to the volume group and the logical volume contained within.

 

You are reading a sample chapter from AlmaLinux 9 Essentials. Buy the full book now in eBook format.

Full book includes 34 chapters and 290 pages. Learn more.

Preview  Buy eBook 

 

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 an AlmaLinux 9 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 the operating system sees it as /dev/sdb. We shall also assume this is a new disk with no existing partitions. If existing partitions are present, they should be backed up, and then the partitions should be 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: 14.46 GiB, 15525216256 bytes, 30322688 sectors
Disk model: USB 2.0 FD      
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: 0x4c33060b

Device     Boot Start      End  Sectors  Size Id Type
/dev/sdb1        2048 30322687 30320640 14.5G 83 LinuxCode language: plaintext (plaintext)

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

# fdisk /dev/sdb

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): d
Selected partition 1
Partition 1 has been deleted.

Command (m for help): w

The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.Code language: plaintext (plaintext)

Before moving to the next step, 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 physical volume using the pvcreate command (also wiping the dos signature if one exists):

 

You are reading a sample chapter from AlmaLinux 9 Essentials. Buy the full book now in eBook format.

Full book includes 34 chapters and 290 pages. Learn more.

Preview  Buy eBook 

 

# 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.
Code language: plaintext (plaintext)

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
Code language: plaintext (plaintext)

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

# vgextend almalinux /dev/sdb
  Volume group "almalinux" successfully extended
Code language: plaintext (plaintext)

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 the logical volume by 14 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/almalinux/home):

# lvextend -L+14G /dev/almalinux/home
  Size of logical volume almalinux/home changed from <223.34 GiB (57174 extents) to <237.34 GiB (60758 extents).
  Logical volume almalinux/home successfully resized.
Code language: plaintext (plaintext)

The last step is to resize the file system residing on the logical volume to use the additional space. The way this is performed will depend on the filesystem type, which can be identified using the following df command and checking the Type column:

# df -T /home
Filesystem          Type 1K-blocks    Used Available Use% Mounted on
/dev/mapper/almalinux-home xfs  234070356 3345116 230725240   2% /home
Code language: plaintext (plaintext)

If / is formatted using the XFS filesystem, it can be resized using the xfs_growfs utility:

 

You are reading a sample chapter from AlmaLinux 9 Essentials. Buy the full book now in eBook format.

Full book includes 34 chapters and 290 pages. Learn more.

Preview  Buy eBook 

 

# xfs_growfs /home
meta-data=/dev/mapper/almalinux-home isize=512    agcount=4, agsize=14636544 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=1 inobtcount=1
data     =                       bsize=4096   blocks=58546176, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=28587, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 58546176 to 62216192
Code language: plaintext (plaintext)

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/almalinux/homeCode language: plaintext (plaintext)

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 restarting the server. As far as users on the system are concerned, nothing has changed (except that there is more disk space).

Summary

Volume groups and logical volumes provide an abstract layer on top of the physical storage devices on an AlmaLinux 9 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 and logical and physical volumes while demonstrating how to manage these using command-line tools.


Categories