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-utils
Ensure the mount point directory exists:
sudo mkdir -p /mnt/media_storage
Create a file to store your SMB credentials:
sudo nano /etc/smbcredentials
Add the following lines:
username=asad
password=test
Secure the credentials file:
sudo chmod 600 /etc/smbcredentials
Create a new systemd mount unit file:
sudo nano /etc/systemd/system/mnt-media_storage.mount
Add 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.target
Reload the systemd daemon to recognize the new unit file:
sudo systemctl daemon-reload
Enable the mount unit to start at boot:
sudo systemctl enable mnt-media_storage.mount
Start the mount unit immediately:
sudo systemctl start mnt-media_storage.mount
Check if the share is mounted:
df -h
List the contents of the mounted directory to ensure it's working:
ls /mnt/media_storage
Ensure 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.service
Check 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.