PleinIQ
Menu
Language

Choose your language

This page is only in English for now. Choosing a language opens its home page.

Other languages

Your browser can translate any page into almost any language.

Other browsers: Open the browser menu and look for “Translate”.

Your resume, your downloads and lab commands are never translated.

Roadmaps / Linux / Lab 5

Lab 5 of 8 · Storage, filesystems and LVM

Build and grow an LVM volume on practice disks

Create two practice disks, combine them with LVM, mount a filesystem at boot, then grow it while it is in use.

Time
45–60 minutes
Cost
Free.

What you learn

Disks fill up, and servers need more space without downtime. LVM builds volumes from disks and grows them while they are in use.

  • Finding what uses space with df and du
  • Physical volumes, volume groups and logical volumes
  • Mounting a filesystem at boot with /etc/fstab, safely
  • Growing a volume while it is mounted

In the AI era: An AI-written disk command can wipe the wrong disk, and a wrong fstab line can stop a server from booting. Sysadmins check device names first, verify fstab before relying on it, and practise on spare disks, as you do here.

Get set up

Commands use Homebrew in the Terminal app. Already have a tool? Skip it.

  • Install
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

    Use the Terminal app. The command installs Homebrew, which the other macOS commands use.

Before you start

  • Finish lab 1.

  • Start your server and open your repository: run multipass start sysadmin-lab and multipass shell sysadmin-lab on your computer, then cd linux-admin-lab on the server.

Step by step

  1. 1 Find out what is using space

    df shows free space per filesystem; du adds up folder sizes.

    Run this on your lab server
    df -h /
    sudo du -xh /var --max-depth=1 2>/dev/null | sort -h | tail -n 5
    You should see:

    The free space on /, then the five largest folders under /var.

  2. 2 Create two practice disks

    Real servers get new disks from the cloud or the hardware. Here, two files act as disks through loop devices, so nothing real can be harmed. D1 and D2 remember the device names for the next steps; if you open a new shell, find them again with sudo losetup -a.

    Run this on your lab server
    sudo apt install -y lvm2
    sudo truncate -s 1G /var/tmp/disk1.img /var/tmp/disk2.img
    D1=$(sudo losetup --find --show /var/tmp/disk1.img)
    D2=$(sudo losetup --find --show /var/tmp/disk2.img)
    echo "$D1 $D2"
    You should see:

    Two device names, such as /dev/loop3 /dev/loop4.

  3. 3 Build the LVM volume

    A physical volume (PV) is a disk prepared for LVM, a volume group (VG) pools PVs, and a logical volume (LV) is the slice you format and mount.

    Run this on your lab server
    sudo pvcreate "$D1"
    sudo vgcreate labvg "$D1"
    sudo lvcreate --name data --size 800M labvg
    sudo lvs
    You should see:

    A logical volume data in labvg of 800.00m.

  4. 4 Create a filesystem and mount it

    ext4 is the usual Linux filesystem.

    Run this on your lab server
    sudo mkfs.ext4 -q /dev/labvg/data
    sudo mkdir -p /mnt/data
    sudo mount /dev/labvg/data /mnt/data
    df -h /mnt/data
    You should see:

    About 780M of space mounted on /mnt/data.

  5. 5 Ask AI for the fstab line, then verify it

    Ask your AI assistant: "Write an /etc/fstab line to mount the ext4 logical volume /dev/labvg/data at /mnt/data at boot, without stopping boot if it is missing." Compare it with the line below, which uses nofail because practice disks disappear after a restart. Then let the system check the file and prove the line works before you trust it.

    Run this on your lab server
    echo '/dev/labvg/data /mnt/data ext4 defaults,nofail 0 2' | sudo tee -a /etc/fstab
    sudo findmnt --verify
    sudo umount /mnt/data
    sudo mount -a
    findmnt /mnt/data
    You should see:

    findmnt --verify reports no errors, and mount -a mounts /mnt/data again from the fstab line.

  6. 6 Grow it while it is in use

    Add the second disk to the group, then grow the volume and its filesystem in one step. Nothing is unmounted.

    Run this on your lab server
    echo "test data" | sudo tee /mnt/data/keep.txt
    sudo pvcreate "$D2"
    sudo vgextend labvg "$D2"
    sudo lvextend --resizefs --size +900M /dev/labvg/data
    df -h /mnt/data
    cat /mnt/data/keep.txt
    You should see:

    The size grows to about 1.7G, and test data is still there.

  7. 7 Write your notes

    Create the file with nano notes/05-storage.md.

    File: notes/05-storage.md
    # Storage and LVM
    
    ## Space on my server
    - Free space on `/`: ...
    - Largest folder under `/var`: ...
    
    ## My LVM setup
    - Physical volumes: ...
    - Volume group: ...
    - Logical volume and size before and after growing: ...
    
    ## fstab
    - The AI's line, and how it differed from mine: ...
    - Why `nofail` matters: ...
    
  8. 8 Commit and push

    Save your work to GitHub from the server.

    Run this on your lab server
    git add notes
    git commit -m "Add storage and LVM notes"
    git push
  9. 9 Clean up the practice disks

    Remove the fstab line first, so the server never looks for a disk that no longer exists.

    Run this on your lab server
    sudo umount /mnt/data
    sudo sed -i '\#/dev/labvg/data#d' /etc/fstab
    sudo lvremove -y labvg/data
    sudo vgremove -y labvg
    sudo losetup -d "$D1"
    sudo losetup -d "$D2"
    sudo rm /var/tmp/disk1.img /var/tmp/disk2.img
    grep -c labvg /etc/fstab
    You should see:

    0: the fstab line is gone.

You are done when

  • You built an LVM volume from a practice disk and mounted it.

  • You grew it while it was mounted, and your test file survived.

  • Your fstab line passed findmnt --verify, and you removed it when cleaning up.

Finished? Get your proof page

We check your public GitHub repository and give you a page to share with recruiters, and can add the project to your resume.

Join PleinIQ Updates

What are you interested in?

Read how we handle your information in our privacy notice.