Grow and Shrink LVM Filesystems

Hands-On Lab

 

Photo of Terrence Cox

Terrence Cox

Senior Vice President of Content

Length

01:00:00

Difficulty

Intermediate

Filesystems and their maintenance are one of the most common things any system administrator or engineer has to do when provisioning or maintaining systems. Creating a disk configuration that allows you the flexibility to grow or shrink a filesystem as needed will allow you to react to any requirement changes your systems undergo. After this hands-on lab, you will be able to create and work with LVM filesystems to adjust their sizes as needed.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Grow and Shrink LVM Filesystems

Introduction

In this hands-on lab, you will be provisioned a CentOS 7 server that will contain (3) 20 GB block devices that are unpartitioned and otherwise unconfigured.

Solution

Open a terminal session, and log in to the server via SSH using the credentials provided on the lab page:

ssh cloud_user@<PUBLIC_IP_ADDRESS>

Become the root user:

sudo su -

Create the Physical Volume Group of Disks and Verify

  1. Install the LVM package:

    yum install lvm2 -y
  2. List out the device names:

    fdisk -l
  3. Assemble the disks into a group that can be used by the Logical Volume Manager:

    pvcreate /dev/xvdf /dev/xvdg /dev/xvdj

Create the Volume Group to Use

  1. Create the volume group, and add the physical volumes to it:

    vgcreate myvol /dev/xvdf /dev/xvdg /dev/xvdj

Create the Logical Volume of 60 GB

  1. Create the logical volume:

    lvcreate -l 100%FREE -n devdisks myvol

Format and Mount the LVM Filesystem

  1. Create the EXT4 filesystem:

    mkfs -t ext4 /dev/myvol/devdisks
  2. Create the directory to mount the filesystem you created:

    mkdir /mnt/newvol
  3. Mount the filesystem:

    mount -t ext4 /dev/myvol/devdisks /mnt/newvol/
  4. Verify:

    df -h

Conclusion

Congratulations on successfully completing this hands-on lab!