You are not logged in.
Hello folks
I apologize in advance if this question has already been asked and answered. I really searched everywhere, in the forum and through Google, and unfortunately I couldn't find an answer to this question.
I have found discussions on the subject, but the benefit, advantage, or effective difference has not really been addressed anywhere.
Hence my question: What is the difference between using the systemd hook instead of continuing with the configuration without systemd.
I have seen that the userspace loading time with the systemd hook has decreased a bit. But the loading time is basically irrelevant to me and I am more interested in what the advantage of the systemd-hook is.
Thanks for all the answers in advance
greeting
Offline
mkinitcpio supports 2 init systems for the initramfs stage : busybox and systemd .
https://wiki.archlinux.org/title/Mkinitcpio#HOOKS gives detailed info and has a useful table in section runtime hooks .
Personally I feel the initramfs stage is critical and I have more trust for that stage in busybox stability then in systemd stability.
Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.
clean chroot building not flexible enough ?
Try clean chroot manager by graysky
Offline
Thank you for your answer, my Arch-Brother. Of course i know and read the wiki page regarding Mkinitcpio. The information on this page helpful but there is no section advantages/disadvantages or effective/practical differences. I even read the dicussion to the wiki page.
At the moment i use: HOOKS=(base udev autodetect modconf block keymap encrypt lvm2 filesystems keyboard resume fsck shutdown) which seems to be absolutely perfect. I checked the systemd hook (the shell script) and understood what it is doing. But at the end there is no real better/worse. It looks like choose whatever your taste is.
Offline
One thing I know is that the sd-encrypt hook can do a bit more than the encrypt hook. And I believe you get an extra data point in systemd-analyze output and it might make the boot slightly faster (or slower
).
Offline
Initramfs is a concept. Kernel unpacks files [provided by bootloader or builtin] in a ramdisk/tmpfs and runs early userspace. What happens then is up to implementation.
There are countless initramfs implementations around. In Arch there is initcpio, or dracut, in Ubuntu it's initramfs-tools, in another distro it will be something else. You can make a custom initramfs entirely on your own if you like (I wrote a page on it in the Gentoo wiki when I was still using Gentoo). Systemd also has its own initrd mode, so systemd is many things and also its own initramfs implementation, in a way.
mkinitcpio is a script that builds initramfs images. It uses a hook system. But what does that mean?
There are install hooks (run at build time, e.g. to decide which files to include in the image) as well as runtime hooks (that actually run while booting and somehow use the files provided).
You can see this in /lib/initcpio/hooks/ (for runtime hooks) and /lib/initcpio/install/ (for build time hooks). Note systemd, sd-* hooks only exists in install/, not in hooks/.
Now, the default initcpio initramfs is a busybox based initramfs, which means it implements /init as a busybox shell script, which in turn has code to run these runtime hooks, which are themselves busybox shell scripts. And that's how initcpio implements initramfs.
If you use the systemd hook, what gets installed into the initramfs image is instead the systemd implementation of initramfs. The /init shell script is gone (/init is now systemd itself), also gone is the logic that runs any runtime hooks. With systemd, there are no hooks. Instead you get systemd services.
That's why things are confusing people: mkinitcpio, depending on configuration, generates two different implementations of initramfs. the initcpio one that runs hooks, and the systemd one that runs services. They're two different implementations that are not compatible with each other. You only get to use one.
You can set up a runtime hook in a systemd mkinitcpio config, the files will get installed, the runtime hook file will even be there, but the hook will not run because the script to run it is missing. So it will not work as expected. That's why when you're using systemd, you also have to use sd-encrypt hook. The encrypt hook will not run.
Which one should you use? As long as it works, it does not matter. One may be faster than the other, or support more features, or... I mainly use initcpio because I customize it with my own custom hooks, which I would have to do quite differently with the systemd version, so I'd rather not change it to systemd. If archlinux drops initcpio in favor of dracut, I might use that and customize it, or go back to custom initramfs.
In the end the initramfs only has a simple task. It has to mount your root filesystem. That's all. Depending on your installation, it may be able to mount it directly, or it might have to jump through hoops (to handle raid, lvm, encryption, network setup and network storage, or other things), but either way, once the root filesystem is mounted, the initramfs is done and the real init system takes over (this time, systemd, at least for a default arch install). The initramfs no longer really affects the running system any so there is no difference other than how the early boot process works in detail.
Last edited by frostschutz (2021-09-04 11:47:55)
Offline
Great and thank you for your extensive explanation.
Offline