How to Mount a Windows Network Drive On Boot as Systemd Service on Ubuntu

Assuming you want to mount 192.168.1.9/files to /home/username/files, create a file matching the name of your local directory where you want to mount to as below:

sudo nano /etc/systemd/system/home-username-files.mount

Its content should be the following with the remote (assuming you want 755 file permissions):

[Unit]
Description=Mount Files

[Mount]
What=//192.168.1.9/files
Where=/home/username/files
Type=cifs
Options=username=WINDOWSUSER,password=WINDOWSPASSWORD

[Install]
WantedBy=multi-user.target

Then create another file with the same name but with automount extension:

sudo nano /etc/systemd/system/home-username-files.automount

Add this content in it:

[Unit]
Description=Mount Files

[Automount]
Where=/home/username/files

[Install]
WantedBy=multi-user.target

Reload services and enable your new service:

sudo systemctl daemon-reload
sudo systemctl enable home-username-files.automount

You will see it mounted automatically after reboot. You can start and see the status of your new service by running:

sudo systemctl start home-username-files.automount
sudo systemctl status home-username-files.automount

If you want to mount the drive and assign it to a user and set file permissions, you’ll need something like this at the end of the options line:

,nounix,rw,uid=1001,gid=1001,file_mode=0770,dir_mode=0770

See all options that can be set here.