Bookmark this page

Guided Exercise: Practice: Extending a Logical Volume

In this lab, you will extend the logical volume added in the previous practice exercise.

Resources:
Machines: serverX

Outcomes:

A resized logical volume, 700MiB total, called storage in the volume group shazam, mounted at /storage. Resizing done while the file system is still mounted and in use. The volume group extended to include an additional physical volume of 512MiB, giving a total VG size of 1GiB.

Complete Practice: Adding a Logical Volume

  1. Check for Space in the Volume Group

    Use vgdisplay to check if the VG has sufficient free space to extend the LV to a total size of 700MiB.

    [root@serverX ~]# vgdisplay shazam
      --- Volume group ---
      VG Name               shazam
      System ID             
      Format                lvm2
    ...
      VG Size               504.00 MiB
      PE Size               4.00 MiB
      Total PE              126
      Alloc PE / Size       100 / 400.00 MiB
      Free  PE / Size       26 / 104.00 MiB
      VG UUID               OBBAtU-2nBS-4SW1-khmF-yJzi-z7bD-DpCrAV

    There is only 104MiB available (26 PEs x 4MiB extents) and we need at least 300MiB to have 700MiB in total. We need to extend the VG.

    For later comparison, use df to check current disk free space:

    [root@serverX ~]# df -h /storage
    Filesystem                  Size  Used Avail Use% Mounted on
    /dev/mapper/shazam-storage  397M   21M  377M   6% /storage
  2. Create the Physical Resources

    Use fdisk to create an additional partition of 512MiB and set it to type Linux LVM.

    1. [root@serverX ~]# fdisk /dev/vdb

      Note: The following steps omit some output.

    2. Add a new primary partition of 512MiB.

      Command (m for help): n
      Partition type:
         p   primary (2 primary, 0 extended, 2 free)
         e   extended
      Select (default p): Enter
      Using default response p
      Partition number (3,4, default 3): Enter
      First sector (1050624-20971519, default 1050624): Enter
      Using default value 1050624
      Last sector, +sectors or +size{K,M,G} (1050624-20971519, default 20971519): +512M
      Partition 3 of type Linux and of size 512 MiB is set
    3. Change the partition type to Linux LVM - 0x8e.

      Command (m for help): t
      Partition number (1-3, default 3): Enter
      Hex code (type L to list all codes): 8e
      Changed type of partition 'Linux' to 'Linux LVM'
    4. Write the changes to the partition table and quit.

      Command (m for help): w
      The partition table has been altered!
    5. Use partprobe to register the new partitions with the kernel.

      [root@serverX ~]# partprobe
  3. Create the Physical Volume

    Use pvcreate to add the new partition as a PV.

    [root@serverX ~]# pvcreate /dev/vdb3
      Physical volume "/dev/vdb3" successfully created
  4. Extend the Volume Group

    1. Use vgextend to extend the VG named shazam, using the new /dev/vdb3 PV.

      [root@serverX ~]# vgextend shazam /dev/vdb3
        Volume group "shazam" successfully extended
    2. Use vgdisplay to check the shazam VG free space again. There should be plenty of free space now.

      [root@serverX ~]# vgdisplay shazam
        --- Volume group ---
        VG Name               shazam
        System ID             
        Format                lvm2
      ...
        VG Size               1012.00 MiB
        PE Size               4.00 MiB
        Total PE              253
        Alloc PE / Size       100 / 400.00 MiB
        Free  PE / Size       153 / 612.00 MiB
        VG UUID               OBBAtU-2nBS-4SW1-khmF-yJzi-z7bD-DpCrAV

      There is now 612MiB available (153 PEs x 4MiB extents); perfect.

  5. Extend the Logical Volume

    Use lvextend to extend the existing LV to 700MiB.

    [root@serverX ~]# lvextend -L 700M /dev/shazam/storage
      Extending logical volume storage to 700.00 MiB
      Logical volume storage successfully resized

    Note

    In our example, we specified the exact size to make the final LV, but we could also have used:

    • -L +300M to add the new space using size in MiB.

    • -l 175 to specify the total number of extents (175 PEs x 4MiB).

    • -l +75 to add the additional extents needed.

  6. Resize the File System

    Use xfs_growfs to extend the XFS file system to the remainder of the free space on the LV.

    [root@serverX ~]# xfs_growfs /storage
    meta-data=/dev/mapper/shazamstorage  isize=256    agcount=4, agsize=25600 blks
    ...
  7. Verify Content Availability and New File System Size

    Use df and ls | wc to review the new file system size and verify the existing files are still present.

    [root@serverX ~]# df -h /storage
    Filesystem                  Size  Used Avail Use% Mounted on
    /dev/mapper/shazam-storage  697M   21M  677M   3% /storage
    [root@serverX ~]# ls /storage | wc -l
    47

    The files are still there and the file system is about the size we expect.

Revision: rh134-7-63a207e