Original Problem
I have a file on one filesystem: /data/src/file
and I want to hard link it to: /home/user/proj/src/file
but /home
is on one disk, and /data
is on another so I get an error:
$ cd /home/user/proj/src
$ ln /data/src/file .
ln: failed to create hard link './file' => '/data/src/file': Invalid cross-device link
Okay, so I learned I can't hard link across devices. Makes sense.
Problem at hand
So I thought I'd get fancy and bind mount a src
folder that's on /data
's file system:
$ mkdir -p /data/other/src
$ cd /home/user/proj
$ sudo mount --bind /data/other/src src/
$ cd src
$ # (now we're technically on `/data`'s file system, right?)
$ ln /data/src/file .
ln: failed to create hard link './file' => '/data/src/file': Invalid cross-device link
Why does this still not work?
Workaround
I know I have this setup right because I can make the hard link as long as I'm in the "real" /data
directory instead of the bound one.
$ cd /data/other/src
$ ln /data/src/file .
$ # OK
$ cd /home/user/proj/src
$ ls -lh
total 35M
-rw------- 2 user user 35M Jul 17 22:22 file
$
Some System Info
$ uname -a
Linux <host> 4.10.0-24-generic #28-Ubuntu SMP Wed Jun 14 08:14:34 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
$ findmnt
.
.
.
├─/home /dev/sdb8 ext4 rw,relatime,data=ordered
│ └─/home/usr/proj/src /dev/sda2[/other/src]
│ ext4 rw,relatime,data=ordered
└─/data /dev/sda2 ext4 rw,relatime,data=ordered
$ mountpoint -d /data
8:2
$ mountpoint -d /home/usr/proj/src/
8:2
Note: I manually changed the file and directory names to make the situation more clear, so there may be a typo or two in the command readouts.
/data
I can access the inode from the bind mount directory, so either the bind mount must be on the same partition as/data
, or the hard link is working across devices, which should be illegal, but works anyway. What am I missing? – SO_fix_the_vote_sorting_bug Jul 22 '17 at 05:22