如何自動掛載 unionfs-fuse 檔案系統?

如何自動掛載 unionfs-fuse 檔案系統?

我可以運行 shell 命令:

unionfs-fuse /changedata=RW:/immutedata=RO -o cow /data

這完全按照我想要的方式安裝檔案系統。現在我需要將其合併到自動安裝程式中,以便根據需要重新安裝。

我在 /etc/auto.misc 中嘗試過的內容:

/data -fstype=fuse,cow /changedata=RW:/immutedata=RO

當我執行 ls /data 時 automount --debug -f /etc/auto.master 會說什麼:

handle_packet: type = 5
handle_packet_missing_direct: token 19, name /data, request pid 6063
attempting to mount entry /data
lookup_mount: lookup(file): looking up /data
lookup_mount: lookup(file): /data -> -fstype=fuse,cow /changedata=RW:/immutedata=RO
parse_mount: parse(sun): expanded entry: -fstype=fuse,cow /changedata=RW:/immutedata=RO
parse_mount: parse(sun): gathered options: fstype=fuse,cow
parse_mount: parse(sun): dequote("/changedata=RW:/immutedata=RO") -> /changedata=RW:/immutedata=RO
parse_mapent: parse(sun): gathered options: fstype=fuse,cow
parse(sun): invalid location 
dev_ioctl_send_fail: token = 19
failed to mount /data

谷歌透露的資訊很少。關於此文件系統的合併,手冊頁相當空白。

也許我應該把它放在 /etc/fstab 中並要求用戶重新安裝?

答案1

我知道現在回答已經太晚了,但是將以下內容添加到 Ubuntu 中的 /etc/fstab 中是可行的,

/dir/A=RW:/dir/B=RO /dir/my-union fuse.unionfs-fuse allow_other,cow,use_ino  0   0

答案2

使用 autofs 自動掛載 unionfs

總長DR:建立以下條目/etc/auto.misc並將其包含在您的etc/auto.master(如下所述)中。

data    -fstype=fuse,cow,allow_other :unionfs\#/changedata=RW\:/immutedata=RO

獎金:在 nfs 自動掛載之上建立 unionfs 自動掛載(以說明如何正確配置 autofs)

使用 NFSv4 時,啟用 IMAPD/etc/default/nfs-common

NEED_IDMAPD=yes

如果您希望 autofs 始終為您的掛載建立目錄,請啟用 browser_mode/etc/autofs.conf

browse_mode = yes

現在到核心部分:在您/etc/auto.master新增以下行

# automount all nfs volumes under /nfs and misc filesystems under /mnt
/nfs   /etc/auto.nfs
/mnt   /etc/auto.misc

autofs 將掛載/etc/auto.nfsunder中指定的所有檔案系統/nfs/<mount>以及/etc/auto.miscunder中指定的所有檔案系統/mnt/<mount>

在我的文件中,/etc/auto.nfs我有以下(範例)條目:

# FileServer: nfs data configuration
data01 -fstype=nfs4,ro,soft,intr,rsize=8192,wsize=8192,nosuid,tcp,allow_other 192.168.3.100:/mnt/data01
data02 -fstype=nfs4,ro,soft,intr,rsize=8192,wsize=8192,nosuid,tcp,allow_other 192.168.3.100:/mnt/data02
data03 -fstype=nfs4,ro,soft,intr,rsize=8192,wsize=8192,nosuid,tcp,allow_other 192.168.3.100:/mnt/data03
data04 -fstype=nfs4,ro,soft,intr,rsize=8192,wsize=8192,nosuid,tcp,allow_other 192.168.3.100:/mnt/data04
data05 -fstype=nfs4,ro,soft,intr,rsize=8192,wsize=8192,nosuid,tcp,allow_other 192.168.3.100:/mnt/data05

在我的文件中,/etc/auto.misc我新增了以下 unionfs 條目

# unionfs mount of all /nfs/data* mounts into /mnt/data
data    -fstype=fuse,allow_other,use_ino,ro,noatime :unionfs\#/nfs/data01=RO\:/nfs/data02=RO\:/nfs/data03=RO\:/nfs/data04=RO\:/nfs/data05=RO

確保所有文件都有權限(必要時644調整)chown 644 /etc/auto.{nfs,misc}

然後就可以啟用autofs並重新啟動服務了。

# reload autofs to enable all shares
systemctl enable autofs
systemctl restart autofs

您現在應該能夠執行ls /mnt/data

相關內容