1

I made a sh script to mount my Synology shared folders via LFS.

It works like a charm, here's the code (xxxxx stands for the IP adress of my nas)

#!/bin/sh
#Mount the following folders on Komputer with LFS protocol:
#1. data
#2. games
#3. Youtubing
sudo mount xxxxxxxxxxxx:/volume1/data /mnt/nas_media/
sudo mount xxxxxxxxxxxx:/volume1/Games /mnt/nas_games/
sudo mount xxxxxxxxxxxx:/volume1/youtubing /mnt/youtubing/

When I run the code, the folders are mounted correctly in the mounting points in /mnt/.

I created a crontab entry with

crontab -e

and i wrote the following:

#Mount useful NAS folders when starting up:
@reboot /etc/nas_mount.sh

When I reboot the system, however, the folders are not mounted. I tried inserting a sleep 30 in my script to await for all the network services to be online, to no avail.

Any ideas?

Thanks.

6
  • /etc is not appropriate at all to store user scripts, /etc is meant to store global configuration files (use something like ~/bin to store user scripts).
    – kos
    Commented Sep 4 at 14:10
  • 2
    not sure that you are taking the correct approach here. I have a Synology NAS with a number of shares which are mounted automatically on boot from entries in ~/etc/fstab. No need for a crontab entry. Happy to create an answer including example code lines based on my system which have worked consistently for a number of years including the latest 24.04.1 LTS version. Not sure what you mean by via LFS in this context.
    – graham
    Commented Sep 4 at 14:17
  • 2
    ... in any case crontab -e (user crontab) + sudo isn't the way to schedule tasks that require elevated permissions - there's no way for sudo to authenticate you without an interactive shell. You'd want to use root's crontab (sudo crontab -e) or - better - the system-wide /etc/crontab instead. Commented Sep 4 at 14:58
  • 1
    @kos fair, I moved the script to the /bin folder like you suggested.
    – Harold
    Commented Sep 5 at 8:41
  • @steeldrivert it does make sense, thanks. Then I will use sudo crontab -e. As for the system-wide crontab, I wrote /etc/crontab in my terminal but nothing happened.
    – Harold
    Commented Sep 5 at 9:01

1 Answer 1

0

the folders are mounted correctly in the mounting points in /mnt/.

That is a perfect start to automatically mounting your Synology shares on Ubuntu. However, when I tried using /mnt/ on my 24.04 instance I encountered an issue which was resolved by using the directory /media which is reflected in the code below (creating the sub-directories for the shares below that as shown).

From there in /etc/fstab create the following entries (based on your provided information in the context of the entries I have in my fstab file):

//nnn.nnn.n.nnn/volume1/data /media/nas_media cifs username=xxxxx,password=xxxxx,rw,uid=1000,gid=500
//nnn.nnn.n.nnn/volume1/games /media/nas_games cifs username=xxxxx,password=xxxxx,rw,uid=1000,gid=500
//nnn.nnn.n.nnn/volume1/youtubing /media/youtubing cifs username=xxxxxx,password=xxxxxx,rw,uid=1000,gid=500

Write out the /etc/fstab file with Ctrl+O after which return to the terminal with Ctrl+X in order to attempt to mount the shares.

Try the mount with sudo mount -a -v in terminal (-a means all and -v means verbose).

You should then be able to see that the shares are mounted in the Nautilus left panel.

If you want to see the shares on your desktop (as I have in the image below) install (if not already done so) Extension Manager and Desktop Icons NG (DING) use the cog wheel and set Show external drives in the desktop to ON and other options as desired.

Of course, replace nnn.nnn.n.nnn with your NAS IP address and also xxxxxx with your actual usernames and passwords for the Synology shares from your device.

enter image description here

enter image description here

It should be noted that my Synology NAS is formatted Ext4 in an SHR Raid configuration (the OP's is NFS) so different mount entries may be required accordingly.

enter image description here

In the end, these entries in fstab worked for the NFS system format.

nnn.nnn.n.nn:/volume1/data /mnt/nas_media/ nfs defaults 0 0
nnn.nnn.n.nn:/volume1/Games /mnt/nas_games/ nfs defaults 0 0
nnn.nnn.n.nn:/volume1/youtubing /mnt/youtubing/ nfs defaults 0 0

It may also benefit you to make a backup copy of your existing fstab file.

8
  • I suggest adding _netdev and x-systemd.automount to the options, though the first one may be implied by the filesystem type; the first one is useful to have the unit be treated as a network device, which adds the required dependencies to make it mount with the appropriate timing during boot, and the second one is used to tell systemd to treat the unit as an automount unit; this will make the unit auto-mount only when needed, but I found it especially useful to deal with a network share not remounting after suspension. Why are you assigning gid=500 though?
    – kos
    Commented Sep 5 at 10:23
  • @kos I hadn't considered those additional options since the mounts just work consistently (since 2020 at least) across LTS versions 20.04 through to 24.04 (and Debian 12). As for gid=500 I don't now recall why I set at that value to be honest but, as with the other bits, it just works. I am the only user on the system so perhaps the UID takes precedence and is otherwise ignored? My advice to the OP at this stage is to try the form suggested and if it works, then experiment further. I might even give it go on my scratch PC to test it out. Thanks.
    – graham
    Commented Sep 5 at 11:06
  • @kos OK so I have read about _netdev` & x-systemd.automaticon Unix & Linux Stack and given that the lines in my fstab work without issue across a range of systems, I've decided that they are superfluous in this case and don't affect the mount progress but thanks anyway.
    – graham
    Commented Sep 5 at 14:01
  • 1
    @graham thanks for your hints, you pointed me in the right direction, but your solution didn't work for some reason, as I got all sorts of error messages. At first a permission denied. I retried with sudo mount -a -v, but then I got an "unkown filesystem". I added auto ext4 or btrfs to suggest the filetype, to no avail. In the end, I manage to pull it off with this entry: nnn.nnn.n.nn:/volume1/data /mnt/nas_media/ nfs defaults 0 0 nnn.nnn.n.nn:/volume1/Games /mnt/nas_games/ nfs defaults 0 0 nnn.nnn.n.nn:/volume1/youtubing /mnt/youtubing/ nfs defaults 0 0
    – Harold
    Commented Sep 5 at 21:32
  • 1
    You could use NFS instead of CIFS, too, unless you disabled NFS support on the NAS
    – kos
    Commented Sep 6 at 6:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .