I recently posted Adjust Mount Options which explains in detail how to configure mount options for udisks2. Unfortunately, the reference operating system, Ubuntu 18.04, doesn’t use a new enough version of udisks2. In fact, even Ubuntu 20.04 doesn’t contain a new enough version. So, what should you do if you want to try out these nifty, new features? Build from source, of course!

Tutorial

This tutorial describes how to install both udisks, version 2.9.2, and its dependency libblockdev, version 2.25, from source on an Ubuntu 18.04 system. A brief introduction to modifying the global mount options is also included. For reference, I’m building on elementary OS 5.1. I assume you’re familiar with building and installing software on Linux and udisks2. The instructions here are intended for the beloved fish shell or Bash or ZSH.

  1. Install the dependencies required to build libblockdev.

    sudo apt -y install build-essential libbytesize-dev libkeyutils-dev \
      libkmod-dev libcryptsetup-dev libglib2.0-dev libgirepository1.0-dev \
      libmount-dev libdmraid-dev libndctl-dev libnss3-dev libparted-dev \
      libudev-dev libvolume-key-dev libyaml-dev pkg-config
  2. Fetch the latest release tarball from GitHub.

    wget -qO - https://api.github.com/repos/storaged-project/libblockdev/releases/latest \
      | awk -F': ' '/browser_download_url/ && /libblockdev-[0-9]+\.[0-9]+\.tar\.gz/ \
      {gsub(/"/, "", $(NF)); system("wget -qLP ~/Downloads/ " $(NF))}'
  3. Extract the tarball.

    tar -C ~/Downloads -xvf ~/Downloads/libblockdev-*.tar.gz
  4. Change to the extracted directory.

    cd ~/Downloads/libblockdev-*/
  5. Prepare the build.

    ./configure
  6. Build libblockdev.

    fish
    make -j(nproc)
    Bash / ZSH
    make -j$(nproc)
  7. Install libblockdev.

    sudo make install
  8. Install the dependencies required to build udisks2.

    sudo apt -y install libacl1-dev libatasmart-dev libgudev-1.0-dev \
      libpolkit-agent-1-dev libpolkit-gobject-1-dev libsystemd-dev
  9. Fetch the latest udisks release from GitHub.

    wget -qO - https://api.github.com/repos/storaged-project/udisks/releases/latest \
      | awk -F': ' '/browser_download_url/ && /\.tar\.bz2/ \
      {gsub(/"/, "", $(NF)); system("wget -qLP ~/Downloads/ " $(NF))}'
  10. Extract the archive.

    tar -C ~/Downloads -xvf ~/Downloads/udisks-*.tar.bz2
  11. Change to the extracted directory.

    cd ~/Downloads/udisks-*/
  12. Configure the build.

    ./configure --enable-btrfs \
      --with-systemdsystemunitdir=/usr/local/lib/systemd/system \
      --with-udevdir=/usr/local/lib/udev

    Installing udisks2 from source installs to the systemd and udev directories in /usr, overwriting files placed there by your system’s installation. To avoid interfering with those, the command here puts these files in their corresponding directories under /usr/local.

  13. Build away.

    fish
    make -j(nproc)
    Bash / ZSH
    make -j$(nproc)
  14. Install udisks2.

    sudo make install
  15. On Ubuntu 18.04, symlink the udisks2 udev rules to /etc/udev/rules.d/80-udisks2.rules

    Ubuntu 18.04 uses an older version of udev which does not load rules from /usr/local/lib/udev/rules.d/. This functions as a workaround and isn’t necessary for newer Ubuntu LTS releases which support udev rules in /usr/local.

    sudo ln -s /usr/local/lib/udev/rules.d/80-udisks2.rules /etc/udev/rules.d/
  16. Update the linker’s cache for the updated libraries now in /usr/local/lib.

    sudo ldconfig
  17. Reload the systemd unit files to refresh the updated udisks2 service unit.

    sudo systemctl daemon-reload
  18. Restart the udisks2 service unit to load the new version.

    sudo systemctl restart udisks2
  19. Cleanup the downloaded source files and residual build artifacts.

    rm -rf ~/Downloads/libblockdev-* ~/Downloads/udisks-*

To prefer the newer LUKS2 encryption, change the line encryption=luks1 to encryption=luks2 in the udisks2 configuration file, /usr/local/etc/udisks2/udisks2.conf.

Mount Options

To configure mount options for udisks2, copy the example template to /usr/local/etc/udisks2/mount_options.conf.

sudo cp /usr/local/etc/udisks2/mount_options.conf.example \
  /usr/local/etc/udisks2/mount_options.conf

Now modify the configuration file to your liking. The template includes lots of helpful comments. I tweak the Btrfs defaults in my configuration shown below.

/usr/local/etc/udisks2/mount_options.conf
[defaults]
btrfs_defaults=autodefrag,compress=zstd
btrfs_allow=autodefrag,compress,compress-force,datacow,nodatacow,datasum,nodatasum,degraded,device,discard,nodiscard,subvol,subvolid,space_cache

Here, autodefrag is allowed by adding it to the default list of allowed options. Additionally, automatic defragmentation and zstd compression are enabled by default. To learn more check the post Adjust Mount Options and the udisks2 Mount Options documentation.

Conclusion

That’s a wrap. You can now enjoy the new features in udisks2 without having to wait for the next Ubuntu LTS release, 22.04. Hopefully this doesn’t break anything. 😅