Anyone have an idiots guide to writing a script to mount drives on boot?

I’m new to Linux (only installed it to use rclone), and finding myself a little lost with the scripting.

In windows I would make a batch file and drop it in startup.

Any basics?

Make new service file:
sudo nano /etc/systemd/system/rclone-mount.service

[Unit]
Description=rclone Amazon Cloud Drive FUSE mount
Documentation=http://rclone.org/docs/
After=network-online.target

[Service]
Type=forking
User=plex
Group=plex
ExecStart= rclone mount --allow-non-empty --allow-other --max-read-ahead 200M --checkers 16 acd:/ /storage/.acd/ &
ExecStop= fusermount -uz /storage/.acd

[Install]
Wants=network-online.target

Proceed with
sudo systemctl daemon-reload
sudo systemctl enable rclone-mount.service
systemctl start rclone-mount.service

Enable network-online.target ( so rclone does not do mount before internet is present on boot )
systemctl enable NetworkManager-wait-online.service

And thats it, now when you reboot your drive will be automatically mounted.
You can check if rclone mounted the drive with
findmnt | grep rclone

p.s. Dont forget to change your names for remote and paths for mount.

Hello @filthyrich,

If you are lucky (or savvy, despite being a beginner) enough to be running a distro free of the systemd abomination, you can just edit /etc/rc.local and put your commands in there – they will be run automatically at every boot.

@Ajki: is the above crapload of commands really necessary to do this very simple thing with systemd? I have avoided this latest Poettering abomination so far on philosophical grounds, seems it is good policy to avoid it in practical grounds too…

Cheers,

Durval.

I’m on Ubuntu 16.04. I think it has system…

@Ajki thanks!!!

If I have 2 drives to mount (movies are separate from tv), would I put 2 entries in the one script, or use two scripts?

Thanks again!

I’ll provide an alternate method that I use and seems to work well. Easy and works for any number of mounts.

Make some script somewhere:
nano /root/mount.sh

#!/bin/bash
/usr/sbin/rclone mount acdcrypt: /mnt/acd &

Make sure to mark it executable:
chmod +x /root/mount.sh

As root, go into crontab:
crontab -e

Then add a line like:
@reboot sh /root/mount.sh

Just make more scripts for more mounts and add them all to cron.

So like nano /root/mount1.sh

nano /root/mount2.sh

etc etc?

Yeah, make 2 scripts with different filename and different mount command inside and add both in separate lines to crontab.

Nice!

Thank you guys!

Its been quite irritating remounting drives every time you reboot.

@durval I know what you mean but since systemd became linux standard and its here to stay, I use it for all my services.

@filthyrich i would not use two mounts for movies and series you should consider mounting a folder that have movies & series as subfolders. ( you can use rclone move if you dont have it set like that atm )

I have it set up with 4 buckets at the moment:

1 ) TV-Current
2) TV-Old
3) Movies-Current
4) Movies-Old

Im trying to avoid bans from scanning so much.

I’m not so sure about that: beyond the Devuan distro which I’m using right now, there are quite a few other options for those unwilling to go the systemd way… for starters, there are 81 of them listed just on this page right now: http://without-systemd.org/wiki/index.php/Main_Page#GNU.2FLinux_distributions

Of course you are within your rights, so more power to you. My post was directed towards those that haven’t made a commitment yet and so can still be saved :wink:

Anyway, before this gets completely OT, I will refrain from posting further on this subject.

Cheers,

Durval.