一般的には,たとえばCD-ROMメディアをドライブにセットしてファイルを参照するためには,次のようなマウント作業が必要となる。
| # mount /mnt/cdrom |
しかし,メディアを抜き取る際にもコマンド(umount)を実行しなければならず面倒な作業だと感じる人が多いだろう。
そこでおすすめなのが,autofsと呼ばれる自動的にマウントを行う機能(デーモン)を利用する方法だ。autofsは,定期的にドライブへメディアが差し込まれていないかを監視しているためコマンド実行をすることなく自動的にマウント作業を行ってくれる。
まず最初に,次のようにautofsがインストールされているかどうかを調べ,存在しない場合にはRPM(Red Hat系の場合)でインストールをしよう。
|
# ls /etc/rc.d/init.d/autofs ls: /etc/rc.d/init.d/autofs: No such file or directory # rpm -Uvh ftp://rpmfind.net/linux/redhat/6.2/en/os/i386/\ RedHat/RPMS/autofs-3.1.4-4.i386.rpm |
インストール後は,デーモンを起動実行すればすぐに有効になる。
|
# /etc/rc.d/init.d/autofs start Starting automounter: [ OK ] |
autofsの起動状態については,次の2つのファイル(/etc/auto.master,/etc/auto.misc)で設定されている。「/etc/auto.master」ファイルの最終行には,60秒のアイドル時間でアンマウントを行う設定がある。
|
# cat /etc/auto.master # $Id: auto.master,v 1.2 1997/10/06 21:52:03 hpa Exp $ # Sample auto.master file # Format of this file: # mountpoint map options # For details of the format look at autofs(8). /misc /etc/auto.misc --timeout 60 |
「/etc/auto.misc」ファイルには,対象とするデバイスが記述されている。標準設定では,CD-ROMのみが有効になっている点に注意が必要だ。フロッピーも有効にしたい場合には,下から4行目行頭のコメント「#」を削除すればよい。
|
# cat /etc/auto.misc # $Id: auto.misc,v 1.2 1997/10/06 21:52:04 hpa Exp $ # This is an automounter map and it has the following format # key [ -mount-options-separated-by-comma ] location # Details may be found in the autofs(5) manpage kernel -ro,soft,intr ftp.kernel.org:/pub/linux cd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom # the following entries are samples to pique your imagination #floppy -fstype=auto :/dev/fd0 #floppy -fstype=ext2 :/dev/fd0 #e2floppy -fstype=ext2 :/dev/fd0 #jaz -fstype=ext2 :/dev/sdc1 |
設定ファイルを編集した場合には,autofsを再起動することを忘れずに行おう。
|
# /etc/rc.d/init.d/autofs restart Checking for changes to /etc/auto.master .... |
Copyright © ITmedia, Inc. All Rights Reserved.