我可以成功挂载ext4分区,问题是分区上的所有文件都归userid为1000的用户所有。在一台机器上,我的userid是1000,但在另一台机器上是1010。我的用户名在两台机器上都是一样的,但我意识到文件系统存储的是用户 ID,而不是用户名。
我可以使用以下内容更正文件所有权:
find /mnt/example -exec chown -h 1010 {} \;
Run Code Online (Sandbox Code Playgroud)
但是当我在另一台机器上安装这个外部驱动器时,我必须再次将文件所有权更正回 1000。
我想要的是给出mount一个选项,说将用户 ID 1000 映射到 1010,这样我就不必实际修改任何文件。有没有办法做到这一点?
小智 27
看一下bindfs包。bindfs 是一个 FUSE 文件系统,它允许在现有文件系统之上对文件权限、文件所有权等进行各种操作。
您正在专门寻找bindfs的--map 选项:
--map=user1/user2:@group1/@group2:..., -o map=...
Given a mapping user1/user2, all files owned by user1 are shown as owned by user2. When user2 creates files, they are chowned to user1 in the underlying directory. When files are chowned to user2, they are chowned to user1 in the underlying directory. Works similarly for groups.
A single user or group may appear no more than once on the left and once on the right of a slash in the list of mappings. Currently, the options --force-user, --force-group, --mirror, --create-for-*, --chown-* and --chgrp-* override the corresponding behavior of this option.
Requires mounting as root.
Run Code Online (Sandbox Code Playgroud)
因此,要将用户 ID 为 1001 的文件映射/mnt/wrong到/mnt/correct用户 ID 1234,请运行以下命令:
sudo bindfs --map=1001/1234 /mnt/wrong /mnt/correct
Run Code Online (Sandbox Code Playgroud)