1

Say we have a partition called /dev/sda2, in order to use this partition, we have to mount it to some directory, for example we can mount it to the /mnt/sda2 directory.

Now say that Linux is installed on the /dev/sda1 partition, is it accurate to say that the Linux partition (/dev/sda1) is "mounted" to the "/" directory, or is using the term "mounting" in this situation not accurate?

  • Check /etc/fstab and /etc/mtab. You will find which device is configured to be mounted to / and which is currently mounted to /. The term "installed on /dev/sda1" is not clear enough to give an unambiguous answer since there are too many possible setups for installation. – Weijun Zhou Mar 21 at 7:36
  • It seems to me more like a philosophical question similar to chicken-egg problem:) Whether mounting a blockdevice to a / directory can be called mounting. Does the directory / even exist before mounting? – Jakub Jindra Mar 21 at 7:47
4

The root filesystem is a bit of a special case, as it is typically mounted by initramfs/initrd (in most major distributions) or the kernel (with no-initramfs kernel configurations, similar to how classic Unix systems did it) as part of the boot process, and cannot really be unmounted like any other filesystems.

But it is not wrong to say that "the root filesystem /dev/sda1 is mounted to /". I think some old Unix textbook said something like "the root filesystem is magically mounted to /", as the details of that special mount process are tricky and essentially only relevant to kernel developers working on the kernel start-up tasks.

When initramfs is being used, the initramfs image is mounted as / as the kernel starts up. The root filesystem is then mounted at some temporary location and /sbin/pivot_root tool (or the equivalent system call as part of some other distribution-specific tool) is used to switch the places of the initramfs and the real root filesystem with each other. Then the real init process is exec()ed from the real root filesystem, to free the last remaining open file handle to the initramfs, and then the initramfs can be unmounted and the RAM allocated to it freed.

It might be possible to use the same process again to switch from one root filesystem to another while the kernel technically keeps running, but in practice this is not usually very useful: you'll need to stop essentially all processes anyway to get all the open files on the old root filesystem closed, so that the old root filesystem can be unmounted after pivoting it. And when you get to that point, you're going to be effectively so far into the shutdown procedures that it will probably be simpler to just reboot. As a bonus, by rebooting in this situation, you'll get a positive proof that the boot works with the new root filesystem.

0

It is a special case. If there is no initrd / initramfs, the root filesystem is mounted by the kernel. The Linux kernel developers use this terminology. I see no reason to contradict them.

linux-v5.0/init/do_mounts.c#L533

I think it is also perfectly fine to describe an initrd / initramfs as mounting the root filesystem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.