「Autofs」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(同期)
(リンクを修正)
 
(3人の利用者による、間の6版が非表示)
5行目: 5行目:
 
[[ru:Autofs]]
 
[[ru:Autofs]]
 
[[uk:Autofs]]
 
[[uk:Autofs]]
[[zh-CN:Autofs]]
+
[[zh-hans:Autofs]]
このドキュメントは AutoFS を設定する手順を解説しています。AutoFS はリムーバルメディアやネットワーク共有などが接続されたりアクセスされたときに自動でマウントするパッケージです。
+
このドキュメントは AutoFS を設定する手順を解説しています。AutoFS はリムーバルメディアやネットワーク共有などが接続されたりアクセスされたときに自動でマウントするパッケージです。
   
 
== インストール ==
 
== インストール ==
25行目: 25行目:
 
}}
 
}}
   
  +
各行の最初の値はテンプレートのメディアをマウントするベースディレクトリです。2番目の値は使用するテンプレートです。デフォルトのベースパスは {{ic|/media}} となっていますが、自由に変更できます。例:
The first value on each line determines the base directory under which all the media in a template are mounted, the second value is which template to use. The default base path is {{ic|/media}}, but you can change this to any other location you prefer. For instance:
 
   
 
{{hc|/etc/autofs/auto.master|2=
 
{{hc|/etc/autofs/auto.master|2=
32行目: 32行目:
   
 
}}
 
}}
  +
{{Note|テンプレートファイルの末尾には改行が必要です (最後の単語の後に {{ic|ENTER}} を押してください)。EOF (end of file) 行が存在しない場合、AutoFS デーモンは正しくロードされません。}}
{{Note|Make sure there is an empty line on the end of template files (press {{ic|ENTER}} after last word). If there is no correct EOF (end of file) line, the AutoFS daemon will not properly load.}}
 
   
  +
{{ic|timeout}} パラメータではディレクトリをアンマウントする秒数を設定します。
The optional parameter {{ic|timeout}} sets the amount of seconds after which to unmount directories.
 
   
  +
システム上にベースディレクトリが存在しなかった場合、作成されます。動的にメディアをロードするためにベースディレクトリはマウントされるため、autofs が動作している間、ベースディレクトリにもともとあった中身を閲覧することはできなくなります。使用中のディレクトリを間違って自動マウントしてしまったとしても、{{ic|auto.master}} でディレクトリを変更して AutoFS を再起動することで元に戻せます。
The base directory will be created if it does not exist on your system. The base directory will be mounted on to load the dynamically loaded media, which means any content in the base directory will not be accessible while autofs is on. This procedure is however non-destructive, so if you accidentally automount into a live directory you can just change the location in {{ic|auto.master}} and restart AutoFS to regain the original contents.
 
   
  +
動的にロードされたディレクトリがマウントされた後でも元あったファイルが使えるようにしたい場合、他のディレクトリ (例: {{ic|/var/autofs/net}}) にマウントするようにするかソフトリンクを使ってください:
If you still want to automount to a target non-empty directory and want to have the original files available even after the dynamically loaded directories are mounted, you can use autofs to mount them to another directory (e.g. /var/autofs/net) and create soft links.
 
   
 
# ln -s /var/autofs/net/share_name /media/share_name
 
# ln -s /var/autofs/net/share_name /media/share_name
   
  +
もしくは autofs でメディアを別のフォルダにマウントする場合:
Alternatively, you can have autofs mount your media to a specific folder, rather than inside a common folder.
 
   
 
{{hc|/etc/autofs/auto.master|2=
 
{{hc|/etc/autofs/auto.master|2=
51行目: 51行目:
 
/home/user/usbstick -fstype=auto,async,nodev,nosuid,umask=000 :/dev/sdb1
 
/home/user/usbstick -fstype=auto,async,nodev,nosuid,umask=000 :/dev/sdb1
 
}}
 
}}
  +
{{Note|共有への接続が失われたときにリソースがロックされたままになるという問題が発生します。フォルダにアクセスしようとしたとき、プログラムは反応が返ってくるまでロックされ、接続が戻るか、プロセスを強制的に終了するまでアンマウントができません。この問題を緩和するには、共有に接続が常に可能な場合のみ使用するようにして、ホームフォルダなど頻繁に使用するフォルダでは使用しないようにしてください。}}
{{Note|This can cause problems with resources getting locked if the connection to the share is lost. When trying to access the folder, programs will get locked into waiting for a response, and either the connection has to be restored or the process has to be forcibly killed before unmounting is possible. To mitigate this, only use if you will always be connected to the share, and do not use your home folder or other commonly used folders lest your file browser reads ahead into the disconnected folder}}
 
   
 
