使用者工具

網站工具


linux:autofs

AUTOFS自動掛載服務

通常掛載裝置除了手動mount,或寫在/etc/fstab上,但不免有顯得無太方便,不知道有沒有一種服務控制掛載裝置,當有需要掛載服務就自動動掛載起來存取裝置,若一段時間內,服務偵測到掛載的裝置沒有存取就自動卸載。就是這個autofs

AUTOFS 套件列表

/etc/auto.master
/etc/auto.master  -->主要設定檔
/etc/auto.misc
/etc/auto.net
/etc/auto.smb
/etc/autofs_ldap_auth.conf
/etc/rc.d/init.d/autofs  -->啟動檔
/etc/sysconfig/autofs 
~略

/etc/auto.master

/etc/auto.master語法
待偵測掛載點         掛載資料對應檔
/media  /etc/auto.media

掛載資料對應檔

vim /etc/auto.media
#內容格式
#掛載點名稱   掛載參數   欲掛載裝置
pc2     -fstype=cifs,rw,soft,intr,username=pc2,password=12345678        ://192.168.0.11/iso
linux          -ro,soft,intr           ftp.example.org:/pub/linux

掛載參數

  • -fstype 指定掛載裝置的檔案系統 預設沒指定表示 nfs
    1. -fstype=iso9660 #CD或ISO
    2. -fstype=cifs #網芳的檔案系統
  • rw 可讀寫
  • ro 唯讀
  • soft 假如無法連接遠端主機或是沒有回應,在一段時間過後就直接回報錯誤並不是重試. return an error and don't retry after the timeout period expired
  • intr autofs 允許我們使用 ctrl+C 去做中斷連接遠端的動作,為了防止連接設定錯誤建議使用這參數以中斷過長時間的遠端連接.
  • hard 假如無法連接遠端主機或是沒有回應,autofs 會不斷的嘗試去做連接直到遠端回應為止.
  • username 使用者名稱
  • password 密碼
  • bg 拿到背景
  • fg 拿到前景

啟動及測試

#/etc/init.d/autofs start
#cd /media/pc2
#df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       45G  7.5G   36G  18% /
tmpfs                1000M     0 1000M   0% /dev/shm
/dev/xvda1            485M   29M  431M   7% /boot
//192.168.0.11/iso/   293G  146G  148G  50% /media/pc2

參考資料

linux/autofs.txt · 上一次變更: 2013/07/06 01:28 (外部編輯)