HTML ファイル生成日時: 2023/09/04 07:18:18.947 (台灣標準時)

Debian で autofs を使い自動で NFS マウントする方法

NetBSD だと amd を使うと、いちいち root にならなくても、必要なときに必 要なディスクを NFS マウントしてくれるようにすることができる。 Debian だと autofs がその役割を果たしてくれるようなので、その設定方法を記録し ておく。

autofs のインストール

まず、 root になって、 autofs のインストールを行う。 apt コマンドを使 えば簡便である。

# apt search autofs
Sorting... Done
Full Text Search... Done
afuse/stable 0.4.1-1+b3 amd64
  automounting file system implemented in user-space using FUSE

autodir/stable 0.99.9-10+b1 amd64
  Automatically creates home and group directories for LDAP/NIS/SQL/local accounts

autofs/stable 5.1.2-4 amd64
  kernel-based automounter for Linux

autofs-hesiod/stable 5.1.2-4 amd64
  Hesiod map support for autofs

autofs-ldap/stable 5.1.2-4 amd64
  LDAP map support for autofs

fusiondirectory-plugin-autofs/stable 1.2.3-4+deb10u1 all
  autofs plugin for FusionDirectory

fusiondirectory-plugin-autofs-schema/stable 1.2.3-4+deb10u1 all
  LDAP schema for FusionDirectory autofs plugin

obexfs/stable 0.11-2+b1 amd64
  mount filesystem of ObexFTP capable devices

# apt install autofs
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-image-4.19.0-11-amd64 linux-image-4.19.0-12-amd64
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
  keyutils libnfsidmap2 libtirpc-common libtirpc3 nfs-common rpcbind
Suggested packages:
  open-iscsi watchdog
The following NEW packages will be installed:
  autofs keyutils libnfsidmap2 libtirpc-common libtirpc3 nfs-common rpcbind
0 upgraded, 7 newly installed, 0 to remove and 0 not upgraded.
Need to get 973 kB of archives.
After this operation, 4,553 kB of additional disk space will be used.
Do you want to continue? [Y/n] 
Get:1 buster/main amd64 autofs amd64 5.1.2-4 [501 kB]
Get:2 buster/main amd64 keyutils amd64 1.6-6 [51.7 kB]
Get:3 buster/main amd64 libnfsidmap2 amd64 0.25-5.1 [32.0 kB]
Get:4 buster/main amd64 libtirpc-common all 1.1.4-0.4 [16.7 kB]
Get:5 buster/main amd64 libtirpc3 amd64 1.1.4-0.4 [93.5 kB]
Get:6 buster/main amd64 rpcbind amd64 1.2.5-0.3+deb10u1 [47.1 kB]
Get:7 buster/main amd64 nfs-common amd64 1:1.3.4-2.5+deb10u1 [231 kB]
Fetched 973 kB in 1s (774 kB/s) 
Selecting previously unselected package autofs.
(Reading database ... 100058 files and directories currently installed.)
Preparing to unpack .../0-autofs_5.1.2-4_amd64.deb ...
Unpacking autofs (5.1.2-4) ...
Selecting previously unselected package keyutils.
Preparing to unpack .../1-keyutils_1.6-6_amd64.deb ...
Unpacking keyutils (1.6-6) ...
Selecting previously unselected package libnfsidmap2:amd64.
Preparing to unpack .../2-libnfsidmap2_0.25-5.1_amd64.deb ...
Unpacking libnfsidmap2:amd64 (0.25-5.1) ...
Selecting previously unselected package libtirpc-common.
Preparing to unpack .../3-libtirpc-common_1.1.4-0.4_all.deb ...
Unpacking libtirpc-common (1.1.4-0.4) ...
Selecting previously unselected package libtirpc3:amd64.
Preparing to unpack .../4-libtirpc3_1.1.4-0.4_amd64.deb ...
Unpacking libtirpc3:amd64 (1.1.4-0.4) ...
Selecting previously unselected package rpcbind.
Preparing to unpack .../5-rpcbind_1.2.5-0.3+deb10u1_amd64.deb ...
Unpacking rpcbind (1.2.5-0.3+deb10u1) ...
Selecting previously unselected package nfs-common.
Preparing to unpack .../6-nfs-common_1%3a1.3.4-2.5+deb10u1_amd64.deb ...
Unpacking nfs-common (1:1.3.4-2.5+deb10u1) ...
Setting up libtirpc-common (1.1.4-0.4) ...
Setting up keyutils (1.6-6) ...
Setting up libnfsidmap2:amd64 (0.25-5.1) ...
Setting up autofs (5.1.2-4) ...

