我们可以在已安装的 Windows 共享上使用 Unix 硬链接吗?

我们可以在已安装的 Windows 共享上使用 Unix 硬链接吗?

ln命令可以在已挂载的 Windows 共享上创建硬链接,但cp -al失败了。这是预期的行为吗?我正尝试通过使用 、 和 来创建写时复制样式的备份,以节省cowdancer磁盘rsync空间cp -al

backupuser@lan0:/mnt/backup/share$ mkdir a
backupuser@lan0:/mnt/backup/share$ touch a/b
backupuser@lan0:/mnt/backup/share$ cp -al a x
cp: cannot create hard link `x/b' to `a/b': No such file or directory
backupuser@lan0:/mnt/backup/share$ mkdir x
mkdir: cannot create directory `x': File exists
backupuser@lan0:/mnt/backup/share$ ln a/b x/b
backupuser@lan0:/mnt/backup/share$ ls -l x
total 0
-rwxr-xr-x 0 backupuser backupuser 0 Dec 23 17:33 b

更新:ln实际上是创建副本而不是真正的链接

答案1

您是否正在运行 SAMBA 作为服务器?然后在“smb.conf”中查找“unix extensions”并启用它们。

https://www.samba.org/samba/docs/man/manpages-3/smb.conf.5.html#UNIXEXTENSIONS

启用“unix 扩展”后,SAMBA 支持硬链接、unix 所有权信息和文件和目录模式(又名权限)。

但是,此设置是全局设置。因此启用 unix 扩展会影响所有共享(这可能是也可能不是您想要的)。

答案2

我最近使用 Windows 10 Pro 作为服务器进行了测试。我的 Linux 系统运行的是 CentOS 7,截至今天,它附带了 Samba 4.4.4。硬链接运行良好,就像在本地文件系统上一样。

测试:

/mnt/f/tmp# mkdir a
/mnt/f/tmp# touch a/b
/mnt/f/tmp# cp -al a x
/mnt/f/tmp# stat a/b
  File: ‘a/b’
  Size: 0           Blocks: 0          IO Block: 16384  regular empty file
Device: 28h/40d Inode: 1688849861497214  Links: 2
Access: (0755/-rwxr-xr-x)  Uid: ( 1000/   yanli)   Gid: ( 1000/   yanli)
Context: system_u:object_r:cifs_t:s0
Access: 2017-05-17 14:31:43.564755100 -0700
Modify: 2017-05-17 14:31:43.564755100 -0700
Change: 2017-05-17 14:31:46.571727600 -0700
 Birth: -
/mnt/f/tmp# stat x/b
  File: ‘x/b’
  Size: 0           Blocks: 0          IO Block: 16384  regular empty file
Device: 28h/40d Inode: 1688849861497214  Links: 2
Access: (0755/-rwxr-xr-x)  Uid: ( 1000/   yanli)   Gid: ( 1000/   yanli)
Context: system_u:object_r:cifs_t:s0
Access: 2017-05-17 14:31:43.564755100 -0700
Modify: 2017-05-17 14:31:43.564755100 -0700
Change: 2017-05-17 14:31:46.571727600 -0700
 Birth: -
/mnt/f/tmp# echo something >a/b
/mnt/f/tmp# cat x/b
something
/mnt/f/tmp# mount | grep /mnt/f
//192.168.1.7/f on /mnt/f type cifs (rw,nosuid,nodev,noexec,relatime,vers=1.0,cache=strict,username=redacted,domain=REDACTED,uid=1000,forceuid,gid=1000,forcegid,addr=192.168.1.7,file_mode=0755,dir_mode=0755,nounix,serverino,mapposix,rsize=61440,wsize=65536,echo_interval=60,actimeo=1,user)

可以看到,文件a/bx/b有相同的 Inode 编号,说明它们是指向相同 Inode 的硬链接。更改一个文件的内容也会影响另一个文件。

ln也能正常工作。

没有使用特殊选项来挂载 CIFS;每个选项都是默认的。我在 Windows 方面也没有做任何特别的事情。这只是 Windows 10 Pro 的默认安装和一个简单的共享文件夹。

我尚不清楚该功能何时添加到 CIFS/Samba 客户端/Windows。OP 只说了“Windows 共享”,因此不清楚他/她运行的是哪个版本的 Windows/Samba。我希望我的回答可以帮助那些在 Windows 服务器支持的 CIFS 挂载共享上创建硬链接时遇到问题的人;您可以通过升级到 Windows 10 Pro 和至少 Samba 4.4.4 来解决问题(CentOS 并不以发布最闪亮和最新的代码而闻名)。

相关内容