Yet another nerdy post, but mostly at the end of the post.
Even though I love spending my spare time on my computer, I also must come to a conclusion that computers suck sometimes. I know, heavy words from someone who appreciates those pesky metal beings, but they also give us so many unnecessary headaches in most weird situations and times.
I have been a very satisfied Linux user for more than five years now, especially with Debian, which is one of the oldest and most reliable Linux distributions. However, a few months ago, I began noticing that my main computer with Debian installed freezes when my Synology NAS gets shut down. This usually happens late at night. It means that my file manager (Thunar) freezes and is basically unusable until I reboot the computer. I was so frustrated that I was unable to locate the issue. I was constantly asking myself if it was a faulty hardware or if it was my Linux installation with Xfce desktop environment that was missing some crucial files. Not only that, but I searched and searched for the specific problem online, but I wasn’t able to find a solution. Furthermore, I even described my issue in one Linux forum, but to no avail. It felt like I was the only one with this specific user case and difficulty.
Then some days ago, I was really fed up with all this situation, that I decided to get rid of my installation. So I first installed Debian with Cinnamon, hoping that the change of the file manager would help, but using Nemo did not change much. Then I tried to install Linux Mint, but I just couldn’t do it for the life of me. At this point, it felt as if my computer wanted to live its life as it pleased, so it just obstructed my intentions. It was very moody, and wouldn’t always do as I told it to do (entering BIOS or booting menu). I swear, I think my computer sometimes acts as a donkey; it just does not want to do what I want it to do. I then tried Fedora with Xfce. It was a pleasant surprise to see how nice and smooth the distributions were, but my problem with the file manager persisted. Then I installed Debian with Plasma, and I once again liked how everything worked in that desktop environment, but also here the issue with deactivated NAS was visible.
Thunar "frozen" because Synology NAS is shut down. The file manager is not able to show any drives, files or folders.
In a total act of desperation I installed Devuan GNU+Linux, which basically is Debian but without systemd, because I thought maybe my problem can be solved if I use other init system. In Devuan’s case it is SysVinit, so I asked ChatGPT:
You are a computer and Linux expert. I want to mount Synology's two drives on my Linux with NFS. How does my fstab look like. Also, how to avoid my Linux machine hang or freeze if Synology NAS gets shut down?
I also gave it some details about my NAS and the names of the drive I wanted to mount.
Initially, it gave me the options: NFS (Network File System) and Autofs. Since I already used NFS and still had an issue, I went with Autofs this time. After going through several interactions and refinements of the given answers, I finally had a solution ready. And it works pretty well so far. What happens now when my Synology gets disconnected, is that Autofs just rescans my mounting points, and if it cannot see my NAS, it just shows the drive that's connected and ignores the ones missing.
Thunar showing only the active mount point (which is what I want). The other two are not shown, and nothing freezes.
I am not a programmer, so that I've been able to solve this issue I had for months with a great help of ChatGPT is remarkable. It only shows how generative artificial intelligence is in the process of changing the world.
And now the nerdy part, in case you're interested or can be useful. It definitely helped me. So, since Devuan Linux is using SysVinit and not the superpowers of automated systemd, I had to go around the bushes to get what I want. Here is the procedure that I could not have done without the gracious help of AI.
The Init Scrypt To Automount Drives and Ignore It When the NAS is Shut Down
- 1. Install autofs
- 2. Configure autofs
- 3. Create the Map File (/etc/auto.nfs)
- 4. Restart autofs
- 5. Test the Configuration
- 6. Verify the Mount
- 7. Create a Trigger Script
- 8. Make the Script Executable
- 9. Create the Init Script
- 10. Make the Script Executable
- 11. Add the Script to Startup
- 12. Start the Service Immediately
- 13. Reboot and Test
Install autofs
Ensure autofs
is installed:
sudo apt update
sudo apt install autofs
Configure autofs
The auto.master
file controls how autofs reads map files for mount points. The share will unmount automatically after a period of inactivity (default is 5 minutes). You can adjust this timeout by adding an idle timeout to the auto.master
entry.
Edit your auto.master
file to specify the automount directory and map file:
sudo nano /etc/auto.master
Add an entry for your NAS:
/mnt /etc/auto.nfs
Create the Map File (/etc/auto.nfs)
Create and edit the file /etc/auto.nfs
:
sudo nano /etc/auto.nfs
Add the following entries:
Backup_NAS -fstype=nfs,rw,soft,timeo=10,retrans=3,autofs_timeout=0 <NAS_IP>:/<NAS_PATH>/Backup
Filmovi_NAS -fstype=nfs,rw,soft,timeo=10,retrans=3,autofs_timeout=0 <NAS_IP>:/<NAS_PATH>/Filmovi
Dietpi -fstype=nfs,rw,soft,timeo=10,retrans=3,autofs_timeout=0 <DEVICE_IP>:/mnt/<MOUNT_POINT>
Save and close the file.
Explanation of Options:
-fstype=nfs
: Specifies the file system type as NFS.
rw
: Enables read and write permissions.
soft
: Ensures the mount fails gracefully if the NAS becomes unreachable.
timeo=10
: Sets the timeout for NFS requests to 1 second (10 tenths of a second).
retrans=3
: Limits the number of retries to 3.
192.168.1.xx:/volume1/Backup
: The NFS export path on your Synology NAS.
autofs_timeout=0
: never unmounts mount points
Restart autofs
Restart the autofs service to apply the changes:
sudo service autofs restart
Test the Configuration
Access the mount point to trigger the automount:
ls /mnt/Backup_NAS
ls /mnt/Filmovi_NAS
ls /mnt/Dietpi
If everything is configured correctly, the Backup_NAS
, Filmovi_NAS
and Dietpi
share will mount automatically when accessed.
Verify the Mount
Check if the share is mounted:
df -h | grep /mnt/Backup_NAS
Create a Trigger Script
Create a script that automatically accesses the mount points during boot. For example:
sudo nano /usr/local/bin/trigger_autofs.sh
Add the following lines to the script:
#!/bin/bash
# Trigger autofs mounts at boot
# Wait for network and autofs to start
sleep 10
# Access each mount point to trigger autofs
ls /mnt/Backup_NAS >/dev/null 2>&1
ls /mnt/Filmovi_NAS >/dev/null 2>&1
ls /mnt/Dietpi >/dev/null 2>&1
Save and close the file.
Make the Script Executable
Ensure the script has executable permissions:
sudo chmod +x /usr/local/bin/trigger_autofs.sh
Create the Init Script
Create a new init script to handle the autofs-trigger
service:
sudo nano /etc/init.d/autofs-trigger
Add the following content to the script:
#!/bin/sh
### BEGIN INIT INFO
# Provides: autofs-trigger
# Required-Start: $network $remote_fs autofs
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Trigger autofs mounts at boot
# Description: Access autofs mounts to ensure they are available after boot
### END INIT INFO
SCRIPT=/usr/local/bin/trigger_autofs.sh
NAME=autofs-trigger
DESC="Trigger autofs mounts"
case "$1" in
start)
echo "Starting $DESC"
$SCRIPT
;;
stop)
echo "Stopping $DESC"
# Nothing to stop since it's a one-time script
;;
restart|force-reload)
echo "Restarting $DESC"
$SCRIPT
;;
*)
echo "Usage: $0 {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
Save and close the file.
Make the Script Executable
Set the correct permissions for the init script:
sudo chmod +x /etc/init.d/autofs-trigger
Add the Script to Startup
Use update-rc.d
to enable the script at boot:
sudo update-rc.d autofs-trigger defaults
This command ensures the script runs at the appropriate runlevels (2, 3, 4, and 5).
Start the Service Immediately
To test the script immediately without rebooting, run:
sudo /etc/init.d/autofs-trigger start
Reboot and Test
sudo reboot
After the reboot, confirm the mounts are active:
df -h | grep /mnt
You should see your mounts (/mnt/Backup_NAS
, /mnt/Filmovi_NAS
, /mnt/Dietpi
) listed and ready for use.
Comments: 0