I run Ubuntu Mate 22.04 and I have a USB mass storage device (aka USB-Stick) that is formatted with btrfs. I know it's partition UUID and label and I want it specifically to be mounted with specific mount options. In particular I want to enable file system compression every time I plug it into my computer without having to unmount it and then manually remount it with the terminal.
When I plug it in, I would usually have to do
sudo umount /dev/sdb/
sudo mkdir /media/username/label
sudo mount -t btrfs -o rw,ssd,nosuid,nodev,noatime,space_cache=v2,subvolid=5,subvol=/,uhelper=udisks2,compress=zstd:15,discard=async /dev/disk/by-uuid/<uuid> /media/username/label
sudo chown username:usergroup /media/username/label
which I would like to automate somehow.
How do I do that?
Edit
I tried adding this line to my /etc/fstab as suggested in the comments.
UUID=<uuid> /mnt/<label> btrfs rw,ssd,nosuid,nodev,noatime,space_cache=v2,subvolid=5,subvol=/,uhelper=udisks2,compress=zstd:15,discard=async,nofail 0 2
However this causes the device to not auto-mount anymore when I plug it in. When I mount it, I have to be root. Then it doesn't show up in the devices anymore in my file manager (caja). It also is not user writable by default.
I would like the same behavior as plugging it in normally, just with the options
ssd
, because the device in question is somewhat special and announces itself as rotational when it is not),compress=zstd:15
, because the device is very slow anyway and also somewhat small andnoatime
to preserve the flash drive's lifespan
I want it to mount automatically with those settings, but also is user writable and show up in the file manager.
One can add an entry to fstab with the desired mount options. The mount point must be in
/media/username/
, so a directory for that should be created. The name of the directory in/media/username/
will be the drive name as shown in the file manager. The directory won't be automatically deleted if this procedure is followed, as it would be with other removable media.The options that need to be added for this to work are
nofail
to prevent an error during boot when the drive is not connecteduser
to allow a user to mount the driveuhelper=udisks2
to allow users to unmount the drive without root privilegesnodev
to disallow device files on the drivenosuid
disallow set userid files on the drivedump and filesystem check order should both be 0.
The complete line would be something like this