* {{ic|/etc/nsswitch.conf}} ファイルを開いて automount エントリを追加してください:
 
* {{ic|/etc/nsswitch.conf}} ファイルを開いて automount エントリを追加してください:
60行目: 60行目:
 
これでデバイスにアクセスしたときに自動的にマウントされるようになります。アクセスしているかぎりはマウントされ続けます。
 
これでデバイスにアクセスしたときに自動的にマウントされるようになります。アクセスしているかぎりはマウントされ続けます。
   
=== リムーバルメディア ===
+
=== リムーバルメディア ===
   
  +
リムーバブルデバイスは空いているブロックデバイスのパスが割り当てられます。例えば、{{ic|/dev/sd{a,b,c} }} が既に使われている場合、次にマウントされたリムーバブルメディアには {{ic|/dev/sdd}} ブロックが与えられます。順番が定かでないブロックデバイスのパスに合わせてマウントポイントを割り当てる代わりに、リムーバブルメディアの UUID や PARTUUID をマップファイルで使用するという方法があります。
* {{ic|/etc/autofs/auto.misc}} を開いて様々なデバイスを追加・削除・編集してください。例えば:
 
   
  +
例えば、特定の USB ドライブを {{ic|/mnt/black}} というパスにマウントするには、テンプレートファイルとマップファイルを以下のように設定:
{{hc|/etc/autofs/auto.misc|<nowiki>
 
  +
{{hc|/etc/autofs/auto.master|2=
#kernel -ro ftp.kernel.org:/pub/linux
 
  +
# master template file
#boot -fstype=ext2 :/dev/hda1
 
  +
/mnt /etc/autofs/auto.mnt # [options here]
usbstick -fstype=auto,async,nodev,nosuid,umask=000 :/dev/sdb1
 
  +
cdrom -fstype=iso9660,ro :/dev/cdrom
 
  +
}}
#floppy -fstype=auto :/dev/fd0
 
</nowiki>}}
 
   
  +
マウントしたいパーティションの UUID を {{ic|blkid}} を使って確認してから、マップファイルを生成:
CD/DVD のコンボドライブがある場合は {{ic|cdrom}} の行を {{ic|-fstype<nowiki>=</nowiki>auto}} のように置き換えることでメディアのタイプが自動で検出されるようになります。
 
  +
<nowiki># _ID=$( blkid --output value --match-tag PARTUUID /dev/sd</nowiki>''XY'' )
  +
# printf "%s %s\n" "black -fstype=auto :PARTUUID=" "${_ID}" >/etc/autofs/auto.mnt
   
 
=== NFS ネットワークマウント ===
 
=== NFS ネットワークマウント ===
   
  +
AutoFS はリモートサーバー上の [[NFS]] 共有を自動で認識・マウントする新しい方法を提供しています (autofs5 で AutoFS のネットワークテンプレートは {{ic|/etc/autofs/auto.net}} から削除されました)。自動認識によるネットワーク共有のマウントを有効にするには、以下を {{ic|/etc/autofs/auto.master}} ファイルに追加してください:
AutoFS provides a new way of automatically discovering and mounting [[NFS]]-shares on remote servers (the AutoFS network template in {{ic|/etc/autofs/auto.net}} has been removed in autofs5). To enable automatic discovery and mounting of network shares from all accessible servers without any further configuration, you will need to add the following to the {{ic|/etc/autofs/auto.master}} file:
 
   
 
/net -hosts --timeout=60
 
/net -hosts --timeout=60
   
  +
{{Note|({{ic|/etc/hosts}} で IP アドレスに名前を付けるか [[DNS]] を使用して) ホストネームが解決できるようになっていること、そして {{Pkg|nfs-utils}} がインストール・動作していることを確認してください。また、共有フォルダを閲覧するには RPC を有効にする必要があります ({{ic|rpcbind.service}} を[[起動]]・[[有効化]]してください)。}}
Each host name needs to be resolveable, e.g. the name an IP address in {{ic|/etc/hosts}} or via [[Wikipedia:Domain_Name_System|DNS]] and please make sure you have {{Pkg|nfs-utils}} installed and working. You also have to enable RPC (systemctl start|enable rpcbind) to browse shared Folders.
 
   
  +
例えば、リモートサーバーの名前が ''fileserver'' で NFS 共有の名前が ''/home/share'' の場合、以下のコマンドを実行するだけで共有にアクセスできます (サーバーのホストネームがディレクトリの名前になります):
For instance, if you have a remote server ''fileserver'' (the name of the directory is the hostname of the server) with an NFS share named ''/home/share'', you can just access the share by typing:
 
   
 
# cd /net/fileserver/home/share
 
# cd /net/fileserver/home/share
88行目: 89行目:
 
{{Note|Please note that ''ghosting'', i.e. automatically creating directory placeholders before mounting shares is enabled by default, although AutoFS installation notes claim to remove that option from {{ic|/etc/conf.d/autofs}} in order to start the AutoFS daemon.}}
 
{{Note|Please note that ''ghosting'', i.e. automatically creating directory placeholders before mounting shares is enabled by default, although AutoFS installation notes claim to remove that option from {{ic|/etc/conf.d/autofs}} in order to start the AutoFS daemon.}}
   
  +
{{ic|-hosts}} オプションは {{ic|showmount}} コマンドと同じような仕組みでリモートの共有を認識します。以下のコマンドを実行することで共有ディレクトリを確認できます:
The {{ic|-hosts}} option uses a similar mechanism as the {{ic|showmount}} command to detect remote shares. You can see the exported shares by typing:
 
   
 
# showmount <servername> -e
 
# showmount <servername> -e
   
 
''<servername>'' はあなたのサーバーの名前に置き換えてください。
 
''<servername>'' はあなたのサーバーの名前に置き換えてください。
 
systemd の自動マウントサービスを使う方法もあります。[[NFS#systemd で /etc/fstab を使う|NFS と systemd-automount]] を参照してください。
 
   
 
==== NFS の手動設定 ====
 
==== NFS の手動設定 ====
To mount a NFS share on server_name called /srv/shared_dir to another computer named client_pc at location /mnt/foo, edit auto.master and create a config file for the share (auto.server_name):
+
server_name /srv/shared_dir という名前の NFS 共有を client_pc というコンピュータの /mnt/foo にマウントする場合、auto.master を編集して共有の設定ファイルを作成します (auto.server_name):
 
{{hc|<nowiki>/etc/autofs/auto.master</nowiki>|<nowiki>/mnt /etc/autofs/auto.server_name --timeout 60</nowiki>}}
 
{{hc|<nowiki>/etc/autofs/auto.master</nowiki>|<nowiki>/mnt /etc/autofs/auto.server_name --timeout 60</nowiki>}}
 
{{hc|<nowiki>/etc/autofs/auto.server_name</nowiki>|<nowiki>foo -rw,soft,intr,rsize=8192,wsize=8192 server_name:/srv/shared_dir</nowiki>}}
 
{{hc|<nowiki>/etc/autofs/auto.server_name</nowiki>|<nowiki>foo -rw,soft,intr,rsize=8192,wsize=8192 server_name:/srv/shared_dir</nowiki>}}
103行目: 102行目:
 
=== Samba ===
 
=== Samba ===
   
  +
==== 単一の共有フォルダ ====
The Arch package does not provide any [[Samba]] or CIFS templates/scripts (23.07.2009), but the following should work for single shares:
 
   
Add the following to {{ic|/etc/autofs/auto.master}}:
+
以下を {{ic|/etc/autofs/auto.master}} に追加:
/media/[my_server] /etc/autofs/auto.[my_server] --timeout=60 --ghost
+
/media/[my_server] /etc/autofs/auto.[my_server] --timeout 60 --browse
  +
{{ic|--timeout}} はファイルシステムがアンマウントされるまでの待機時間を定義します。{{ic|--browse}} オプションはネットワーク共有が使えなくなったときにタイムアウトを防ぐために各マウントポイントに空のフォルダを作成します。
where {{ic|--timeout}} defines how many seconds to wait before the file system is unmounted. The {{ic|--ghost}} option creates empty folders for each mount-point in the file in order to prevent timeouts, if a network share cannot be contacted.
 
   
Next create a file {{ic|/etc/autofs/auto.[my_server]}}
+
そして {{ic|/etc/autofs/auto.[my_server]}} ファイルを作成:
 
[any_name] -fstype=cifs,[other_options] ://[remote_server]/[remote_share_name]
 
[any_name] -fstype=cifs,[other_options] ://[remote_server]/[remote_share_name]
   
  +
{{ic|other_options}} セクションに、共有で使用するユーザー名とパスワードを指定してください:
You can specify a user name and password to use with the share in the {{ic|other_options}} section:
 
 
[any_name] -fstype=cifs,username=[username],password=[password],[other_options] ://[remote_server]/[remote_share_name]
 
[any_name] -fstype=cifs,username=[username],password=[password],[other_options] ://[remote_server]/[remote_share_name]
   
  +
{{Note|&#36; などの文字はバックスラッシュでエスケープしてください。}}
{{Note|Escape &#36;, and other characters, with a backslash when neccessary.}}
 
  +
  +
==== 複数の共有フォルダ ====
  +
  +
{{ic|/etc/autofs/auto.[my_server]}} では複数の共有フォルダを指定することができます。例:
  +
  +
[any_name] -fstype=cifs,[other_options] /photos ://[remote_server]/photos /music ://[remote_server]/music /video ://[remote_server]/video
  +
  +
==== 自動探索 ====
  +
  +
{{ic|/etc/autofs/auto.smb}} のコメントを見てください。
   
 
=== FTP と SSH (FUSE を使用) ===
 
=== FTP と SSH (FUSE を使用) ===
140行目: 149行目:
   
 
{{Note| Your passwords are plainly visible for anyone that can run {{ic|df}} (only for mounted servers) or view the file {{ic|/etc/autofs/auto.ftp}}.}}
 
{{Note| Your passwords are plainly visible for anyone that can run {{ic|df}} (only for mounted servers) or view the file {{ic|/etc/autofs/auto.ftp}}.}}
  +
セキュリティを高めたい場合 {{ic|~root/.netrc}} ファイルを作成することでパスワードを追加できます。パスワードは平文のテキストですが、600 にパーティションを設定すれば {{ic|df}} コマンドで表示されなくなります。フォーマットは:
If you want slightly more security you can create the file {{ic|~root/.netrc}} and add the passwords there.
 
Passwords are still plain text, but you can have mode 600, and {{ic|df}} command will not show them (mounted or not).
 
This method is also less sensitive to special characters (that else must be escaped) in the passwords. The format is:
 
   
 
machine remoteserver
 
machine remoteserver
148行目: 155行目:
 
password mypassword
 
password mypassword
   
The line in {{ic|/etc/autofs/auto.ftp}} looks like this without user and password:
+
ユーザー名とパスワードを指定しない場合 {{ic|/etc/autofs/auto.ftp}} に追加する行は以下のようになります:
   
 
servername -fstype=curl,allow_other :ftp\://remoteserver
 
servername -fstype=curl,allow_other :ftp\://remoteserver
   
Create the file {{ic|/sbin/mount.curl}} with this code:
+
以下の内容で {{ic|/sbin/mount.curl}} ファイルを作成:
   
 
{{hc|/sbin/mount.curl|<nowiki>
 
{{hc|/sbin/mount.curl|<nowiki>
#! /bin/sh
+
#!/bin/sh
curlftpfs $1 $2 -o $4,disable_eprt
+
curlftpfs $1 $2 -o $4,disable_eprt
 
</nowiki>}}
 
</nowiki>}}
   
Create the file {{ic|/sbin/umount.curl}} with this code:
+
以下の内容で {{ic|/sbin/umount.curl}} ファイルを作成
   
 
{{hc|/sbin/umount.curl|<nowiki>
 
{{hc|/sbin/umount.curl|<nowiki>
#! /bin/sh
+
#!/bin/sh
fusermount -u $1
+
fusermount -u $1
 
</nowiki>}}
 
</nowiki>}}
   
  +
両方のファイルのパーティションを設定:
Set the permissions for both files:
 
   
 
# chmod 755 /sbin/mount.curl
 
# chmod 755 /sbin/mount.curl
 
# chmod 755 /sbin/umount.curl
 
# chmod 755 /sbin/umount.curl
   
  +
再起動後 {{ic|/media/ftp/servername}} から FTP サーバーにアクセスできるようになっているはずです。
After a restart your new FTP server should be accessible through {{ic|/media/ftp/servername}}.
 
   
 
==== リモート SSH ====
 
==== リモート SSH ====
   
  +
以下は AutoFS を使って [[SSH]] 経由でリモートサーバーのファイルシステムにアクセスする手順です。
These are basic instructions to access a remote filesystem over [[SSH]] with AutoFS.
 
   
 
{{Note|パスワードを使わない認証は便利なだけでなくセキュリティ的に安全でもあります。詳しくは [[SSH 鍵]]を参照。}}
 
{{Note|パスワードを使わない認証は便利なだけでなくセキュリティ的に安全でもあります。詳しくは [[SSH 鍵]]を参照。}}
192行目: 199行目:
 
$ ssh-keygen
 
$ ssh-keygen
   
  +
パスフレーズが要求されたら、{{ic|ENTER}} を押してください。パスフレーズを設定しないで SSH 鍵を使用するのはセキュリティ的には問題がありますが、パスフレーズを設定して AutoFS を使うのは難しいためここでは避けます。
When the generator ask for a passphrase, just press {{ic|ENTER}}. Using SSH keys without a passphrase is less secure, yet running AutoFS together with passphrases poses some additional difficulties which are not (yet) covered in this article.
 
   
  +
そして、リモートの SSH サーバーに公開鍵をコピー:
Next, copy the public key to the remote SSH server:
 
 
$ ssh-copy-id username@remotehost
 
$ ssh-copy-id username@remotehost
   
  +
root で、パスワードを入力しなくてもリモートサーバーにログインできることを確認:
'''As root''', see that you can login to the remote server without entering a password:
 
 
# ssh username@remotehost
 
# ssh username@remotehost
   
{{Note|This will add the remote server to root's list of {{ic|known_hosts}}. Hosts can be also be manually added to {{ic|/etc/ssh/ssh_known_hosts}}.}}
+
{{Note|上記のコマンドで root {{ic|known_hosts}} リストにリモートサーバーが追加されます。ホストは手動で {{ic|/etc/ssh/ssh_known_hosts}} に追加することもできます。}}
   
Create a new entry for SSH servers in {{ic|/etc/autofs/auto.master}}:
+
{{ic|/etc/autofs/auto.master}} に SSH サーバーのエントリを作成:
 
/media/ssh /etc/autofs/auto.ssh --timeout=60
 
/media/ssh /etc/autofs/auto.ssh --timeout=60
   
Create the file {{ic|/etc/autofs/auto.ssh}} and add an SSH server:
+
{{ic|/etc/autofs/auto.ssh}} ファイルを作成して SSH サーバーを追加:
 
{{hc|/etc/autofs/auto.ssh|2=
 
{{hc|/etc/autofs/auto.ssh|2=
 
servername -fstype=fuse,rw,allow_other,IdentityFile=/home/username/.ssh/id_rsa :sshfs\#username@host\:/
 
servername -fstype=fuse,rw,allow_other,IdentityFile=/home/username/.ssh/id_rsa :sshfs\#username@host\:/
 
}}
 
}}
   
  +
再起動後 {{ic|/media/ssh/servername}} から SSH サーバーにアクセスできるようになっているはずです。
After a restart your SSH server should be accessible through {{ic|/media/ssh/servername}}.
 
   
 
== MTP ==
 
== MTP ==
238行目: 245行目:
 
=== 任意のパラメータ ===
 
=== 任意のパラメータ ===
   
You can set parameters like {{ic|timeout}} systemwide for all AutoFS media in {{ic|/etc/default/autofs}}:
+
{{ic|timeout}} などのパラメータは {{ic|/etc/default/autofs}} でシステム全体に適用するように設定できます:
   
 
* {{ic|/etc/default/autofs}} ファイルを開いて {{ic|OPTIONS}} 行を編集:
 
* {{ic|/etc/default/autofs}} ファイルを開いて {{ic|OPTIONS}} 行を編集:
 
OPTIONS='--timeout=5'
 
OPTIONS='--timeout=5'
   
  +
* ログ出力を有効にするには (デフォルトでは何もログが記録されません)、{{ic|/etc/default/autofs}} の {{ic|OPTIONS}} 行をアンコメントして {{ic|--verbose}} を追加してください:
* To enable logging (default is no logging at all), uncomment and add {{ic|--verbose}} to the {{ic|OPTIONS}} line in {{ic|/etc/default/autofs}} e.g.:
 
 
OPTIONS='--verbose --timeout=5'
 
OPTIONS='--verbose --timeout=5'
   
After restarting the {{ic|autofs}} daemon, verbose output is visible in {{ic|systemctl status}} or in {{ic|journalctl}}.
+
{{ic|autofs}} デーモンの再起動後、{{ic|systemctl status}} {{ic|journalctl}} でログが確認できるようになります。
   
 
=== 複数のデバイスを認識 ===
 
=== 複数のデバイスを認識 ===
   
USB ドライブ/スティックを複数使用する場合、AutoFS を使ってマウントポイントを設定して [[Udev]] で USB ドライブごとに名前を付けることができます。Udev ルールの設定方法については [[udev#固定デバイス名設定]] を見て下さい。
+
USB ドライブ/スティックを複数使用する場合、AutoFS を使ってマウントポイントを設定して [[Udev]] で USB ドライブごとに名前を付けることができます。Udev ルールの設定方法については [[udev#固定デバイス名設定する]] を見て下さい。
   
 
=== AutoFS のパーミッション ===
 
=== AutoFS のパーミッション ===

2023年12月28日 (木) 12:58時点における最新版

このドキュメントは AutoFS を設定する手順を解説しています。AutoFS はリムーバブルメディアやネットワーク共有などが接続されたりアクセスされたときに自動でマウントするパッケージです。

インストール

autofs パッケージをインストールしてください。

ノート: autofs4 モジュールをロードする必要はなくなりました。

設定

AutoFS ではテンプレートファイルを使って設定します。ファイルは /etc/autofs にあります。メインのテンプレートは auto.master で、メディアタイプに合わせて他のテンプレートを読み込むことができます。

  • お好きなエディタで /etc/autofs/auto.master ファイルを開いて下さい。以下のようになっているはずです:
/etc/autofs/auto.master
#/media /etc/autofs/auto.media

各行の最初の値はテンプレートのメディアをマウントするベースディレクトリです。2番目の値は使用するテンプレートです。デフォルトのベースパスは /media となっていますが、自由に変更できます。例:

/etc/autofs/auto.master
/media/misc     /etc/autofs/auto.misc     --timeout=5
/media/net      /etc/autofs/auto.net      --timeout=60
ノート: テンプレートファイルの末尾には改行が必要です (最後の単語の後に ENTER を押してください)。EOF (end of file) 行が存在しない場合、AutoFS デーモンは正しくロードされません。

timeout パラメータではディレクトリをアンマウントする秒数を設定します。

システム上にベースディレクトリが存在しなかった場合、作成されます。動的にメディアをロードするためにベースディレクトリはマウントされるため、autofs が動作している間、ベースディレクトリにもともとあった中身を閲覧することはできなくなります。使用中のディレクトリを間違って自動マウントしてしまったとしても、auto.master でディレクトリを変更して AutoFS を再起動することで元に戻せます。

動的にロードされたディレクトリがマウントされた後でも元あったファイルが使えるようにしたい場合、他のディレクトリ (例: /var/autofs/net) にマウントするようにするかソフトリンクを使ってください:

# ln -s /var/autofs/net/share_name /media/share_name

もしくは autofs でメディアを別のフォルダにマウントする場合:

/etc/autofs/auto.master
/-     /etc/autofs/auto.template
/etc/autofs/auto.template
/path/to/folder     -options :/device/path
/home/user/usbstick  -fstype=auto,async,nodev,nosuid,umask=000  :/dev/sdb1
ノート: 共有への接続が失われたときにリソースがロックされたままになるという問題が発生します。フォルダにアクセスしようとしたとき、プログラムは反応が返ってくるまでロックされ、接続が戻るか、プロセスを強制的に終了するまでアンマウントができません。この問題を緩和するには、共有に接続が常に可能な場合のみ使用するようにして、ホームフォルダなど頻繁に使用するフォルダでは使用しないようにしてください。
  • /etc/nsswitch.conf ファイルを開いて automount エントリを追加してください:
automount: files
  • テンプレートの設定が完了したら (下を参照)、root で autofs.service有効化・起動して AutoFS デーモンを起動してください。

これでデバイスにアクセスしたときに自動的にマウントされるようになります。アクセスしているかぎりはマウントされ続けます。

リムーバブルメディア

リムーバブルデバイスは空いているブロックデバイスのパスが割り当てられます。例えば、/dev/sd{a,b,c} が既に使われている場合、次にマウントされたリムーバブルメディアには /dev/sdd ブロックが与えられます。順番が定かでないブロックデバイスのパスに合わせてマウントポイントを割り当てる代わりに、リムーバブルメディアの UUID や PARTUUID をマップファイルで使用するという方法があります。

例えば、特定の USB ドライブを /mnt/black というパスにマウントするには、テンプレートファイルとマップファイルを以下のように設定:

/etc/autofs/auto.master
# master template file
/mnt     /etc/autofs/auto.mnt   # [options here]

マウントしたいパーティションの UUID を blkid を使って確認してから、マップファイルを生成:

 # _ID=$( blkid --output value --match-tag PARTUUID /dev/sdXY )
 # printf "%s %s\n" "black -fstype=auto :PARTUUID=" "${_ID}" >/etc/autofs/auto.mnt

NFS ネットワークマウント

AutoFS はリモートサーバー上の NFS 共有を自動で認識・マウントする新しい方法を提供しています (autofs5 で AutoFS のネットワークテンプレートは /etc/autofs/auto.net から削除されました)。自動認識によるネットワーク共有のマウントを有効にするには、以下を /etc/autofs/auto.master ファイルに追加してください:

/net -hosts --timeout=60
ノート: (/etc/hosts で IP アドレスに名前を付けるか DNS を使用して) ホストネームが解決できるようになっていること、そして nfs-utils がインストール・動作していることを確認してください。また、共有フォルダを閲覧するには RPC を有効にする必要があります (rpcbind.service起動有効化してください)。

例えば、リモートサーバーの名前が fileserver で NFS 共有の名前が /home/share の場合、以下のコマンドを実行するだけで共有にアクセスできます (サーバーのホストネームがディレクトリの名前になります):

# cd /net/fileserver/home/share
ノート: Please note that ghosting, i.e. automatically creating directory placeholders before mounting shares is enabled by default, although AutoFS installation notes claim to remove that option from /etc/conf.d/autofs in order to start the AutoFS daemon.

-hosts オプションは showmount コマンドと同じような仕組みでリモートの共有を認識します。以下のコマンドを実行することで共有ディレクトリを確認できます:

# showmount <servername> -e 

<servername> はあなたのサーバーの名前に置き換えてください。

NFS の手動設定

server_name の /srv/shared_dir という名前の NFS 共有を client_pc というコンピュータの /mnt/foo にマウントする場合、auto.master を編集して共有の設定ファイルを作成します (auto.server_name):

/etc/autofs/auto.master
/mnt   /etc/autofs/auto.server_name --timeout 60
/etc/autofs/auto.server_name
foo  -rw,soft,intr,rsize=8192,wsize=8192 server_name:/srv/shared_dir

Samba

単一の共有フォルダ

以下を /etc/autofs/auto.master に追加:

/media/[my_server] /etc/autofs/auto.[my_server] --timeout 60 --browse

--timeout はファイルシステムがアンマウントされるまでの待機時間を定義します。--browse オプションはネットワーク共有が使えなくなったときにタイムアウトを防ぐために各マウントポイントに空のフォルダを作成します。

そして /etc/autofs/auto.[my_server] ファイルを作成:

[any_name] -fstype=cifs,[other_options] ://[remote_server]/[remote_share_name]

other_options セクションに、共有で使用するユーザー名とパスワードを指定してください:

[any_name] -fstype=cifs,username=[username],password=[password],[other_options] ://[remote_server]/[remote_share_name]
ノート: $ などの文字はバックスラッシュでエスケープしてください。

複数の共有フォルダ

/etc/autofs/auto.[my_server] では複数の共有フォルダを指定することができます。例:

[any_name] -fstype=cifs,[other_options] /photos ://[remote_server]/photos /music ://[remote_server]/music /video ://[remote_server]/video

自動探索

/etc/autofs/auto.smb のコメントを見てください。

FTP と SSH (FUSE を使用)

リモートの FTP や SSH サーバーには FUSE (仮想ファイルシステムレイヤー) と AutoFS でシームレスにアクセスすることができます。

リモート FTP

まず、curlftpfs パッケージをインストールしてください。

fuse モジュールをロード:

# modprobe fuse

システムが起動するたびにモジュールがロードされるように /etc/modules-load.d/fuse.conf ファイルを作成して fuse と記述してください。

そして、/etc/autofs/auto.master に FTP サーバーのエントリを追加します:

/media/ftp        /etc/autofs/auto.ftp    --timeout=60

/etc/autofs/auto.ftp ファイルを作成して ftp://myuser:mypassword@host:port/path の形式でサーバーを追加してください:

servername -fstype=curl,rw,allow_other,nodev,nonempty,noatime    :ftp\://myuser\:mypassword\@remoteserver
ノート: Your passwords are plainly visible for anyone that can run df (only for mounted servers) or view the file /etc/autofs/auto.ftp.

セキュリティを高めたい場合 ~root/.netrc ファイルを作成することでパスワードを追加できます。パスワードは平文のテキストですが、600 にパーティションを設定すれば df コマンドで表示されなくなります。フォーマットは:

machine remoteserver  
login myuser
password mypassword

ユーザー名とパスワードを指定しない場合 /etc/autofs/auto.ftp に追加する行は以下のようになります:

servername -fstype=curl,allow_other    :ftp\://remoteserver

以下の内容で /sbin/mount.curl ファイルを作成:

/sbin/mount.curl
#!/bin/sh
curlftpfs $1 $2 -o $4,disable_eprt

以下の内容で /sbin/umount.curl ファイルを作成

/sbin/umount.curl
#!/bin/sh
fusermount -u $1

両方のファイルのパーティションを設定:

# chmod 755 /sbin/mount.curl
# chmod 755 /sbin/umount.curl

再起動後 /media/ftp/servername から FTP サーバーにアクセスできるようになっているはずです。

リモート SSH

以下は AutoFS を使って SSH 経由でリモートサーバーのファイルシステムにアクセスする手順です。

ノート: パスワードを使わない認証は便利なだけでなくセキュリティ的に安全でもあります。詳しくは SSH 鍵を参照。

sshfs パッケージをインストールしてください。

fuse モジュールをロード:

# modprobe fuse

システムが起動するたびにモジュールがロードされるように /etc/modules-load.d/fuse.conf ファイルを作成して fuse と記述してください。

openssh をインストールしてください。

SSH 鍵を生成:

$ ssh-keygen

パスフレーズが要求されたら、ENTER を押してください。パスフレーズを設定しないで SSH 鍵を使用するのはセキュリティ的には問題がありますが、パスフレーズを設定して AutoFS を使うのは難しいためここでは避けます。

そして、リモートの SSH サーバーに公開鍵をコピー:

$ ssh-copy-id username@remotehost

root で、パスワードを入力しなくてもリモートサーバーにログインできることを確認:

# ssh username@remotehost
ノート: 上記のコマンドで root の known_hosts リストにリモートサーバーが追加されます。ホストは手動で /etc/ssh/ssh_known_hosts に追加することもできます。

/etc/autofs/auto.master に SSH サーバーのエントリを作成:

/media/ssh		/etc/autofs/auto.ssh	--timeout=60

/etc/autofs/auto.ssh ファイルを作成して SSH サーバーを追加:

/etc/autofs/auto.ssh
servername     -fstype=fuse,rw,allow_other,IdentityFile=/home/username/.ssh/id_rsa :sshfs\#username@host\:/

再起動後 /media/ssh/servername から SSH サーバーにアクセスできるようになっているはずです。

MTP

Android デバイスでは Media Transfer Protocol (MTP) が使われます。

mtpfs パッケージをインストールしてください。

/etc/autofs/auto.misc に MTP デバイスのエントリを追加:

android -fstype=fuse,allow_other,umask=000     :mtpfs

トラブルシューティング

このセクションでは AutoFS に関するよくある問題の解決方法を載せています。

NIS を使用

AutoFS のバージョン 5.0.5 には NIS の高度なサポートが含まれています。AutoFS で NIS を使うには、/etc/autofs/auto.master でテンプレートの名前の前に yp: を追加してください:

/home   yp:auto_home    --timeout=60 
/sbtn   yp:auto_sbtn    --timeout=60
+auto.master

バージョン 5.0.5 以前の NIS を使っている場合、/etc/nsswitch.confnis を追加してください:

automount: files nis

任意のパラメータ

timeout などのパラメータは /etc/default/autofs でシステム全体に適用するように設定できます:

  • /etc/default/autofs ファイルを開いて OPTIONS 行を編集:
OPTIONS='--timeout=5'
  • ログ出力を有効にするには (デフォルトでは何もログが記録されません)、/etc/default/autofsOPTIONS 行をアンコメントして --verbose を追加してください:
OPTIONS='--verbose --timeout=5'

autofs デーモンの再起動後、systemctl statusjournalctl でログが確認できるようになります。

複数のデバイスを認識

USB ドライブ/スティックを複数使用する場合、AutoFS を使ってマウントポイントを設定して Udev で USB ドライブごとに名前を付けることができます。Udev ルールの設定方法については udev#固定デバイス名を設定する を見て下さい。

AutoFS のパーミッション

AutoFS が機能しない場合、テンプレートファイルのパーミッションが正しいことを確認してください。パーミッションが間違っていると AutoFS は起動しません。設定ファイルをバックアップしたときにファイルモードを保持してなかった場合に起こりえます。設定ファイルの正しいモードは以下の通りです:

  • 0644 - /etc/autofs/auto.master
  • 0644 - /etc/autofs/auto.media
  • 0644 - /etc/autofs/auto.misc
  • 0644 - /etc/conf.d/autofs

通常、スクリプト (先の auto.net など) には実行可能属性 (chmod a+x filename) が必要で、マウントのリストには必要ありません。

/var/log/daemon.log に以下のようなエラーが出力される場合、パーミッションに問題があります:

May  7 19:44:16 peterix automount[15218]: lookup(program): lookup for petr failed
May  7 19:44:16 peterix automount[15218]: failed to mount /media/cifs/petr

fusermount の問題

util-linux の特定のバージョンでは、"user=" オプションを使用しても autofs でマウントした fuse ファイルシステムドライブをアンマウントすることができません。次の URL を参照: http://fuse.996288.n3.nabble.com/Cannot-umount-as-non-root-user-anymore-tp689p697.html

自動マウントの問題のデバッグ

効率的にデバッグするために、フォアグラウンドで自動マウントを実行してみてください:

# systemctl stop autofs.service
# automount -f -v

もしくは、デバッグ情報をもっと表示させたい場合:

# automount -f --debug

AutoFS の代替

参照