This repository/documentation outlines the migration from a legacy Bash-script mount process to a robust, native systemd mount architecture. This setup prevents "already mounted" errors and secures credentials.
Credential Masking: Credentials moved from cleartext scripts to a restricted-access file.
Log Management: Configured to prevent journal flooding during network outages.
Dependency Logic: Uses network-online.target to ensure mounts only attempt after the stack is up.
Ensure the CIFS helper is installed on the Ubuntu host:
sudo apt update && sudo apt install cifs-utils -yCreate the local mount points:
sudo mkdir -p /media/mordor /media/mordor2 /media/otros /media/cursosCreate a secure credentials file to store the NAS password.
Create the file:
sudo nano /etc/nas-credentialsAdd the following content:
username=mortasoft
password=YOUR_PASSWORD_HERE
Set strict permissions (Root only):
sudo chmod 600 /etc/nas-credentialsSystemd mount units must be named after their target path. Create the following four files in /etc/systemd/system/.
"media-mordor.mount" (Repeat the pattern above for media-mordor2.mount, media-otros.mount, and media-cursos.mount, updating the What= and Where= lines accordingly.)
[Unit]
Description=Mount Multimedia Share
StartLimitIntervalSec=300
StartLimitBurst=3
[Mount]
What=//192.168.1.200/Multimedia
Where=/media/mordor
Type=cifs
Options=credentials=/etc/nas-credentials,uid=1000,gid=1000,forceuid,forcegid
[Install]
WantedBy=multi-user.target
Create a manager service to trigger all mounts simultaneously.
File: /etc/systemd/system/nas.service
[Unit]
Description=NAS Mount Manager
After=network-online.target
Wants=network-online.target media-mordor.mount media-mordor2.mount media-otros.mount media-cursos.mount
[Service]
Type=oneshot
ExecStart=/usr/bin/true
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
Execute these commands to initialize the new system:
# Reload systemd to recognize new files
sudo systemctl daemon-reloadsudo systemctl enable nas.service
sudo systemctl enable media-mordor.mount media-mordor2.mount media-otros.mount media-cursos.mountsudo systemctl start nas.service#Check Status:
systemctl status nas.service
#View Logs:
journalctl -u "media-*.mount"