Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Google Cloud Platform icon
Labs

Working with Logical Volume Management

Effective storage management is a constant challenge in any enterprise environment. The ability to react quickly to increasing storage needs without disrupting the current configuration is key. In this activity, we will set up Logical Volume Manager (LVM) storage utilities to address this challenge. We will partition a disk for use with LVM, and then create Physical Volumes, Volume Groups, and Logical Volumes. We will also delete a Logical Volume, and extend a Volume Group to be able to provide additional space in a Logical Volume. Learning how to use the flexibility of LVM makes us more effective at storage management.

Google Cloud Platform icon
Labs

Path Info

Level
Clock icon Intermediate
Duration
Clock icon 30m
Published
Clock icon Jan 17, 2020

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Create Linux LVM Type Partitions on /dev/xvdb and /dev/xvdc to Use All Space

    Start an interactive root shell with sudo. Use fdisk to create a new default partition of type 8e on /dev/xvdb and /dev/xvdc. Create the first:

    sudo -i
    fdisk /dev/xvdb
    

    Use the n command and choose all the defaults to create a new partition:

    Command (m for help): n
    Partition Type: p
    Partition number (1-4, default 1): Press Enter to accept the default
    First sector: Press Enter to accept the default
    Last sector: Press Enter to accept the default
    

    Use the t command to change to 8e (Linux LVM):

    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'
    

    Use the w command to write the changes to the partition table and exit:

    Command (m for help): w
    

    Now create the second:

    fdisk /dev/xvdc
    

    Use the n command and choose all the defaults to create a new partition:

    Command (m for help): n
    Partition Type: p
    Partition number (1-4, default 1): Press Enter to accept the default
    First sector: Press Enter to accept the default
    Last sector: Press Enter to accept the default
    

    Use the t command to change to 8e (Linux LVM):

    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'
    

    Use the w command to write the changes to the partition table and exit.

    The result is that the /dev/xvdb1 and /dev/xvdc1 partitions of type 8e have been created.

  2. Challenge

    Create Physical Volumes with the LVM Partitions /dev/xvdb1 and /dev/xvdc1, and Create the Volume Group volgroup Using /dev/xvdb1

    Initialize the /dev/xvdb1 and /dev/xvdc1 LVM partitions as Physical Volumes with pvcreate. Inspect the Physical Volumes with pvs and pvdisplay:

    pvcreate /dev/xvdb1 /dev/xvdc1
    pvs
    pvdisplay
    

    Use vgcreate to create the volgroup Volume Group using the /dev/xvdb1 Physical Volume. Inspect volgroup with vgs and vgdisplay:

    vgcreate volgroup /dev/xvdb1
    vgs
    vgdisplay
    
  3. Challenge

    Create the Logical Volume datavol Using 3GB of Space and tempvol Using 1GB of Space

    Use the lvcreate command to create two Logical Volumes, a 3 GB named datavol and a 1 GB named tempvol. Inspect them using lvs and lvdisplay commands:

    lvcreate -n datavol -L3G volgroup
    lvcreate -n tempvol -L1G volgroup
    lvs
    lvdisplay
    
  4. Challenge

    Remove /dev/volgroup/tempvol, Extend volgroup with /dev/xvdc1, and Then Resize /dev/volgroup/datavol to Use All Space in the Volume Group

    Use lvremove to get rid of the tempvol, then run vgextend to expand the volume group. Create an ext4 filesystem on /dev/volgroup/datavol and mount it on /mnt/data. Use lvresize to extend the datavol Logical Volume and filesystem to the maximum size possible. Check everything afterward using the df and vgs commands:

    lvremove /dev/volgroup/tempvol
    Type 'y' and Enter to confirm 
    vgs
    vgextend volgroup /dev/xvdc1
    vgs
    vgdisplay
    mkfs -t ext4 /dev/volgroup/datavol
    mkdir /mnt/data
    mount  /dev/volgroup/datavol /mnt/data
    df -h /mnt/data
    lvresize -r -L 9.99G /dev/volgroup/datavol
    df -h
    
  5. Challenge

    Configure the /dev/volgroup/datavol Logical Volume to Mount on /mnt/data Persistently

    Unmount the /mnt/data directory with the umount command:

    umount /mnt/data
    

    Add the following line to /etc/fstab:

    /dev/volgroup/datavol /mnt/data ext4 defaults 0 1
    

    Use an editor like vim to add the line to the file:

    vim /etc/fstab
    

    Mount the device with the mount command. Use df to verify it mounted:

    mount -a
    df -h /mnt/data
    

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

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.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans