When I wanted to create a hard link in my /home
directory in root mode, Linux showed the following error message:
ln: failed to create hard link ‘my_sdb’ => ‘/dev/sda1’: Invalid cross-device link
The above error message is shown below:
# cd /home/user/
# ln /dev/sda1 my_sdb
But I could only create a hard link in the /dev
directory, and it was not possible in other directories.
Now, I want to know how to create a hard link from an existing device file (like sdb1
) in /home
directory (or other directories) ?
Best Answer
As shown by the error message, it is not possible to create a hard link across different filesystems; you can create only soft (symbolic) links.
For instance, if your
/home
is in a different partition than your root partition, you won't be able to hard link/tmp/foo
to/home/user/
.Now, as @RichardNeumann pointed out,
/dev
is usually mounted as a devtmpfs filesystem. See this example:Therefore you can only create hard links to files in
/dev
within/dev
.