Systemd Unit Types 중 하나인 mount 파일에 대해 알아보겠다.
정의
확장자는 .mount 를 가지며 파일시스템의 마운트 포인트를 나타낸다. Unit 섹션과 Install 섹션 사용은 다른 유닛들과 비슷하나 Mount 섹션이 추가된다. 마운트 지점이 /home/kw 이라면 유닛파일은 home-kw.mount 로 지정한다.
Ubuntu16.04 에서 진행하였으며
/lib/systemd/system 경로에 있는 .mount 파일을 분석
항목은 다음과 같다.
ManPage Link: https://www.freedesktop.org/software/systemd/man/systemd.mount.html
1. sys-kernel-debug.mount
[Unit]
Description=Debug File System
Documentation=https://www.kernel.org/doc/Documentation/filesystems/debugfs.txt
Documentation=http://www.freedesktop.org/wiki/Software/systemd/APIFileSystems
DefaultDependencies=no
ConditionPathExists=/sys/kernel/debug
ConditionCapability=CAP_SYS_RAWIO
Before=sysinit.target
[Mount]
What=debugfs
Where=/sys/kernel/debug
Type=debugfs
2. sys-fs-fuse-connections.mount
[Unit]
Description=FUSE Control File System
Documentation=https://www.kernel.org/doc/Documentation/filesystems/fuse.txt
Documentation=http://www.freedesktop.org/wiki/Software/systemd/APIFileSystems
DefaultDependencies=no
ConditionPathExists=/sys/fs/fuse/connections
ConditionCapability=CAP_SYS_ADMIN
After=systemd-modules-load.service
Before=sysinit.target
[Mount]
What=fusectl
Where=/sys/fs/fuse/connections
Type=fusectl
3. dev-hugepages.mount
[Unit]
Description=Huge Pages File System
Documentation=https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt
Documentation=http://www.freedesktop.org/wiki/Software/systemd/APIFileSystems
DefaultDependencies=no
Before=sysinit.target
ConditionPathExists=/sys/kernel/mm/hugepages
ConditionCapability=CAP_SYS_ADMIN
[Mount]
What=hugetlbfs
Where=/dev/hugepages
Type=hugetlbfs
4. sys-kernel-config.mount
[Unit]
Description=Configuration File System
Documentation=https://www.kernel.org/doc/Documentation/filesystems/configfs/configfs.txt
Documentation=http://www.freedesktop.org/wiki/Software/systemd/APIFileSystems
DefaultDependencies=no
ConditionPathExists=/sys/kernel/config
ConditionCapability=CAP_SYS_RAWIO
After=systemd-modules-load.service
Before=sysinit.target
[Mount]
What=configfs
Where=/sys/kernel/config
Type=configfs
5. sysinit.target.wants/sys-kernel-debug.mount
[Unit]
Description=Debug File System
Documentation=https://www.kernel.org/doc/Documentation/filesystems/debugfs.txt
Documentation=http://www.freedesktop.org/wiki/Software/systemd/APIFileSystems
DefaultDependencies=no
ConditionPathExists=/sys/kernel/debug
ConditionCapability=CAP_SYS_RAWIO
Before=sysinit.target
[Mount]
What=debugfs
Where=/sys/kernel/debug
Type=debugfs
6. sysinit.target.wants/sys-fs-fuse-connections.mount
[Unit]
Description=FUSE Control File System
Documentation=https://www.kernel.org/doc/Documentation/filesystems/fuse.txt
Documentation=http://www.freedesktop.org/wiki/Software/systemd/APIFileSystems
DefaultDependencies=no
ConditionPathExists=/sys/fs/fuse/connections
ConditionCapability=CAP_SYS_ADMIN
After=systemd-modules-load.service
Before=sysinit.target
[Mount]
What=fusectl
Where=/sys/fs/fuse/connections
Type=fusectl
7. sysinit.target.wants/dev-hugepages.mount
[Unit]
Description=Huge Pages File System
Documentation=https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt
Documentation=http://www.freedesktop.org/wiki/Software/systemd/APIFileSystems
DefaultDependencies=no
Before=sysinit.target
ConditionPathExists=/sys/kernel/mm/hugepages
ConditionCapability=CAP_SYS_ADMIN
[Mount]
What=hugetlbfs
Where=/dev/hugepages
Type=hugetlbfs
8. sysinit.target.wants/sys-kernel-config.mount
[Unit]
Description=Configuration File System
Documentation=https://www.kernel.org/doc/Documentation/filesystems/configfs/configfs.txt
Documentation=http://www.freedesktop.org/wiki/Software/systemd/APIFileSystems
DefaultDependencies=no
ConditionPathExists=/sys/kernel/config
ConditionCapability=CAP_SYS_RAWIO
After=systemd-modules-load.service
Before=sysinit.target
[Mount]
What=configfs
Where=/sys/kernel/config
Type=configfs
9. sysinit.target.wants/dev-mqueue.mount
[Unit]
Description=POSIX Message Queue File System
Documentation=man:mq_overview(7)
Documentation=http://www.freedesktop.org/wiki/Software/systemd/APIFileSystems
DefaultDependencies=no
Before=sysinit.target
ConditionPathExists=/proc/sys/fs/mqueue
ConditionCapability=CAP_SYS_ADMIN
[Mount]
What=mqueue
Where=/dev/mqueue
Type=mqueue
10. proc-sys-fs-binfmt_misc.mount
[Unit]
Description=Arbitrary Executable File Formats File System
Documentation=https://www.kernel.org/doc/Documentation/binfmt_misc.txt
Documentation=http://www.freedesktop.org/wiki/Software/systemd/APIFileSystems
DefaultDependencies=no
[Mount]
What=binfmt_misc
Where=/proc/sys/fs/binfmt_misc
Type=binfmt_misc
11. dev-mqueue.mount
[Unit]
Description=POSIX Message Queue File System
Documentation=man:mq_overview(7)
Documentation=http://www.freedesktop.org/wiki/Software/systemd/APIFileSystems
DefaultDependencies=no
Before=sysinit.target
ConditionPathExists=/proc/sys/fs/mqueue
ConditionCapability=CAP_SYS_ADMIN
[Mount]
What=mqueue
Where=/dev/mqueue
Type=mqueue
사용되는 옵션
[Unit]
Description=
Documentation=
Documentation=
DefaultDependencies=
ConditionPathExists=
ConditionCapability=
Before=
[Mount]
마운트 파일은 Mount 섹션을 포함한다.
What= 마운트할 파일 및 리소스의 절대경로
Where= 마운트할 디렉토리를 지정한다. 마운트경로가 없으면 자동으로 생성한다. unit 파일 이름과 연관이 있다.
Type= 파일시스템 타입을 가져온다 . mount(8) for details. This setting is optional.
Options= 마운트 옵션이 들어가며 콤마, 로 구분한다. See mount(8) for details. This setting is optional.
SloppyOptions= boolean 값으로, true 이면 디폴트값은 off
DirectoryMode= 디렉토리 마운트 폴더가 자동생설될 때 폴더의 권한을 설정할 수 있다. 디폴트값은 0755
TimeoutSec= 마운트 커맨드의 대기시간을 설정한다. 이 시간내에 수행되지 않으면, 실패로 간주하고 종료한다.
Check systemd.exec(5) and systemd.kill(5) for more settings.
샘플예제
ext4 파일시스템을 마운트하는 unit 파일을 생성 함.
[Unit] mnt-fs.mount 파일 생성
Description=Board rootFileSystem Documentation=https://www.kernel.org/kw Documentation=http://www.mysystem.org DefaultDependencies=no After=systemd-modules-load.service #Before=sysinit.target
[Mount] What=/home/kwangjo/Desktop/7_15.ext4 Where=/mnt/fs Type=ext4 |
systemctl start mnt-fs.mount
마운트는 확인 되었으나 재부팅시 적용되지 않았다.
자동추가하기 위해 Mount 섹션 아래에 Install 섹션 추가
[Install] Alias=homeroofs WantedBy=multi-user.target |
등록 : sudo systemctl enable mnt-fs.mount
재부팅후 정상 동작 확인함.
상태 확인
root@kwangjo:/mnt/fs# systemctl status mnt-fs.mount
● mnt-fs.mount - Board rootFileSystem
Loaded: loaded (/lib/systemd/system/mnt-fs.mount; static; vendor preset: enabled)
Active: active (mounted) since 화 2016-07-19 15:37:54 KST; 9s ago
Where: /mnt/fs
What: /dev/loop0
Docs: https://www.kernel.org/kw
http://www.mysystem.org
Process: 2537 ExecMount=/bin/mount /home/kwangjo/Desktop/7_15.ext4 /mnt/fs -t ext4 (code=exited, status=0/SUCCESS)
CPU: 4ms
7월 19 15:37:53 kwangjo systemd[1]: Mounting Board rootFileSystem...
7월 19 15:37:54 kwangjo systemd[1]: Mounted Board rootFileSystem.