wiki-grav/pages/02.linux/systemd-automount/default.en.md

48 lines
1.1 KiB
Markdown
Raw Normal View History

2022-09-11 14:22:54 +02:00
---
title: 'Systemd Automount'
visible: true
2022-09-11 14:22:54 +02:00
---
[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
```systemd
2022-09-11 14:22:54 +02:00
[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`