0

I'm installing arch linux, and I've got my root partition in /dev/sda2. As I understand, this partition will now be my root, containing all the subdirectories /home, /usr, etc.

What's confusing to me is why we must mount the "root" to what seems to be the "root" during installation. E.g., arch linux has an installation step of: mount /dev/root_partition /mnt.

I understand we're mounting the partition to a directory in the fs of the installation media. But when we do genfstab, it specifies that the root partition will be mounted to "/".

This seems kind of recursive to me, in the sense we're mounting "root" to "root". Is there another fs that the kernel has or something? Does this have something to do with initramfs?

3 Answers 3

1

Modern linux boots from an initramfs. When in this boot environment, the "root" filesystem is the initramfs mounted at /.

As part of the boot process, the initramfs loads drivers and stuff, finds the real root filesystem, and mounts it on some subdirectory. Originally, at this point, chroot was used to change that subdirectory to / for future processes. Then linux added a system call that allows swapping the initramfs mount point with the subdirectory, so that the initramfs can then be unmounted and released from memory.

Somewhere in between, things like genfstab could be used to dynamically generate a new fstab reflecting the shifted mount points after the chroot. (I don't see this used outside of a dynamic cloud environment -- usually fstab is a static file listing what to mount, rather than what is currently mounted.)

4
  • Agree. In more detail, an intramfs file is loaded into memory, and part of that file is a compressed filesystem which becomes the initial root '/'. After some system initialization, the fstab in the initramfs (usually a copy of the actual fstab) is consulted, the "real" of final roofs (perhaps /dev/sdb2) is mounted, and then a very clever switch from the initramfs-root to the 'real' root is executed, and the memory for initramfs is deallocated.
    – stevea
    Commented Dec 21, 2023 at 1:30
  • Technically I think the initramfs could be a squashfs that doesn't need to be uncompressed to be mounted instead of a compressed cpio archive, but I'm not aware of any distro that does that, but they should.
    – user10489
    Commented Dec 21, 2023 at 5:48
  • NO. initramfs is a gzip'ed cpio archive which is expanded (decompressed and de-archived) into a ramfs (specifically 'rootfs') filesystem. This is described in the kernel docs. The ungzip and cpio-i features are built into the kernel and not external programs.
    – stevea
    Commented Dec 28, 2023 at 11:22
  • @stevea : Correct, I agree with all that, but I think it might support a squashfs too. All the pieces for it are certainly in place, it just needs to check the format, and if I recall correctly, it wasn't always a gzip'ed cpio.
    – user10489
    Commented Dec 28, 2023 at 12:49
0

No, this has nothing to do with initramfs.

File system is a file system. You can mount it anywhere, in multiple locations or nowhere. In your current linux (I guess its your live installer archlinux) the file system of /dev/sda2 is mounted under /mnt. But when installation is complete and you reboot, it will be mounted at / (root).

1
  • The reason you want an entry in fstab for root "/" is b/c it is typically mounted by initramfs using that very entry & options. If you direct-boot a partition rather than use initramfs, then you can skip this entry, but you must build the filesystem support into the boot-kernel (cannot by a dynamic kernel module).
    – stevea
    Commented Dec 21, 2023 at 1:35
0

There's no such thing as root partition. It's just a partition you choose to mount as /.

Seems to me that we shouldn't need to mount root partition at all, since it contains the entire file system?

The kernel by default doesn't mount anything, it has no clue and it's not its business to figure out where your desired root FS it.

The partition mounted at /, i.e. the partition hosting the root directory, is commonly referred to as the "root partition".

That's just a calling convention. There may be a "root partition", "exfat partition" or any number of "SWAP partitions".

3
  • 2
    The partition mounted at /, i.e. the partition hosting the root directory, is commonly referred to as the "root partition". The OP didn't write "root partition", they wrote "root partition", and just mean /, the root partition.
    – terdon
    Commented Dec 17, 2023 at 21:56
  • Right so why are we mounting the partition containing root at /? It seems recursive to me. Seems to me that we shouldn't need to mount root partition at all, since it contains the entire file system?
    – vw1262
    Commented Dec 18, 2023 at 4:03
  • @vw1262 whatever is mounted at / is by definition the root partition. A "root partition" only makes sense in context of some root that it gets mounted on to. (So, for some OS installation on a system, partition X maybe the root partition because it gets mounted at / for that OS, and partition Y maybe the root partition for some other OS installed on that same system because it gets mounted at / for this other OS).
    – muru
    Commented Dec 18, 2023 at 6:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .