Automatically Mount RDX Drive on Insertion

Hi all,

I am trying to get a backup system (Bacula in this case) setup to work with some RDX drives I have. Currently the machine that has the RDX drive attached to it is a Windows server, which of course natively automatically mounts the drives (cartridges) when they’re inserted. I’m now looking to decommission that old Windows server and move it over to a linux machine running Rocky.

I am however left scratching my head on how to get this setup. Ultimately I want to be able to insert the RDX cartridge and have it automatically mounted at the same mount point, regardless of which cartridge is inserted. I then want to eject the cartridge when the backup is complete.

Can anyone give me any ideas of how I might achieve this? I’ve considered adding a mount command to the start of the backup job, however this only works if the cartridge has been inserted before the backup job started. If I’m running late for any reason and insert it later, I’d have to manually mount it (which isn’t ideal).

Appreciate any ideas you might have on how to address this problem.

Probably better to ask on Bacula forums. However from a quick google: [Bacula-users] Question on how automount works someone suggests using volume poll interval along with the automaticmount option in the bacula-sd.conf.

Also: Thread: [Bacula-users] automatic mount / unmount after Backup | Bacula seems to suggest that using pre/post jobs for the automatic mounting as well as someone else suggesting to use autofs which is available in Rocky Linux and let this mount them and use the path of the autofs mount point for your Bacula storage device.

Sorry for the delayed response - I was hoping to reply with details of the solution I found, but alas, not yet.

Firstly the automount function in Bacula refers to the ‘mounting’ of the virtual tape file that Bacula uses when backing up to block storage devices. There is not (to my knowledge) any functionality in Bacula to automatically mount an external USB drive (or any drive for that matter).

I have considered using pre-backup script/s to mount the USB drive. The major issue with this is that it would only work if the drive is connected before be backup starts. If it’s connected after the backup is scheduled to start, I would have to manually mount the drive for the backup to proceed. This isn’t a great solution for me.

Leaping off the previous reply, I came across this article which appears to provide information about what I’m trying to achieve (but the forum will only allow me to post two links).

I first tried installing uam (GitHub - projg2/uam: Lightweight filesystem (pendrive) automounter based on udev rules.), since it appeared to do basically what I was looking for and I have no burning desire to unnecessary reinvent the wheel. However, after crashing around trying to get it installed (there does not appear to be any installation instructions for it anywhere), I’m unable to get it to work.

I then came across ldm (GitHub - LemonBoy/ldm: A lightweight device mounter, with libudev as only dependency) which seems to be an even better fit for my needs. However, attempting to compile and install this was also unsuccessful as it appears to be unable to locate the libudev library that it depends upon:

c -std=c99 -D_GNU_SOURCE -Wall -Wunused-parameter -O2 -DVERSION_STR="\"v0.7\"" `pkg-config --cflags libudev mount glib-2.0` -o ldm.o -c ldm.c
Package libudev was not found in the pkg-config search path.
Perhaps you should add the directory containing `libudev.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libudev', required by 'virtual:world', not found
Package 'mount', required by 'virtual:world', not found
Package 'glib-2.0', required by 'virtual:world', not found
ldm.c:6:10: fatal error: glib.h: No such file or directory
    6 | #include <glib.h>
      |          ^~~~~~~~
compilation terminated.
make: *** [Makefile:26: ldm.o] Error 1

So, after all of that, maybe I should rephrase my question…

All I am trying to achieve here is automatically mounting a ground of different USB drives at a consistent mount point (so that bacula knows where to find it). I would have assumed there was a generally accepted ‘standard’ way of achieving this in non-GUI envisionments (although my research seems to come up short on this).

Any suggestions would be greatly appreciated, and/or assistance in getting one of the above tools to successfully install (and work).

Update
I have managed to work out how to get ldm installed. It turns out that what I needed to do was install some of the deval packages, which provides the necessary pkgconfig files needed to compile the software. After doing so, it compiled and installed successfully, and after creating the necessary config file, it worked as advertised.

My next job is to write a short bash script to run when a mount action occurs, to create a symlink to the just mounted drive so that there is a static mount point, regardless of the name of the drive.

Further update, I have success!

After successfully getting ldm installed (see above), I was able to get USB drives to automatically mount. Since ldm also has the ability to run a callback script, with variables for the action initiating the script, I was able to put together a very simple bash script to create a symlink to a common mount point, which allows bacula to reference the symlink irrespective of the name of the drive.

For those that are interested (or for anyone stumbling across the same problem), here is the bash script I’ve put together:

#!/bin/bash
#
# This script is expected to be called by ldm (https://github.com/LemonBoy/ldm) when mounting or unmounting a drive.
# When a drive is mounted and the first three characters of the drive label equal "RDX", a symlink will be created to a common mount point.
# When a drive is unmounted and the first three characters of the drive label qual "RDX", the symlink will be removed.


# Log that the script us running and the variables passed.
logger -t "[ldm script]" "Running ldm script. Action: $LDM_ACTION Mountpoint: $LDM_MOUNTPOINT"

# Set variable to the drive label (striping off the path)
drivelabel="${LDM_MOUNTPOINT##*/}"


# Take action only if the first three letters equal "RDX".
if [ "${drivelabel:0:3}" = "RDX" ]
then

	# Determine if the action is either mount or unmount	
	if [ "$LDM_ACTION" = "mount" ]
	then
			#Create symlink from the recently mounted drive, to a static mount point.
			logger -t "[ldm script]" "Creating symlink. Mountpoint $LDM_MOUNTPOINT"
			ln -s "$LDM_MOUNTPOINT" /mnt/RDX\ Drive
	fi
	
	if [ "$LDM_ACTION" = "unmount" ]
	then
			#Remove the symlink.
			logger -t "[ldm script]" "Removing symlink. Mountpoint $LDM_MOUNTPOINT"
			rm -f /mnt/RDX\ Drive
	fi

else

	# Write to the log that drive label did not match and therefore no action was taken.
	logger -t "[ldm script]" "Drive label did not start with RDX. No action taken."

fi

This script checks to see if the drive label starts with “RDX” (which I use to name the RDX cartridges by convention" and if it does, will either add or remove the symlink on mount/unmount.

I haven’t yet tested this with an actual RDX drive (I’ve been using a standard USB hard drive for testing), but I expect this to work just the same.