Categories :

Network Drive mapping using systemd

Last Updated on 17/11/2023 by Kevin Agar

To configure systemd to automatically mount a network folder on boot, you need 2 files

mnt-pibackups.mount # The .mount file specifies how to mount a drive

mnt-pibackups.automount. #The .automount file specifies what to mount automatically on boot

For example, to mount in /home/user/myfolder the file names must be home-user-myfolder.(auto)mount.

The content of the .mount file is:

# cat /etc/systemd/system/mnt-pibackups.mount
[Unit]
Description=Remote Win Mount
[Mount]
What=//192.168.0.13/Volume_1/MaxAir_Backups
Where=/mnt/pibackups
Type=cifs
Options=user=myuser,password=secret123,uid=www-data,gid=www-data,vers=1.0,noatime
[Install]
WantedBy=multi-user.target

The content of the .automount file is:


# cat /etc/systemd/system/mnt-pibackups.automount
[Unit]
Description=Automount Remote Win Mount
[Automount]
Where=/mnt/pibackups
[Install]
WantedBy=multi-user.target

Then, reload the units to ensure everything is to its latest version:

# sudo systemctl daemon-reload

At this point, you should be able to manually mount and unmount the remote folder using systemctl:

# sudo systemctl start mnt-pibackups.mount

# sudo systemctl stop mnt-pibackups.mount

This will not, however, automatically mount the system at startup. To do so, just enable the automount

# sudo systemctl enable mnt-pibackups.automount

Leave a Reply

Your email address will not be published. Required fields are marked *