2

I have a really basic doubt, which part creates all these directories, where is this configuration of creating directories stored while installing a new OS?

What is the order in which these directories are created? Are they created after /boot has been mounted by the kernel, by which part of the kernel?

MC68020
  • 6,281
  • 2
  • 13
  • 44
Vyom Yadav
  • 123
  • 5
  • Please [edit] your question and clarify what directories. If you mean the ones from the title, please include them in the actual question, but more importantly, note that `/dev/` is a completely different thing to `/bin` but neither is created on boot. The _contents_ of `/dev/` and `/proc` and `/sys` are created on boot or while the system is working, but not the directories themselves. And are you asking about system installation or normal system use? Basically, please [edit] your question and clarify what you are asking. – terdon Dec 15 '22 at 18:15
  • I find [this video](https://www.youtube.com/watch?v=BBUPc0aO5lw) does an OK job of explaining the whole boot process – Jaromanda X Dec 15 '22 at 21:24

1 Answers1

3

The root filesystem is mounted first (readonly) at bootime, as your bootlog could tell you :

[kernel] [    2.242830] VFS: Mounted root (ext4 filesystem) readonly on device 8:24.

It will then be remounted at init time :

[kernel] [    2.266181] Run /sbin/init as init process
...
[kernel] [    6.882156] EXT4-fs (sdb8): re-mounted. Opts: (null)
[kernel] [    6.882160] ext4 filesystem being remounted at /

From there incidentally populating with (at the very least) all standard base directories (/bin, /usr, /dev, /etc…) possibly empty, possibly serving as mountpoints on which, still as part of the init process…

other disk filesystems will be mounted following /etc/fstab directives :

[kernel] [    7.155270] EXT4-fs (sdb9): mounted filesystem with writeback data mode. Opts: data=writeback,commit=120
[kernel] [    7.155274] ext4 filesystem being mounted at /var
[kernel] [    7.222851] EXT4-fs (sdb10): mounted filesystem with writeback data mode. Opts: data=writeback
[kernel] [    7.222855] ext4 filesystem being mounted at /home

This as a successful result of some init service (e.g. localmount in openrc), incidentally populating every standard directory of any *x sytem as well as possibly… even more.

BTW, since the kernel does not need /boot filesystem it might well never be mounted. It just can be, at init time, depending on /etc/fstab entries.

Network File Systems can (v.g. not necessarily) be mounted as well at init time, in a way depending on the init system (e.g. netmount service in openrc) taking care network services will have been successfully launched before as an obvious prerequisite.

Special file systems (procfs / sysfs / configfs or other virtual? pseudo? filesystems presenting non-file elements of an operating system as files) will, depending on appropriate CONFIG_* kernel tuneables be mounted at init time, depending on the init system (e.g. execution of /lib/rc/sh/init.sh for openrc) and being consequently automomagically populated.

Temporary File Systems (data is stored in volatile memory instead of a persistent storage device) can also be mounted at init time following directives found in /etc/fstab e.g.

tmpfs  /tmp  tmpfs   rw,nosuid,noatime,nodev,size=4G,mode=1777

/dev particular case :

The /dev directory exists as per / mount together with two nodes the kernel needs at early boot time : /dev/console and /dev/null.
The kernel will add new nodes into /dev directory at boot time following devices' enumeration.
If the kernel is configured to enable temporary file systems, the nodes won't be created in the root partition :
The kernel will first mount an empty temporary file system on the /dev directory, overlaying its content.

[kernel] [    2.262470] devtmpfs: mounted

Hence allowing the devices to be created dynamically into that filesystem as they are detected (or accessed).

Of course, Linux being a plug&play OS, the population is subject to change at runtime.

MC68020
  • 6,281
  • 2
  • 13
  • 44