Creating and Managing Logical Volumes in SUSE Linux Enterprise

30 minutes
  • 4 Learning Objectives

About this Hands-on Lab

In this hands on lab, we will work with LVM in SUSE Linux Enterprise as we create a volume group and then extend that group to increase the available size of the logical volume.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create a Linux LVM Partition on Each of the Disks
  1. Get the drive names:

  2. Your output should match the below (the disks you’ll be partitioning are nvme0n1, nvme1n1, and nvme2n1):

    nvme2n1     259:0    0   2G  0 disk
    nvme1n1     259:1    0   2G  0 disk
    nvme0n1     259:2    0   2G  0 disk
    nvme3n1     259:3    0  10G  0 disk
    ├─nvme3n1p1 259:4    0   2M  0 part
    ├─nvme3n1p2 259:5    0  20M  0 part /boot/efi
    └─nvme3n1p3 259:6    0  10G  0 part /
  3. Run fdisk against the first of the drives that has no partitions listed:

    sudo fdisk /dev/nvme0n1
    Enter n to create a new partition, 
    Then p for primary
    Then 1 for the partition number.
    Hit Enter for first and last sector since we will use the whole drive
    Enter p to see the partition. 
  4. Change the partition type label to Linux LVM:

    Enter t to set the label
    Then L to get a list of possible types
    Then 8e for Linux LVM
    The p to review the changes
    Then w to write the changes
  5. Have the kernel rescan the partition table, and then list partitions to verify:

    sudo partprobe
  6. Repeat this process for the other two disks.

  7. When finished with all three disks, run lsblk again to confirm the partitions are correct:

    nvme2n1     259:0    0   2G  0 disk
    └─nvme2n1p1 259:7    0   2G  0 part
    nvme1n1     259:1    0   2G  0 disk
    └─nvme1n1p1 259:11   0   2G  0 part
    nvme0n1     259:2    0   2G  0 disk
    └─nvme0n1p1 259:8    0   2G  0 part
    nvme3n1     259:3    0  10G  0 disk
    ├─nvme3n1p1 259:4    0   2M  0 part
    ├─nvme3n1p2 259:5    0  20M  0 part /boot/efi
    └─nvme3n1p3 259:6    0  10G  0 part /
Create a Physical Volume and a Volume Group Named `VolumeGroup0`
  1. Create a physical volume on the first drive:

    sudo pvcreate /dev/nvme0n1p1
  2. Verify the physical volume was created:

    sudo pvdisplay
  3. Create the volume group:

    sudo vgcreate VolumeGroup0 /dev/nvme0n1p1
  4. Verify it was created:

    sudo vgdisplay
Add the Second Disk to the Volume Group and Then Create a Logical Volume, Create an XFS Filesystem, and Mount It
  1. Extend the volume group to the second drive — this will create the necessary physical volume:

    sudo vgextend VolumeGroup0 /dev/nvme1n1p1
  2. Get the size, which should be 3.99 GiB:

    sudo vgdisplay
  3. Create the logical volume from the volume group:

    sudo lvcreate -L+3.99GB -n "backups" VolumeGroup0
  4. Create the filesystem on the volume:

    sudo mkfs.xfs /dev/VolumeGroup0/backups
  5. Create a mount point and mount the volume:

    sudo mkdir /mnt/backups
    sudo mount /dev/VolumeGroup0/backups /mnt/backups/
  6. Create a data file in the mount location:

    sudo touch /mnt/backups/data
    ls -l /mnt/backups
Add the Third Disk to the Volume Group, Extend the Size of the Logical Volume, and Grow the Filesystem to Use the Added Space
  1. Add in the third drive to the volume group — this will also create the physical volume:

    sudo vgextend VolumeGroup0 /dev/nvme2n1p1
  2. Grow the logical volume by adding the size of the third disk:

    sudo lvextend -L+1.91GB /dev/VolumeGroup0/backups
  3. Then grow the filesystem to use the added space:

    sudo xfs_growfs /mnt/backups
  4. Verify data is still there and that the drive is the correct size:

    ls -l /mnt/backups
    df -hT 

    This should show 5.9G in the Size column for /dev/mapper/VolumeGroup0-backups.

Additional Resources

You have been asked to create more storage on an existing server.

There are three drives that have been added. You have been asked to create a volume using the space on two of the drives. This volume needs to have an XFS file system. Make a directory named backups containing a file named data in the volume.

Later, it is indicated that the volume is getting full. Using the third disk, add space to the volume, and create a data2 file in the backup directory to ensure the volume is useable.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?