Creating Btrfs Subvolumes and Snapshots

30 minutes
  • 4 Learning Objectives

About this Hands-on Lab

The `b-tree` file system, `btrfs`, is a Linux filesystem that implements several advanced features such as volume management, snapshots, and copy-on-write. In this hands-on lab, you will be tasked with creating and interacting with a `btrfs` file system.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create a btrfs filesystem based on the information provided in the instructions.
  1. Create a btrfs filesystem using /dev/xvdf1, /dev/xvdg1, and /dev/xvdj1:

mkfs -t btrfs /dev/xvdf1 /dev/xvdg1 /dev/xvdj1

  1. Mount the btrfs filesystem on /mnt/data:

mount -t btrfs /dev/xvdg1 /mnt/data

  1. Use a text editor (i.e., vim) to open /etc/fstab and add the following entry:

UUID=filesystem_UUID /mnt/data btrfs defaults 0 0

Create two subvolumes for /mnt/data based on the information provided in the instructions.
  1. Create the user and admin subvolumes in the /mnt/data filesystem:
btrfs subvolume create /mnt/data/user
btrfs subvolume create /mnt/data/admin
  1. Mount the admin subvolume at /mnt/admin and the user subvolume at /mnt/user:
mount -t btrfs -o subvol=user /dev/xvdg1 /mnt/user
mount -t btrfs -o subvol=admin /dev/xvdg1 /mnt/admin
  1. Use a text editor (i.e., vim) to open /etc/fstab and add entries for /mnt/user and /mnt/admin:
UUID=filesystem_UUID       /mnt/user       btrfs   subvol=user,defaults    0 0
UUID=filesystem_UUID       /mnt/admin      btrfs   subvol=admin,defaults   0 0
Add the /dev/xvdj2 device to the filesystem mounted on /mnt/backup
  1. Add /dev/xvdj2 to filesystem mounted on /mnt/backup using the btrfs command:

btrfs device add /dev/xvdj2 /mnt/backup

  1. Balance the filesystem to spread block groups across all devices:

btrfs balance start --full-balance /mnt/backup

Create two snapshots of /mnt/backup/user_data based on the information provided in the instructions.
  1. Create a snapshot called user_data_snap” from the user_data volume:

btrfs subvolume snapshot /mnt/backup/user_data/ /mnt/backup/user_data_snap

  1. Create a read-only snapshot called user_data_snap_ro from the user_data volume:

btrfs subvolume snapshot -r /mnt/backup/user_data/ /mnt/backup/user_data_snap_ro

Additional Resources

As part of the Linux engineering team for your company, you have been tasked with setting up a btrfs filesystem, creating subvolumes to be used by administrators and normal users, increasing the storage capacity of the existing backups file system, and creating some snapshots of an existing subvolume.

First, you will need to create a btrfs filesystem using the following devices: /dev/xvdf1, /dev/xvdg1, and /dev/xvdj1. This file system should be mounted on /mnt/data, and an entry should be added to /etc/fstab using the default options to ensure that it is mounted on boot. Two subvolumes should be created on this file system at /mnt/data/user and /mnt/data/admin and should be mounted on /mnt/user and /mnt/admin respectively. To ensure that they are mounted on boot, an entry for each of these should be added to /etc/fstab.

A btrfs filesystem has been created on /mnt/backup that needs the overall space to be increased. Expand this volume by adding the /dev/xvdj2 device to the btrfs pool for that file system. Once added, balance the pool by spreading out the block groups across all devices. Finally, create two snapshots of the subvolume /mnt/backup/user_data. The first should be a normal snapshot created at /mnt/backup/user_data_snap, and the second should be a read-only snapshot created at /mnt/backup/user_data_snap_ro.


  • Perform all ll tasks as the root user.
  • The UUIDs of the filesystems will change with each attempt.

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.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


Sign In
Welcome Back!

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