Devices can be mounted to a path. For example "/dev/sda1" can be mounted to "/home/user". What I don't understand is how and where the " / " is mounted during boot. Any help explaining?
During the boot of a Unix system, the kernel does a few things that it doesn't do during normal operation. One of these things is to mount a filesystem on the directory
/; this is quite different from normal mounting operations since the mounting is not triggered of a
mount system call, and the target directory is not an existing directory. Another thing is to execute a program as PID 1, which is different from normal operation since this creates a process without duplicating an existing process.
The way this “magic” mounting of the root directory is very different in different Unix variants. The kernel chooses what device to mount based on configuration parameters that may be specified in a variety of ways: compile-time configuration, runtime configuration in the kernel image, runtime configuration in some predefined memory location, command line parameters, … To find how it works on your machine, you would need to look at the documentation of your Unix variant, and find how your machine is configured.
To give an idea of how it works, here's an overview of how a modern Linux kernel operates. This is not the simplest example because Linux has a lot of history and varied use cases.
- Linux can start with a “special” filesystem attached to the path
/, which consists of files stored in RAM. This special filesystem is called initramfs; it's an instance of the rootfs filesystem type. The initramfs is populated by content either passed by the bootloader through an architecture-dependent protocol, compiled directly into the kernel image that is loaded into memory by the bootloader.
- Alternatively, Linux can mount a device to
/that is part of a restricted (but large) set of volume types that are recognized by the initialization code in the kernel. Such device types include any filesystem on common types of partitions on common types of disks (anything vaguely SCSI-like, including ATA, USB, etc.), as well as RAM disks and NFS mounts.
- Depending on which path was taken, the initial root filesystem may later be shadowed or replaced by another. Shadowing is what happens with an initramfs, and that's how most desktop and server systems operate (embedded systems, on the other hand, often have a hard-coded root filesystem). Replacement is what happens with an initrd, which is a particular kind of RAM disk. The job of the initramfs or initrd is to load the drivers that provide the “real” root filesystem that will get used in normal operation.
This is from the
bootup(7) manual on an Ubuntu machine:
A number of different components are involved in the system boot. Immediately after power-up, the system BIOS will do minimal hardware initialization, and hand control over to a boot loader stored on a persistent storage device. This boot loader will then invoke an OS kernel from disk (or the network). In the Linux case, this kernel (optionally) extracts and executes an initial RAM disk image (
initrd), such as generated by
dracut(8), which looks for the root file system (possibly using
systemd(1)for this). After the root file system is found and mounted, the
initrdhands over control to the host's system manager (such as
systemd(1)) stored on the OS image, which is then responsible for probing all remaining hardware, mounting all necessary file systems and spawning all configured services.
You would have found this by
man boot, reading it and not finding the answer, but seeing "See also:
bootup(7)" at the bottom of the manual.
Being curious, I then looked at the manual for
In the first boot-up phase, the kernel starts up and mounts an initial root filesystem from the contents of
/dev/initrd(e.g., RAM disk initialized by the boot loader). In the second phase, additional drivers or other modules are loaded from the initial root device's contents. After loading the additional modules, a new root filesystem (i.e., the normal root filesystem) is mounted from a different device.