Red Hat Training
A Red Hat training course is available for Red Hat Enterprise Linux
3.13. bind 掛載與檔案系統的掛載順序
當您使用
mount
指令的 bind
選項時,請確定檔案系統是以正確的順序掛載的。在以下範例中,/var/log/
目錄必須在執行 bind 掛載至 /tmp/
目錄之前,先被掛載。
# mount --bind /var/log /tmp
檔案系統的掛載順序是由以下準則來決定的:
- 一般來說,檔案系統的掛載順序是由
fstab
檔案裡的先後順序而定。例外情形是使用_netdev
旗標掛載的檔案系統,或擁有自己的init
script 之檔案系統。 - 擁有自己的
init
script 之檔案系統會在稍後的初始化過程中掛載,這會在fstab
檔案中的系統 - 使用
_netdev
旗標掛載的檔案系統,會在系統上的網路功能啟用後掛載。
如果您的配置需要 bind 掛載至 GFS2 檔案系統,您可以將
fstab
檔案排列如下:
- 掛載需要 bind 掛載的本地檔案系統。
- 以 bind 方式將 GFS2 檔案系統掛載至目錄
- 掛載 GFS2 檔案系統
如果您的配置需要使用 bind 的方式掛載本地目錄(或檔案系統)至一個 GFS2 檔案系統上,在
fstab
檔案裡以正確的順序列出檔案系統,才能正確地掛載,因為 GFS2 檔案系統會直到 GFS2 的 init
script 執行之後才能掛載。因此,您需要撰寫 init
script 來執行 bind 掛載,這樣 bind 掛載才會在 GFS2 檔案系統掛載之後行之。
以下 script 是自訂
init
script 的範例。這個 script 會 bind 掛載兩個目錄至 GFS2 檔案系統上的兩個目錄。在此範例中有一個現存的 GFS2 掛載點,位置是 /mnt/gfs2a
,會在 GFS2 init
script 執行時、叢集啟動後掛載。
在這範例 script 中,
chkconfig
敘述的值表示:
- 345 表示這個 script 會在 runlevel 3、4 與 5 執行時啟動
- 29 表示啟動時的優先順序,在這例子中,這個 script 會在開機時,GFS2 的
init
script 執行後啟動,啟動的優先順序為 26 - 73 是停止時的優先順序,在這例子裡 script 會在關機程序進行時、GFS2 script 之前停止,停止時的優先順序為 74
這啟動與停止的值表示您可以手動執行這些工作,方法是執行
service start
與 service stop
指令。舉例來說,如果這 script 的名稱是 fredwilma
,您可以執行 service fredwilma start
。
這個 script 應該放在
/etc/init.d
目錄裡,執行權限與其它在此目錄的檔案相同。您接下來可以執行 chkconfig on
指令,連結這個 script 到所指稱的 runlevel。舉例來說,如果這個 script 名為 fredwilma
,您就可以執行 chkconfig fredwilma on
。
#!/bin/bash # # chkconfig: 345 29 73 # description: mount/unmount my custom bind mounts onto a gfs2 subdirectory # # ### BEGIN INIT INFO # Provides: ### END INIT INFO . /etc/init.d/functions case "$1" in start) # In this example, fred and wilma want their home directories # bind-mounted over the gfs2 directory /mnt/gfs2a, which has # been mounted as /mnt/gfs2a mkdir -p /mnt/gfs2a/home/fred &> /dev/null mkdir -p /mnt/gfs2a/home/wilma &> /dev/null /bin/mount --bind /mnt/gfs2a/home/fred /home/fred /bin/mount --bind /mnt/gfs2a/home/wilma /home/wilma ;; stop) /bin/umount /mnt/gfs2a/home/fred /bin/umount /mnt/gfs2a/home/wilma ;; status) ;; restart) $0 stop $0 start ;; reload) $0 start ;; *) echo $"Usage: $0 {start|stop|restart|reload|status}" exit 1 esac exit 0