Bookmark this page

Guided Exercise: Practice: Adding a Logical Volume

In this lab, you will add a physical volume, volume group, logical volume, and an XFS file system. You will persistently mount the logical volume file system.

Resources:
Machines: serverX

Outcomes:

A 400MiB logical volume called storage in the volume group shazam, mounted at /storage. The volume group consists of two physical volumes, each 256MiB in size.

  • Reset your serverX system.

  • Log into serverX.

  • Open a terminal.

  • Switch to root (sudo -i).

  1. Create the Physical Resources

    1. Use fdisk to create two partitions of 256MiB apiece and set them to type Linux LVM.

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

      Note: The following steps omit some output.

    2. Add a new primary partition of 256MiB.

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

      Command (m for help): t
      Selected partition 1
      Hex code (type L to list all codes): 8e
      Changed type of partition 'Linux' to 'Linux LVM'
    4. Repeat the previous two steps to add a second primary partition of the same size in the next available partition space.

    5. Write the changes to the partition table and quit.

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

      [root@serverX ~]# partprobe
  2. Create the Physical Volumes

    Use pvcreate to add the two new partitions as PVs.

    [root@serverX ~]# pvcreate /dev/vdb1 /dev/vdb2
      Physical volume "/dev/vdb1" successfully created
      Physical volume "/dev/vdb2" successfully created
    
  3. Create the Volume Group

    Use vgcreate to create a new VG named shazam built from the two PVs.

    [root@serverX ~]# vgcreate shazam /dev/vdb1 /dev/vdb2
      Volume group "shazam" successfully created
  4. Create the Logical Volume

    Use lvcreate to create a 400MiB LV named storage from the shazam VG.

    [root@serverX ~]# lvcreate -n storage -L 400M shazam
      Logical volume "storage" created

    This will create a device called /dev/shazam/storage, currently without a file system on it.

  5. Add a Persistent File System

    1. Use mkfs to place an xfs file system on the storage LV; use the LV device name.

      [root@serverX ~]# mkfs -t xfs /dev/shazam/storage
      meta-data=/dev/shazam/storage    isize=256    agcount=4, agsize=25600 blks
      ...
    2. Use mkdir to create a mount point at /storage.

      [root@serverX ~]# mkdir /storage
    3. Use vim to add the following line to the bottom of /etc/fstab on serverX:

      /dev/shazam/storage    /storage    xfs  defaults  1 2
    4. Use mount to verify the /etc/fstab entry and mount the new storage LV device.

      [root@serverX ~]# mount -a
  6. Test and Review Your Work

    1. As a final test, copy some files onto /storage and verify how many were copied.

      [root@serverX ~]# cp -a /etc/*.conf /storage
      [root@serverX ~]# ls /storage | wc -l
      47

      We will check that we still have the same number of files in the next practice exercise.

    2. fdisk -l /dev/vdb will show you the partitions that exist on /dev/vdb.

      [root@serverX ~]# fdisk -l /dev/vdb

      Check the /dev/vdb1 and /dev/vdb2 entries, and notice the Id and System columns showing 8e and Linux LVM, respectively.

    3. pvdisplay will show you information about each of the physical volumes. Optionally, include the device name to limit details to a specific PV.

      [root@serverX ~]# pvdisplay /dev/vdb2
        --- Physical volume ---
        PV Name               /dev/vdb2
        VG Name               shazam
        PV Size               256.00 MiB / not usable 4.00 MiB
        Allocatable           yes 
        PE Size               4.00 MiB
        Total PE              63
        Free PE               26
        Allocated PE          37
        PV UUID               N64t6x-URdJ-fVU3-FQ67-zU6g-So7w-hvXMcM

      This shows that our PV is allocated to VG shazam, is 256MiB in size (although 4MiB is not usable), and our physical extent size (PE Size) is 4MiB (the smallest allocatable LV size).

      There are 63 PEs, of which 26 PEs are free for allocation to LVs in the future and 37 PEs are currently allocated to LVs. These translate to MiB values as follows:

      • Total 252MiB (63 PEs x 4MiB); remember, 4MiB are unusable.

      • Free 104MiB (26 PEs x 4MiB)

      • Allocated 148MiB (37 PEs x 4MiB)

    4. vgdisplay vgname will show you information about the volume group named vgname.

      [root@serverX ~]# vgdisplay shazam

      Check the following values:

      • VG Size is 504.00MiB.

      • Total PE is 126.

      • Alloc PE / Size is 100 / 400.00MiB.

      • Free PE / Size is 26 / 104.00MiB.

    5. lvdisplay /dev/vgname/lvname will show you information about the logical volume named lvname.

      [root@serverX ~]# lvdisplay /dev/shazam/storage

      Notice the LV Path, LV Name, VG Name, LV Status, LV Size, and Current LE (logical extents, which map to physical extents).

    6. mount will show all the devices that are mounted and any mount options. It should include /dev/shazam/storage.

      Note

      Reminder: Many tools will report the device mapper name instead, /dev/mapper/shazam-storage; it is the same logical volume.

      [root@serverX ~]# mount

      You should see (probably on the last line) /dev/mapper/shazam-storage mounted on /storage and the associated mount information.

    7. df -h will show human-readable disk free space. Optionally, include the mount point to limit details to that file system.

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

      Allowing for file system metadata, these values are what we would expect.

Revision: rh134-7-63a207e