UPDATED – 26 January, 2017
This script has been updated to work with the changes made in the last guide using rClone rather than acd_cli for the ACD mount.
People have been asking how to mount all those different directories we set up in Using Amazon Cloud Drive with Plex Media Server on Ubuntu… And Encrypting It! at boot automatically. So here’s a quick guide on getting that set up. As usual, we’ll be assuming you’re using a user called “plex” for all this, and the directory structure from the guide as well.
I’ve played around with using fstab to mount all these directories, but there are just too many hurdles and things that tend to go wrong, between acd_cli needing the “_netdev” option to wait for a network device, and the EncFS mounts trying to run before acd_cli is fully mounted. Not only all that, but anything mounted automatically in fstab is mounted as root, which can cause another set of issues with accessing the directories as another user. I’ve found that a simple crontab entry is the easiest and most straightforward method.
Step 1 – Create a Password File for EncFS
To fully automate the mounting of our EncFS directories, we’ll have to have the password readily available to pass into our script. I like to keep a “scripts” directory right inside my plex home folder with another directory for logs, so let’s create that first and then move into that scripts directory:
cd ~ mkdir scripts mkdir scripts/logs cd scripts
And now we can create a password file. Just run:
And type only your EncFS password. When you’re finished, press “CTRL+X” and “Y” to save the file. Make that file executable with the following command:
chmod +x encfspass
Step 2 – Write a Script
We’ll need a script that will automatically clear out any mount points (if any) and then mount all our different shares. Go ahead and start off with opening Nano with a filename of “mount.sh” like so:
And then copy and paste the following:
#!/bin/sh #Unmount any directories already mounted /bin/fusermount -uz /home/plex/acd /bin/fusermount -uz /home/plex/.acd /bin/fusermount -uz /home/plex/.local /bin/fusermount -uz /home/plex/media #Mount ACD using rClone /usr/sbin/rclone mount acd:Plex /home/plex/.acd & #Mount encryption over these folders ENCFS6_CONFIG='/home/plex/encfs.xml' encfs --extpass="cat /home/plex/scripts/encfspass" /home/plex/.acd /home/plex/acd ENCFS6_CONFIG='/home/plex/encfs.xml' encfs --extpass="cat /home/plex/scripts/encfspass" /home/plex/.local /home/plex/local #Use union-fs to merge our remote and local directories unionfs-fuse -o cow /home/plex/local=RW:/home/plex/acd=RO /home/plex/media exit
The first section in this script is to unmount the directories we’re using just in case something breaks, so you can simply just execute this script to easily “start fresh.” If you receive any errors from fusermount, you can usually ignore them.
And to allow the script to be executed, we have to add the “execute” permission to the file:
chmod +x mount.sh
Now that you’ve got your script written, we can add it to our cron list!
Step 3 – Add Mount Script to Crontab
Start by editing your crontab jobs:
If this is your first time editing crontab, you’ll be asked to choose a text editor. If you haven’t noticed, I prefer Nano. Press “2” and “enter” to continue. Now, use your arrow keys to scroll down to the last blank line in the file, and enter the following line:
@reboot /home/plex/scripts/mount.sh > /home/plex/scripts/logs/mount.log 2>&1
“@reboot” obviously means this script will be run on a system reboot. The 2>&1 bit at the end will append to the specified log file, just in case something goes wrong with our script.
So that’s about it. The nice thing about this method is, if anything happens to your mounts or directories, you can just hop over to your scripts directory and run that mount.sh script. It should clear up most issues. Not having to worry about manually mounting anything during reboots is definitely a plus! As always, leave a comment if you have any issues with the guide, or drop me a message on Reddit. Thanks for reading!