I would like to make use of Btrfs' transparent compression on an external drive.

  1. Which tool is best for formatting the drive? Disk Utility or GParted?
  2. How do I activate the compression? During formatting or when I mount the drive? I guess at mount time. I'm using usbmount to automatically mount newly attached devices, because nobody is logged in on the desktop. Would I have to set general default options somewhere in a system configuration file to get Btrfs mounted with compression, or would I specify this via FS_MOUNTOPTIONS in /etc/usbmount/usbmount.conf and how?



Format and enable LZO

I would avoid using any GUI to format;-)

mkfs.btrfs device is good enough, depending on how you would like to make use of Btrfs features:

  1. use the external USB HDD as 1 single partition/block device
  2. create 2 partitions (2 block devices) and form a raid1 or raid0 for data (-d), metadata is replicated on all devices by default, unless you manually specify to change

You can make use of the compression by adding the option when mounting, for example:

sudo mount -o compress=lzo /dev/sdd /mnt/btrfs

The good thing about Btrfs is that LZO compression can also be enabled on a subvol basis, very flexible;-) For example

/* Create a subvolume named subvol1 */

# btrfs subvolume create /mnt/btrfs/subvol1

/* Mount the subvolume and enable compression */

# mount -o compress=lzo,subvol=subvol1 /dev/sdd /mnt/subvol1

NOTE: You can add compression to existing Btrfs file systems at any time, just add the option when mounting and do a defragment to apply compression to existing data.

BTW: 2 best Btrfs docs out there:



Make use of LZO compression:


USB Auto Mount

I am not too sure about this, will let other blokes answer it;-)

I'd prefer to write a simple shell script to do the mount because I won't attach the USB HDD to the computer all the time.

  • Thanks a lot. I'll try this asap. Question: does the Btrfs partition to be mounted with the compression option to read the compressed data? Or can I just plug it to another machine?
    – Andre
    Nov 21 '12 at 3:43
  • Don't quiet get it;-( But I'll say that if data (the whole disk or a subvol) is compressed, you'll need to add the -o compress=lzo when mounting it to access (r/w) it. Of course you can plug it onto another computer, as long as it supports Btrfs.
    – Terry Wang
    Nov 21 '12 at 3:56
  • 1
    I tested it with a USB thumb drive. I formated it using Disk Utility. Then I mounted it once with LZO option and once with ZLIB to write some files. Then I just plugged it in and let the Dekstop automatically mount it without compression. I have used highly compressible text files. The disk usage of the files is for LZO and ZLIB at about 40%. The files are also accessible when mounted without compression option.
    – Andre
    Dec 2 '12 at 22:22
  • The files should be accessible wihtout the mount option. But I am not sure what the behaviours are if you edit/copy/move, most likely (mv/cp) it will be decompressed.
    – Terry Wang
    Dec 3 '12 at 0:01

As the formatting and enabling LZO compression question is answered already, here is the answer to the Question how to automatically set the compression mount option on automount.

This solution also works if you have btrfs on a LUKS-encrypted disk.

USB Automount

  1. Connect the disk and let your automounter mount the filesystem
  2. Use lsblk -o UUID,MOUNTPOINT to find the UUID of the block device the filesystem is on, e.g. 6e642696-3cb4-4d4e-86a6-2fae2b9295cc
  3. Add a line to your /etc/fstab referencing the UUID and specifying the additional mount option:

    UUID=6e642696-3cb4-4d4e-86a6-2fae2b9295cc /media/user/backupdrive btrfs noauto,subvol=/,compress=zstd
  4. Unmount and re-mount the drive and check that the options were set using mount

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.