Getting Started with Stratis Linux Storage: Managing Pools and Filesystems

Stratis is a free and open source storage management system developed by Red Hat. Available as a technology preview since RHEL 8, it gained full support starting from version 9.3 of the distribution, and can be used also on Fedora. Stratis relies on existing storage technologies such as LUKS, device mapper, and the XFS filesystem, to provide features similar to those integrated in the BTRFS and ZFS filesystems. In this tutorial, we learn Stratis basic concepts, we create a Stratis pool and a Stratis-managed filesystem.

In this tutorial you will learn:

  • What are the basic concepts behind Stratis
  • How to create a Stratis pool
  • How to create a Stratis-managed filesystem
  • How to create a snapshot of a Stratis-managed filesystem
Introduction to Stratis
Introduction to Stratis
Category Requirements, Conventions or Software Version Used
System RHEL >= 8/Fedora
Software stratisd, stratis-cli
Other Root privileges
Conventions # – requires given linux-commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux-commands to be executed as a regular non-privileged user

Basic Stratis concepts

When working with Stratis, we have to deal with three basic components: block devices, pools and filesystems. One or more block devices, such as raw disks or partitions, are put together to create pools of space. Filesystems are created inside those pools and are used to manage files. They don’t have a fixed size, but are automatically grown as space is required. The only filesystem supported by Stratis is XFS.

Installing Stratis packages

Strictly speaking, Stratis is not itself a filesystem like ext4 or XFS. It is, instead, a high level storage management system which, under the hood, uses well known and battle-tested technologies such as LUKS and Linux device-mapper, and relies on D-bus as an inter-process communication (IPC) system.



Stratis uses a client-server architecture: it is composed by a daemon written in Rust (stratisd), and a series of client utilities written in Python. We can install both by running the following command:

$ sudo dnf install stratisd stratis-cli

Installing the packages won’t automatically start or enable the stratisd daemon. We must do it manually:

$ sudo systemctl enable --now stratisd

Creating a Stratis pool

A Stratis pool is composed by all block devices managed by Stratis. In order to be added to a Stratis pool, a block device must not contain partitions or filesytem signatures on it. To ensure a block device is “clean”, we can use the wipefs utility. In the example below, we work with the /dev/vdb block device, which is 20 GiB in size:

$ sudo wipefs -af /dev/vdb*

Once we removed all signatures from the block device, we can add it to the Stratis pool, which we can create on the fly:

$ sudo stratis pool create pool00 /dev/vdb

The pool should be created without errors. To list all the available storage pools, we can run:

$ sudo stratis pool list

In this case, as expected, the command returns the following output:

Name              Total / Used / Free    Properties                                                                 UUID   Alerts
pool00   20 GiB / 534 MiB / 19.48 GiB   ~Ca,~Cr, Op   a06ca8a8-df69-41aa-987f-ab794c1f2c81

Encrypting a Stratis pool

A Stratis Pool can be encrypted. To create an encrypted pool, as a first thing, we must generate an encryption key:

$ sudo stratis key set --capture-key pool00-key



When creating a key, one among the --capture-key or --keyfile-path options must be used. The latter is used to specify the path of a file containing the key/passphrase, while the former is used to provide the same information interactively. Since in the example we used --capture-key, we will be prompted to provide and confirm the key data/passphrase. Existing keys can be listed by running:

$ sudo stratis key list

We can now create the encrypted pool, referencing the key we generated in the previous step, via the --key-desc option:

$ sudo stratis pool create --key-desc pool00-key pool00 /dev/vdb

The key we generated was stored in the kernel keyring, and is not persistent; this means it must be recreated at each boot, before starting and unlocking the pool. First we re-create the key, then we start the pool by referencing the key storage method via the --unlock-method option (“keyring” in this case – a Tang keyserver can also be used), and the name of the pool as argument to --name:

$ sudo stratis key set --capture-key pool00-key
$ sudo stratis pool start --unlock-method keyring --name pool00

The whole process can be automated, perhaps by storing the key content into a file, but here we will not cover the procedure.

Creating a Stratis-managed filesystem

Once we created and populated a Stratis pool, we can create a filesytem out of it. The only proper filesystem supported by Stratis is XFS. As we said before, Stratis-managed filesystems are thin provisioned: they automatically grow as additional space is required. At creation time, however, we can optionally provide an initial size for the filesystem and a size limit, respectively, with the --size and --size-limit flags.

When creating a filesystem, the only mandatory arguments we must provide, are the name of the pool on which we want to create it, and the name we want to use for the filesystem itself. In the example below, we create a Stratis-managed filesystem called “foo”, with an initial size of 10 GiB, in the “pool00” pool:

$ sudo stratis filesystem create --size 10GiB pool00 foo

To list existing Stratis-managed filesystems, we can run the following command:

$ sudo stratis filesystem list

The filesystem we just created is reported in the output of the command above:

Pool     Filesystem   Total / Used / Free / Limit         Created             Device                    UUID 
pool00   foo          10 GiB / 82 MiB / 9.92 GiB / None   Sep 16 2024 11:42   /dev/stratis/pool00/foo   5a58db3a-d4f4-4b56-b4e7-df70daf141f0

To mount the filesystem we don’t need any special tool, e.g:

$ sudo mount /dev/stratis/pool00/foo /mnt

Creating and restoring snapshot of a stratis-managed filesystem

Thanks to snapshots, we can freeze and save the filesystem state at a certain point in time. In the previous example, we created a Stratis-managed filesystem, which we later mounted on /mnt. Creating a snapshot of the filesystem, is as easy as running:

$ sudo stratis filesystem snapshot pool00 foo foo-snapshot0



To create a snapshot we use the “snapshot” command, and provide: the name of the pool on which the filesystem exists, the filesystem name, and the name we want to use for the snapshot. The snapshot is just another filesytem which its own UUID:

Pool     Filesystem      Total / Used / Free / Limit         Created           Device                              UUID 
pool00   foo             10 GiB / 82 MiB / 9.92 GiB / None   Sep 16 2024 11:42 /dev/stratis/pool00/foo             5a58db3a-d4f4-4b56-b4e7-df70daf141f0
pool00   foo-snapshot0   10 GiB / 82 MiB / 9.92 GiB / None   Sep 16 2024 11:52 /dev/stratis/pool00/foo-snapshot0   1615b07f-2345-4fa1-bbb5-25301f554422

Unlike lvm snapshot which can be “merged” to their origin with a dedicated command, to “restore” a Stratis snapshot, we simply unmount and remove the filesystem the snapshot is based on, then we take a new snapshot of the snapshot, and we name it as the original filesystem. This way we can use the snapshot, and keep a copy of it at the same time. In our case, first we ensure the “foo” filesystem is unmounted:

$ sudo umount /dev/stratis/pool00/foo

Once the filesystem is unmounted, to destroy it, we can run:

$ sudo stratis filesystem destroy pool00 foo

At this point, we create a snapshot of the “foo-snapshot0”, and name it “foo”, as the original filesystem:

$ sudo stratis filesystem snapshot pool00 foo-snapshot0 foo

Conclusions

In this tutorial, we approached Stratis, the storage management system made in Red Hat. We learned what are the basic components involved in Stratis, how to create a Stratis pool and a Stratis-based filesystem. Finally, we saw how to create a snapshot of a Stratis-managed XFS filesystem.



Comments and Discussions
Linux Forum