简体   繁体   English

如何在Linux上附加安装

[英]how to mount additively on linux

I have been trying to mount directories in linux additively and fail to do so. 我一直试图以其他方式在linux中挂载目录,但没有这样做。 I have three directrories a, b and c. 我有三个目录a,b和c。 a contains file x, b contains file y and c contains file z. a包含文件x,b包含文件y,c包含文件z。 Now when i mount "a" and "b" into c and then open c there are only x and y present in "c". 现在,当我将“ a”和“ b”安装到c然后打开c时,“ c”中仅存在x和y。 when i mount a, b and c into c the directory c is empty and ls says permission denied. 当我将a,b和c装入c时,目录c为空,并且ls表示权限被拒绝。 i cannot also unmount c even with sudo. 即使使用sudo,我也无法卸载c。 What i want to do is to mount ab and c in one of them and be able to see xy and z all together. 我想要做的是将ab和c安装在其中一个中,并且能够一起看到xy和z。 is it possible or is there a solution to this problem please let me know. 是否可以解决此问题,请让我知道。

naveed@ubuntu:~$ mkdir /tmp/test1 /tmp/test2 /tmp/test3
naveed@ubuntu:~$ touch /tmp/test{1,2,3}/{a,b,c}
naveed@ubuntu:~$ rm /tmp/test1/{b,c}
naveed@ubuntu:~$ rm /tmp/test2/{a,c}
naveed@ubuntu:~$ rm /tmp/test3/{a,b}
naveed@ubuntu:~$ ls -al /tmp/test*/
/tmp/test1/:
total 16
drwxrwxr-x  2 naveed naveed  4096 Mar  9 15:00 .
drwxrwxrwt 11 root   root   12288 Mar  9 15:00 ..
-rw-rw-r--  1 naveed naveed     0 Mar  9 15:00 a

/tmp/test2/:
total 16
drwxrwxr-x  2 naveed naveed  4096 Mar  9 15:00 .
drwxrwxrwt 11 root   root   12288 Mar  9 15:00 ..
-rw-rw-r--  1 naveed naveed     0 Mar  9 15:00 b

/tmp/test3/:
total 16
drwxrwxr-x  2 naveed naveed  4096 Mar  9 15:00 .
drwxrwxrwt 11 root   root   12288 Mar  9 15:00 ..
-rw-rw-r--  1 naveed naveed     0 Mar  9 15:00 c
naveed@ubuntu:~$ sudo unionfs-fuse -o nonempty /tmp/test1=RO:/tmp/test2=RO:/tmp/test3=RO /tmp/test1/
naveed@ubuntu:~$ ls -al /tmp/test1 
ls: cannot access /tmp/test1: Permission denied
naveed@ubuntu:~$ sudo ls -al /tmp/test1 
#nothing shows up here 

This is really a SuperUser question, so I've flagged it as such. 这确实是一个超级用户问题,因此已将其标记出来。

If you're creating a unioned file system of multiple sources, then all the source locations need to be accessible by the user that's trying to access the directory. 如果要创建具有多个源的联合文件系统,则所有源位置都必须由尝试访问目录的用户访问。

Take for example: 举个例子:

$ mkdir a; touch a/a
$ mkdir b; touch b/b
$ mkdir c; touch c/c
$ mkdir join
$ ls join
drwxr-xr-x 4 petesh petesh 4096 Mar  9 10:25 a/
drwxr-xr-x 2 petesh petesh 4096 Mar  9 10:19 b/
drwxr-xr-x 2 petesh petesh 4096 Mar  9 10:20 c/
drwxr-xr-x 4 petesh petesh 4096 Mar  9 10:25 join/

$ sudo mount -t aufs -o br:(pwd)/a:(pwd)/b:(pwd)/c none (pwd)/join
$  ls join
a  b  c

ie we can see all the content. 即我们可以看到所有内容。

change the permissions on one of the folders - eg 更改其中一个文件夹的权限-例如

$ chmod u-rwx a

and now when we ls the join folder: 现在,当我们ls join文件夹时:

$ ls join
ls: cannot open directory join: Permission denied

ie all folders need to be accessible in order for the joined directory to be accessible. 也就是说,所有文件夹都必须是可访问的,以便可以访问加入的目录。

Make sure that the permissions are correct for accessing all the directories - the union file system enforces the permissions of the underlying directories, you can't bypass the OS's protection using this. 确保访问所有目录的权限均正确-联合文件系统强制执行基础目录的权限,您不能使用此权限绕过操作系统的保护。

Next, if we mount them all into one folder: 接下来,如果我们将它们全部装入一个文件夹中:

$ sudo mount -t aufs -o br:(pwd)/a:(pwd)/b:(pwd)/c none (pwd)/c
$ ls c
a  b  c

ie there's no issue mounting them all over one directory, making the mounted directory look different to the underlying directory. 也就是说,将它们全部安装在一个目录上没有问题,从而使安装的目录看起来与基础目录不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM