最後更新: 2024-09-06
介紹
systemd.mount — Mount unit configuration
A unit configuration file whose name ends in ".mount"
unit file 的名稱係有意思的, 如
mount /home/data 相當於要有 home-data.mount
目錄
Example: 設定 2M hugepage 的 mountpoint
dev-hugepages.mount
dev-hugepages.mount 預設會建立 /dev/hugepages
mount | grep ^huge
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=1024M)
(/lib/systemd/system/dev-hugepages.mount)
由於要同時使用 2M 及 1G, 以免混淆, 所以要 disable 先.
Step 1: mask 了原本的 dev-hugepages.mount
systemctl stop dev-hugepages.mount
systemctl mask dev-hugepages.mount
Step 2: 建立新的 hugepages2M 及 hugepages1G
/etc/systemd/system/dev-hugepages2M.mount
[Unit] Description=Huge Pages File System DefaultDependencies=no Before=sysinit.target ConditionPathExists=/sys/kernel/mm/hugepages ConditionCapability=CAP_SYS_ADMIN ConditionVirtualization=!private-users [Mount] What=hugetlbfs Where=/dev/hugepages2M Type=hugetlbfs Options=nofail,pagesize=2M [Install] WantedBy=sysinit.target
Info: target
* 必須使用名稱 dev-hugepages2M.mount, 否則 start 時有 error
# hugepages2M.mount: Where= setting doesn't match unit name. Refusing.
systemctl daemon-reload
systemctl enable dev-hugepages2M.mount --now
# 如 dev-hugepages2M.mount 一樣建立 1G 版本
enable dev-hugepages1G.mount --now
Verify
systemctl status dev-hugepages2M.mount
mount | grep ^huge
Settings
Default Dependencies
* The following dependencies are added unless "DefaultDependencies=no" is set
Mount units
referring to local file systems automatically gain an After= dependency on local-fs-pre.target, and a Before= dependency on local-fs.target unless one or more mount options among nofail, x-systemd.wanted-by=, and x-systemd.required-by= is set. See below for detailed information.
Additionally, an After= dependency on swap.target is added when the file system type is "tmpfs".
Network mount units
automatically acquire After= dependencies on remote-fs-pre.target, network.target, plus After= and Wants= dependencies on network-online.target, and a Before= dependency on remote-fs.target, unless one or more mount options among nofail, x-systemd.wanted-by=, and x-systemd.required-by= is set.
Options=
This takes a comma-separated list of options. This setting is optional.
e.g.
Options=defaults,nofail