Add systemd automount docu

This commit is contained in:
RealStickman 2022-09-11 14:22:54 +02:00
parent eec289187f
commit bb78070a32

View File

@ -0,0 +1,46 @@
---
title: Systemd Automount
---
[toc]
Systemd can be used to mount filesystems not only on boot (simple `.mount` file), but also on request by any process. (`.automount` file)
## Mount file
The `.mount` file should be placed in `/etc/systemd/system`
**NOTE: The filename must be (mountpoint).mount with slashes `/` being replaced with dashes `-`**
Example: `/mnt/target` --> `mnt-target.mount`
Here's an example `.mount` file for a CIFS share
```
[Unit]
Description=cifs mount
[Mount]
What=//(url/ip)/(sharename)
Where=/(target mountpoint)
Type=cifs
Options=defaults,username=(user),password=(password),file_mode=0640,dir_mode=0750,iocharset=utf8,uid=(local uid),gid=(local gid)
[Install]
WantedBy=multi-user.target
```
## Automount file
The corresponding `.automount` file needs to have the same name as its `.mount` file
Example: `mnt-target.mount` and `mnt-target.automount`
```
[Unit]
Description=cifs automount
[Automount]
Where=/(target mountpoint)
[Install]
WantedBy=multi-user.target
```
Enable the `.automount` file to mount the filesystem when necessary
`# systemctl enable (target-mount).automount`