Notebook

これは日々の作業を通して学んだことや毎日の生活で気づいたことをを記録しておく備忘録である。

HTML ファイル生成日時: 2024/05/08 09:31:52.302 (台灣標準時)

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 http://deb.debian.org/debian buster/main amd64 autofs amd64 5.1.2-4 [501 kB]
Get:2 http://deb.debian.org/debian buster/main amd64 keyutils amd64 1.6-6 [51.7 kB]
Get:3 http://deb.debian.org/debian buster/main amd64 libnfsidmap2 amd64 0.25-5.1 [32.0 kB]
Get:4 http://deb.debian.org/debian buster/main amd64 libtirpc-common all 1.1.4-0.4 [16.7 kB]
Get:5 http://deb.debian.org/debian buster/main amd64 libtirpc3 amd64 1.1.4-0.4 [93.5 kB]
Get:6 http://deb.debian.org/debian buster/main amd64 rpcbind amd64 1.2.5-0.3+deb10u1 [47.1 kB]
Get:7 http://deb.debian.org/debian 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/auto.net 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/multi-user.target.wants/autofs.service → /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/multi-user.target.wants/rpcbind.service → /lib/systemd/system/rpcbind.service.
Created symlink /etc/systemd/system/sockets.target.wants/rpcbind.socket → /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/multi-user.target.wants/nfs-client.target → /lib/systemd/system/nfs-client.target.
Created symlink /etc/systemd/system/remote-fs.target.wants/nfs-client.target → /lib/systemd/system/nfs-client.target.
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 auto.net
-rwxr-xr-x 1 root root  2191 Jul  9  2018 auto.smb

auto.master.d:
total 0

設定ファイルの編集

設定ファイルに必要な変更を加える。

# cd /etc
# cp -pi auto.master auto.master.original
# vi auto.master
# diff auto.master.original auto.master
13c13
< #/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. Computer___FreeBSD/20220621_0.html
  3. Food___Taiwan/20220429_0.html
  4. Computer___Network/20230516_00.html
  5. Computer___Python/20220715_0.html
  6. Computer___NetBSD/20220817_3.html
  7. Computer___Python/20220410_0.html
  8. Computer___Debian/20210223_1.html
  9. Food___Taiwan/20230526_00.html
  10. Food___Taiwan/20210205_5.html
  11. Computer___Python/20210124_0.html
  12. Computer___Network/20230508_00.html
  13. Computer___NetBSD/20220818_1.html
  14. Food___Taiwan/20210205_1.html
  15. Computer___NetBSD/20220428_0.html
  16. Science___Astronomy/20220503_0.html
  17. Computer___TeX/20230503_00.html
  18. Travel___Taiwan/20220809_2.html
  19. Computer___Network/20230726_00.html
  20. Computer___NetBSD/20210204_0.html
  21. Science___Math/20220420_0.html
  22. Computer___NetBSD/20230515_00.html
  23. Computer___NetBSD/20220808_0.html
  24. Science___Astronomy/20220420_1.html
  25. Food___Taiwan/20230618_00.html
  26. Computer___NetBSD/20230119_00.html
  27. Computer___Python/20220816_1.html
  28. Food___Taiwan/20220424_8.html
  29. Food___Taiwan/20220424_1.html
  30. Computer___NetBSD/20210204_2.html


HTML file generated by Kinoshita Daisuke.