Mounting USB Drives in TrueNAS Scale

Mounting USB Drives in TrueNAS Scale
Photo by Carl Heyerdahl / Unsplash

This is not a post about how to use USB drives in your TrueNAS Scale as a dataset, and there are probably better solutions (i.e. udev rules). This was only a quick script and config settings for ingesting data off an external HDD for my dad, so I tried to keep things as simple as possible w/o too much CLI.

Since TrueNAS seems to be read-only for most parts, I created this script to enumerate various USB disk types and then mount them under /tmp/.

Afterwards, I configured a init/shutdown script to always ensure the folder is created when the system is rebooted.

I also ran the command via the CLI from the web-ui so it existed before we deploy our container for file browsing, and the CLI is also how we'll execute the script in the future.

mkdir -p /tmp/mounted_drives

Next, we add an ACL to allow the app user, which this permission has been explained in more detail here, to have modify permissions on the SMB Share.

While this isn't the most secure configuration, because it allows any app to modify the folder, this is the most straightforward way to configure this. I'll probably revisit it to figure out a more secure way (i.e. change the uid/gid of the File Browser container and map that locally).

Lastly, we deploy the File Browser app (version initially installed) to have some Additional Storage which is a read-only view of the expected mount folder under /tmp/mounted_drives.

We then add another Additional Storage for the SMB share that allow my dad to access the data over the network.

You can then run the script in the web shell like so, and you'll see the individual partitions of your thumbdrives or external HDDs show up like shown in the picture below.

It checks to see if you're in a tmux session first and launches one, just in case you shell disconnects in the middle of mounting or unmounting a USB device. That's happened to me before and depending on your USB device's filesystem you don't want it to interrupt that process...

Once the HDD is mounted, you should be able to see everything in your File Browser app web-ui. This'll allow you to facilitate move files over from you HDD to your SMB Share, so your lesser technical users don't have to worry about running a lot of CLI commands.

Of course, while writing this, I noticed that a few partition labels came out a null and that's something I haven't accounted for yet in my script. Eh, I'll fix it later...

NOTE! be sure to change the password for File Browser as well, the default creds are admin/admin.