This guide provides steps to auto-mount an SMB share on Debian using a systemd mount unit and NetworkManager-wait-online.service.
Ensure cifs-utils is installed:
sudo apt update
sudo apt install cifs-utilsEnsure the mount point directory exists:
sudo mkdir -p /mnt/media_storageCreate a file to store your SMB credentials:
sudo nano /etc/smbcredentialsAdd the following lines:
username=asad
password=test
Secure the credentials file:
sudo chmod 600 /etc/smbcredentialsCreate a new systemd mount unit file:
sudo nano /etc/systemd/system/mnt-media_storage.mountAdd the following content to the file:
[Unit]
Description=Mount SMB Share
After=network-online.target
Wants=network-online.target
Requires=network-online.target
[Mount]
What=//10.10.12.74/media_storage
Where=/mnt/media_storage
Type=cifs
Options=credentials=/etc/smbcredentials,uid=1000,gid=1000,iocharset=utf8
[Install]
WantedBy=multi-user.targetReload the systemd daemon to recognize the new unit file:
sudo systemctl daemon-reloadEnable the mount unit to start at boot:
sudo systemctl enable mnt-media_storage.mountStart the mount unit immediately:
sudo systemctl start mnt-media_storage.mountCheck if the share is mounted:
df -hList the contents of the mounted directory to ensure it's working:
ls /mnt/media_storageEnsure that the system waits for the network to be fully up:
Enable and start the NetworkManager-wait-online.service:
sudo systemctl enable NetworkManager-wait-online.service
sudo systemctl start NetworkManager-wait-online.serviceCheck the status of the service to ensure it's working properly:
sudo systemctl status NetworkManager-wait-online.service- Check for errors in system logs:
sudo journalctl -xeu mnt-media_storage.mount
- Verify network connectivity to the SMB server:
ping 10.10.12.74
Following these steps should help you auto-mount an SMB share on Debian, ensuring it is available at boot time.