Creating config file /etc/auto.master with new version

Creating config file /etc/ with new version

Creating config file /etc/auto.misc with new version

Creating config file /etc/auto.smb with new version

Creating config file /etc/autofs.conf with new version

Creating config file /etc/default/autofs with new version
Created symlink /etc/systemd/system/ → /lib/systemd/system/autofs.service.
update-rc.d: warning: start and stop actions are no longer supported; falling back to defaults
Setting up libtirpc3:amd64 (1.1.4-0.4) ...
Setting up rpcbind (1.2.5-0.3+deb10u1) ...
Created symlink /etc/systemd/system/ → /lib/systemd/system/rpcbind.service.
Created symlink /etc/systemd/system/ → /lib/systemd/system/rpcbind.socket.
Setting up nfs-common (1:1.3.4-2.5+deb10u1) ...

Creating config file /etc/idmapd.conf with new version
Adding system user `statd' (UID 110) ...
Adding new user `statd' (UID 110) with group `nogroup' ...
Not creating home directory `/var/lib/nfs'.
Created symlink /etc/systemd/system/ → /lib/systemd/system/
Created symlink /etc/systemd/system/ → /lib/systemd/system/
nfs-utils.service is a disabled or a static unit, not starting it.
Processing triggers for systemd (241-7~deb10u6) ...
Processing triggers for man-db (2.8.5-2) ...
Processing triggers for libc-bin (2.28-10) ...

autofs がインストールされると、 /etc 以下に必要なファイルがコピーされ る。

# cd /etc
# ls -l auto*
-rw-r--r-- 1 root root 13354 Jul  9  2018 autofs.conf
-rw-r--r-- 1 root root   797 Jul  9  2018 auto.master
-rw-r--r-- 1 root root   524 Jul  9  2018 auto.misc
-rwxr-xr-x 1 root root  1039 Jul  9  2018
-rwxr-xr-x 1 root root  2191 Jul  9  2018 auto.smb

total 0



# cd /etc
# cp -pi auto.master auto.master.original
# vi auto.master
# diff auto.master.original auto.master
< #/net -hosts
> /net  -hosts



# mkdir /net

autofs の起動

以下のようにして autofs を起動する。

# /etc/init.d/autofs
Usage: /etc/init.d/autofs {start|forcestart|stop|restart|forcerestart|reload|force-reload|status}
# /etc/init.d/autofs start
[ ok ] Starting autofs (via systemctl): autofs.service.

NFS サーバのディレクトリにアクセス

これで、 NFS サーバのディレクトリが見えるようになる。ホスト名 nfs_server の /tmp を読み書きしたい場合には、 /net/nfs_server/tmp を見 てみれば、自動的に NFS マウントされる。

Frequently accessed files

  1. Computer___Python/20220518_0.html
  2. Food___Taiwan/20220429_0.html
  3. Computer___FreeBSD/20220621_0.html
  4. Food___Taiwan/20210205_5.html
  5. Computer___NetBSD/20220817_3.html
  6. Computer___Python/20220410_0.html
  7. Travel___Taiwan/20220809_2.html
  8. Computer___Debian/20210223_1.html
  9. Science___Astronomy/20220503_0.html
  10. Food___Taiwan/20210205_1.html
  11. Computer___NetBSD/20220818_1.html
  12. Computer___Python/20210124_0.html
  13. Computer___NetBSD/20220428_0.html
  14. Science___Astronomy/20220420_1.html
  15. Food___Taiwan/20210131_1.html
  16. Food___Taiwan/20230526_00.html
  17. Food___Taiwan/20220424_1.html
  18. Food___Taiwan/20220424_8.html
  19. Computer___Python/20220715_0.html
  20. Food___Taiwan/20220424_2.html
  21. Computer___NetBSD/20210204_2.html
  22. Food___Taiwan/20220819_1.html
  23. Computer___NetBSD/20210204_0.html
  24. Science___Astronomy/20220703_4.html
  25. Food___Taiwan/20210227_4.html
  26. Food___Taiwan/20220829_2.html
  27. Computer___Python/20220816_1.html
  28. Computer___NetBSD/20220406_0.html
  29. Science___Astronomy/20210214_2.html
  30. Food___Taiwan/20210216_1.html

HTML file generated by Kinoshita Daisuke.