2

From systemd/fstab-generator.c it follows that systemd treats root= as required kernel parameter, the only configuration source for /sysroot mount. However from kernel/init/main.c and kernel/init/do_mounts.c it is not clear if that is so. Question: how can one do kernel init without 'root=' parameter (and tell systemd to support it)?

See: https://github.com/systemd/systemd/issues/3551

1

In do_mounts.c, the variable saved_root_name is set to the value of the root= command line parameter, if present. This value is a path-like string passed by the kernel, it typically looks like /dev/something (though the /dev/ prefix is optional) but it doesn't actually correspond to any on-disk path. If the root= parameter is absent, the value of ROOT_DEV is used; this is normally 0 but a different value can be injected in the system binary. The util-linux toolchain used to include a utility called `rdev to do this (on x86 only) but it disappeared a few years ago.

All of this happens only if the initramfs or initrd hasn't taken care of mounting the root (initramfs by running /init which is supposed to call mount, initrd by calling pivot_root).

I don't know about the systemd part. There isn't much that systemd can do about the root filesystem anyway apart from mounting it read-write.

7
  • just to clarify: in scenario when : 1) parameter root= is missing, and 2) using initramfs with /init, then options are : 3) either the /init process must mount actual /sysroot as r/w to the ROOT_DEV (which is defined at kernel build time as major:minor=0:0), or : 4) /init can set ROOT_DEV in the live kernel to point to the actual /sysroot, and : 5) there are no tools available for the /init to actually set ROOT_DEV value for #4. correct? finally : 6) are there tools which allow /init to read ROOT_DEV value from the live kernel for #3? Jun 15 '16 at 12:46
  • @AndreiPozolotin ROOT_DEV can't be set at runtime, it can only be set in the kernel image on disk. I don't think it can be read either. If there's a /init on the initramfs, ROOT_DEV isn't used anyway. Jun 15 '16 at 13:04
  • you mean that in scenario #1 / #2 : /init need only discover/prepare actual /sysroot, then switch_root form initramfs root / to the actual /sysroot , and kernel is not involved in rootfs setup via do_mounts.c / ROOT_DEV at all? Jun 15 '16 at 13:23
  • @AndreiPozolotin Yes: prepare_namespace is called only if there is no /init on the initramfs. Jun 15 '16 at 16:57
  • 2
    @Gilles how did you get a kernel to boot without a root= parameter? In theory, if I pass it initrd=, I should be exempt from a root=, but the kernel complains that it is required.
    – deitch
    Aug 11 '17 at 12:58

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.