A single inode number use to represent file in each file system. All hard links based upon inode number.
So linking across file system will lead into confusing references for UNIX or Linux. For example, consider following scenario
* File system: /home
* Directory: /home/vivek
* Hard link: /home/vivek/file2
* Original file: /home/vivek/file1
Now you create a hard link as follows:
$ touch file1
$ ln file1 file2
$ ls -l
Output:
-rw-r--r-- 2 vivek vivek 0 2006-01-30 13:28 file1 -rw-r--r-- 2 vivek vivek 0 2006-01-30 13:28 file2
Now just see inode of both file1 and file2:
$ ls -i file1
782263
$ ls -i file2
782263
As you can see inode number is same for hard link file called file2 in inode table under /home file system. Now if you try to create a hard link for /tmp file system it will lead to confusing references for UNIX or Linux file system. Is that a link no. 782263 in the /home or /tmp file system? To avoid this problem UNIX or Linux does not allow creating hard links across file system boundaries. Continue reading rest of the Understanding Linux file system series (this is part VII):
- Part I - Understanding Linux superblock
- Part II - Understanding Linux superblock
- Part III - An example of Surviving a Linux Filesystem Failures
- Part IV - Understanding filesystem Inodes
- Part V - Understanding filesystem directories
- Part VI - Understanding UNIX/Linux symbolic (soft) and hard links
- Part VII - Why isn't it possible to create hard links across file system boundaries?
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop












{ 13 comments… read them below or add one }
Hi,
I wants to know that where are the links store?,is it created automatically at the time of creating the new file?Is it store in the inode or special file created for directory?
what is different between the links and link count?
regard
Debakanata
this example was confusing
because you are using
the same name
for the files
and
for the paths
Answer is good but simply say “Another name to same file”with same inodes.
Your /tmp example above assumes that a novice-user already knows the difference between ‘filesystems’ . This term is used interchangeably and the meaning depends on the context where[how] it’s used.
/tmp above implies it’s on a different partition (and may be possibly another filesystem(ext2 rather than ext3(/home)).
Subtle meaning
1) A FSH – example all dir’s under ‘/’ on a single partition.
2) Different (logically grouped or part of entire hierarchy)dir’s under same partition ,different partition’s or on different type-of-filesystem(ext2[3],reiser etc).
Anyways, keep up the good work.
hi,
I need some clarification.
I am very clear that hard links points to same inode number.
==========================================================
Now if you try to create a hard link for /tmp file system it will lead to confusing references for UNIX or Linux file system. Is that a link no. 782263 in the /home or /tmp file system? To avoid this problem UNIX or Linux does not allow creating hard links across file system boundaries
======================================================
If i am trying to create hard link for /tmp file system.
For example:
$ cd /home/karan
$ touch sfile
$ ln sfile hfile
$ ls – ali
4489496 -rw-r–r– 3 karan karan 0 2008-12-19 13:41 hfile
4489496 -rw-r–r– 3 karan karan 0 2008-12-19 13:41 sfile
very clear till this part.
Do you meant to say that we cannot create hard links like the below?
$ ln sfile /tmp/hfile
If i misunderstood,please do clear me.
Thanks
Karan,
If the /tmp directory is on the same partition as where ‘sfile’ is, then you can hard link it. You can’t hard link across different partitions/disks. They’re different file systems, therefore the inodes differ on each partition.
Otherwise to say, the inode number will not and can not be unique across filesystems / servers / partitions.
Hope this helps.
Nanda
I was just wondering how I could make a link to a drive?
When I do
root@Ubuntu9:media > ln -s disk disk
it returns an error saying /media/disk already exists!
I know it exists I just want to make a link to it (shortcut),
I know it seems dumb/redundant to make a same name link in the same folder but I was trying to figure out why this disk does not mount?and thought it may help because the cdrom and other disks mount OK and they all have links in the /media!
when I do mount disk it returns the usual fstab nonsense. It (disk) ONLY come up when I use the GUI and go in My Computer, then it appears in the /media directory?
So I thought it has something to do with making a link?
thanks@!
In general we create softlink for sortcut, If you already have file or folder name on current directory, why do you want same name softlink, it does not make sense to have duplicate softlink or even hardlink on same folder or in otherwords, directory maintains filenames and it requires uniq names you can not have duplicate names for given file in same folder.
if you are planing to create softlink from different partition or folder, it should not cause any problem.
Look at following example, I am creating data.txt to data.txt it gives error but when I tried data.txt to data1.txt, it works fine.
ln -s data.txt data.txt
ln: creating symbolic link `data.txt’: File exists
ln -s data.txt data1.txt
ls -la data*.txt
lrwxrwxrwx 1 root root 8 2009-08-13 00:02 data1.txt -> data.txt
-rw-r–r– 1 root root 15 2009-08-12 23:53 data.txt
Hope this helps,
Babu Satasiya
Thanks Babu,
I used different name and it worked.
I was testing to see why this 60 Gig hard drive does not mount on ts own while th cdrom0 and floppy0 loaded no problem!?
Thanks!
I want know about u have create a hardlink that time delete man hardlink file. then u have access that file or not tell me please
with what Franklin put forth, go over the example again. When spanning multiple FS you may encounter duplicate inodes. On a single physical HD with multiple mount points most FS (that i know of) keep track of the data by drive. the inodes are created in a incremental fashion.
-Eric Peyser
I may date myself here —-but –Unix beyond the magic garden– was a great book. It had alot of internals. from FS and the internals to IPC and named/unnamed pipe info. It helped me to understand what was behind the screen. BTW article was great !!!!