Fedora System Extensions: Tinkering with the /usr Directory Without Rebooting

Fedora tutorial - IT technology blog
Fedora tutorial - IT technology blog

The Struggle of Rebooting on Fedora Immutable

The best thing about using Fedora Silverblue or Kinoite is stability. The /usr directory is locked down (read-only), making the system nearly impossible to break by accident. However, the price you pay is having to reboot every time you need to install a tool using rpm-ostree install.

Waiting 30-60 seconds just to use a temporary library is truly frustrating. For someone using Fedora as their primary dev machine like me, this disrupts the workflow. Fortunately, systemd-sysext (System Extensions) was born to solve exactly this problem.

Its mechanism is quite clever: instead of modifying the base image directly, it creates an overlay of binaries and libraries into /usr while the system is running. You get new tools without touching the integrity of the base OS. Extremely flexible!

Preparing Your Arsenal

The good news is that systemd-sysext is already available on most modern Fedora versions. You just need to check if systemd is version v248 or higher with the command:

systemd --version

Next, create a home for your extensions. I recommend using /var/lib/extensions because it’s outside the read-only partition, making management easier:

sudo mkdir -p /var/lib/extensions

Hands-on: Creating an Extension for the ‘Micro’ Editor

Instead of using a cliché “Hello World” example, let’s try bringing the micro editor into the system without installing it via RPM or Flatpak.

Step 1: Building the Directory Structure

Each extension needs to mimic the exact structure of /usr. We will download the portable version of micro and place it in the correct location.

# Create temporary directory
mkdir -p ~/micro-ext/usr/bin

# Download micro binary (example for x86_64 architecture)
cd ~/micro-ext/usr/bin
curl -L https://github.com/zyedidia/micro/releases/download/v2.0.11/micro-2.0.11-linux64.tar.gz | tar xvz --strip-components=1 micro-2.0.11/micro

Step 2: Declaring Metadata (Required)

For systemd to accept “mounting” this extension, you must prove it’s compatible with your current Fedora version. This metadata file acts as the extension’s ID card.

mkdir -p ~/micro-ext/usr/lib/extension-release.d/

# Get the ID and Version of the current OS
source /etc/os-release

cat <<EOF > ~/micro-ext/usr/lib/extension-release.d/extension-release.micro
ID=$ID
VERSION_ID=$VERSION_ID
EOF

Quick tip: If you want this extension to run on any Fedora version, use ID=_any. However, if the extension contains complex .so libraries, specify the exact version to avoid segfaults.

Step 3: Deployment

Copy the entire directory you just created into the system’s management area:

sudo cp -r ~/micro-ext /var/lib/extensions/micro

Activation: No Waiting Required

Now it’s time to enjoy the results. Tell systemd to merge the new extension into the system:

sudo systemd-sysext refresh

Check if micro is present in /usr/bin:

which micro
# Result: /usr/bin/micro

You can type micro to start editing immediately. Everything happens in an instant, no reboot required, and no rpm-ostree transaction needed.

Troubleshooting and Cleanup

Sometimes things don’t go as planned. Here are some of my real-world tips.

Access Errors (SELinux)

Fedora is very strict. If you see the file in /usr/bin but can’t run it (Permission Denied), it’s likely due to an incorrect SELinux context. Run this command to fix it:

sudo restorecon -Rv /var/lib/extensions

Removing the Extension

Want your system clean again? Just unmerge and delete the directory:

sudo systemd-sysext unmerge
sudo rm -rf /var/lib/extensions/micro
sudo systemd-sysext refresh

Using systemd-sysext is a professional way to customize Fedora Immutable. It keeps the base image clean while ensuring you have the tools needed to work efficiently.

Share: