0

In my Ubuntu 12.04, /home and / are different partitions. But why does /home look like a subdirectory of /?

Is it because it is a hard link:

Are there five hard links which link to the same dir as /home?

$ ls -l /home
drwxr-xr-x   5 root     root      4096 Apr 19  2012 home

How can I show all the hard links for /home?

Tim
  • 101,790
  • http://unix.stackexchange.com/questions/31073/how-to-find-all-the-links-to-a-directory – Mat Oct 02 '14 at 17:47
  • I'm a bit confused about your question "why does /home look like a subdir of /" - why wouldn't it? – Mat Oct 02 '14 at 17:48
  • (1) can a parent dir and a child dir be different partitions? (2) How can you list all the hard links for /home then? – Tim Oct 02 '14 at 17:51
  • (2): see comment 1; (1): yes. That's kind of the whole point of mount points. – Mat Oct 02 '14 at 17:53
  • (2) but your answer there doesn't given a way to find all the other hard links from one. – Tim Oct 02 '14 at 18:00
  • What "all other"? – Mat Oct 02 '14 at 18:01

4 Answers4

3

In your Ubuntu 12.04, "/" and "/home" are mounted under different partitions.

The mount command will show you the structure of your partition mounting. These are not accomplished by hard links. These are mount points.

Linux Directory Structure Map

Mount Manual

umount manual

FSTab Manual

The FSTab is where you system gets/sets static mount points for your Linux directory structure.

ls -l is the long-form output of directory listing.

The bit you are asking about is the number of links to the file. Yes, I believe that if we are talking about "links," there are "5" hard links to the home directory.

  • (1) What does 5 mean in drwxr-xr-x 5 root root 4096 Apr 19 2012 home? (2) a directory and a subdirectory of it can be different partitions? – Tim Oct 02 '14 at 17:38
  • 1
    (2) a filesystem is made up of a collection of one or more partitions. Partitions are attached (mounted) into the filesystem. Thus they become subdirectories of the pre-existing directories. – hymie Oct 02 '14 at 19:42
2

In my Ubuntu 12.04, /home and / are different partitions. But why does /home look like a subdirectory of /?

Partitions and directory structure are two completely separate things. One has nothing to do with the other. /home is a subdirectory of /.

How can I show all the hard links for /home?

I don't believe that there is any easy command to show the files linked to a specific file. In theory, you should be able to use /bin/ls -ldi /home to get the inode number, followed by find . -inum xxxx -print, but I can't seem to get that to work on my home machine right now. But in this particular case, I would start with /bin/ls -aldi /home/*/..

hymie
  • 1,710
1

-Yeah, you see any partitions independently of what the name is a sub-partition "Root - / " because it is the primary partition of the system it is the whole system, hence the name "root" starts as a tree that starts at the root, the same occurs in the system, only it is not for this that also have other partitions starting or being present on the same disk, is very common in a little more complex systems and sensitive data is devote exclusive separate partitions on other disks just for security and "backup", so do not be surprised that, ok!

Joke Sr. OK
  • 903
  • 1
  • 8
  • 11
1

Suppose that there are five hard links for /home. The five hard links are /home/., /home/.., and for the three subdirs s of /home /home/s/... Note that if /home is on its own partition, then the references to /home/.. and /home/. are identical, however /home/.. is nonetheless evaluated to /. This is because every directory has entries for . and .., even a root directory. If instead /home were a plain subdirectory of /, then /home had still five hard links since now /home (as a directory entry of /) points to /home.

Final note: yes, it is possible to hard link a directory to another directory, but only root can do that for a good reason: the file system tree must not contain cycles.

countermode
  • 7,533
  • 5
  • 31
  • 58