Why Linux boots with multiple teeth initialized for root "/"

I am playing around with Linux kernel code, especially the filesystem part. I found that when the kernel boots up, multiple dentry objects are allocated for the root "/" directory. Why dose it to allocate multiple copies of the root directory in RAM? Moreover, since it seems like dcache (a cache pin is essentially a large hash table) uses the hash function H (parent_dentry_address, name_hash) to compute the bucket that dentis resisted. Does this mean that each root dentry "/" makes different dentry mappings to the hash bucket in dcache?

Btw, the above behaviors have been observed on Linux-3.3.0-rc4.


source to share

3 answers

I'm going to close my eyes and not look at any code and just yell out, maybe this could be the result of installing /

on top /

and more than once?

If you put something on top /

, then the underlyling /

cannot just disappear, because it can be opened with umount.



Read the documentation /initrd.txt from the kernel source to see what happens at boot:

When using initrd, the system typically boots as follows:

  1) the boot loader loads the kernel and the initial RAM disk
  2) the kernel converts initrd into a "normal" RAM disk and
     frees the memory used by initrd
  3) if the root device is not /dev/ram0, the old (deprecated)
     change_root procedure is followed. see the "Obsolete root change
     mechanism" section below.
  4) root device is mounted. if it is /dev/ram0, the initrd image is
     then mounted as root
  5) /sbin/init is executed (this can be any valid executable, including
     shell scripts; it is run with uid 0 and can do basically everything
     init can do).
  6) init mounts the "real" root file system
  7) init places the root file system at the root directory using the
     pivot_root system call
  8) init execs the /sbin/init on the new root filesystem, performing
     the usual boot sequence
  9) the initrd file system is removed

Note that changing the root directory does not involve unmounting it.
It is therefore possible to leave processes running on initrd during that
procedure. Also note that file systems mounted under initrd continue to
be accessible.


I hope this answers the question why the kernel allocates multiple teeth for "/"



There are two types of '/' in the kernel, one for the root of the process and the other for the root of the filesystem.

When a filesystem register is mounted, it will first select the root mount dentia as the entry to that filesystem, usually this twine uses the name /. name. RAM fs like proc / devtmpfs ... mounted inner core, so there will be multiple dentitions with the same name '/..//p>



All Articles