From 56fcf88f8a657e87de8c29d9baf5bfc2196c871b Mon Sep 17 00:00:00 2001 From: Eric Curtin Date: Sun, 18 Feb 2024 13:13:54 +0000 Subject: [PATCH] Rename initoverlayfs-setup to initoverlayfs This binary is going to have two modes: initoverlayfs --systemd which is the recommended one. And: initoverlayfs where we use initoverlayfs's built-in init system, this is for use-cases where we require high levels of optimization, such as in the Automotive use case, this requires storage drivers to be built directly into the kernel so the kernel can do storage initialization, this built-in initoverlayfs init system will not do udev type things, at least initially. Signed-off-by: Eric Curtin --- README.md | 12 ++++----- initoverlayfs-setup.c => initoverlayfs.c | 2 +- initoverlayfs-setup.h => initoverlayfs.h | 0 initoverlayfs.spec.in | 6 ++--- integration/tests/boot-validation/test.sh | 4 +-- .../modules.d/81initoverlayfs/module-setup.sh | 2 +- lib/systemd/system/pre-initoverlayfs.service | 2 +- scripts/build-bin-only.sh | 12 ++++----- scripts/build.sh | 26 +++++++++---------- 9 files changed, 33 insertions(+), 33 deletions(-) rename initoverlayfs-setup.c => initoverlayfs.c (99%) rename initoverlayfs-setup.h => initoverlayfs.h (100%) diff --git a/README.md b/README.md index 21f43a8..6f93bbc 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ fw -> bootloader -> kernel -> mini-initramfs --------------> initoverlayfs -> ro fw -> bootloader -> kernel -> init ------------------------------------------------> | - `-initoverlayfs-setup-+ + `-initoverlayfs-+ ``` # Why use initoverlayfs? @@ -45,7 +45,7 @@ Conversely, the initoverlayfs approach proposes a solution: dividing the initram This division entails segregating the initramfs image into two distinct components. -The first component (initramfs) contains init, kernel modules, udev-rules and an initoverlayfs-setup tool, responsible for setting up and mounting initoverlayfs. Then we switches to the second component (initoverlayfs), containing all additional kernel modules and essential files required to support the Linux boot process. +The first component (initramfs) contains init, kernel modules, udev-rules and an initoverlayfs tool, responsible for setting up and mounting initoverlayfs. Then we switches to the second component (initoverlayfs), containing all additional kernel modules and essential files required to support the Linux boot process. This scalable approach moves a significant portion on the initial filesystem content to initoverlayfs which is more scalable as it does on-demand decompression. @@ -196,10 +196,10 @@ To validate whether the new image has been successfully loaded after the reboot, # journalctl -b -o short-monotonic | grep -i initoverlayfs [ 4.949129] fedora systemd[1]: Queued start job for default target pre-initoverlayfs.target. [ 5.526459] fedora systemd[1]: Starting pre-initoverlayfs.service - pre-initoverlayfs initialization... -[ 9.179469] fedora initoverlayfs-setup[193]: bootfs: {"UUID=1a3a6db4-a7c2-43e5-bed5-9385f26c68ff", "bootfs UUID=1a3a6db4-a7c2-43e5-bed5-9385f26c68ff"}, bootfstype: {"ext4", "bootfstype ext4"}, fs: {"(null)", "(null)"}, fstype: {"(null)", "(null)"} -[ 9.179469] fedora initoverlayfs-setup[193]: fork_execlp("udevadm") -[ 9.179469] fedora initoverlayfs-setup[193]: forked 199 fork_execlp -[ 9.179469] fedora initoverlayfs-setup[193]: mount("/boot", "/initoverlayfs/boot", "ext4", MS_MOVE, NULL) 2 (No such file or directory) +[ 9.179469] fedora initoverlayfs[193]: bootfs: {"UUID=1a3a6db4-a7c2-43e5-bed5-9385f26c68ff", "bootfs UUID=1a3a6db4-a7c2-43e5-bed5-9385f26c68ff"}, bootfstype: {"ext4", "bootfstype ext4"}, fs: {"(null)", "(null)"}, fstype: {"(null)", "(null)"} +[ 9.179469] fedora initoverlayfs[193]: fork_execlp("udevadm") +[ 9.179469] fedora initoverlayfs[193]: forked 199 fork_execlp +[ 9.179469] fedora initoverlayfs[193]: mount("/boot", "/initoverlayfs/boot", "ext4", MS_MOVE, NULL) 2 (No such file or directory) [ 9.216158] fedora systemd[1]: Finished pre-initoverlayfs.service - pre-initoverlayfs initialization. [ 9.235546] fedora systemd[1]: Starting pre-initoverlayfs-switch-root.service - Switch Root pre-initoverlayfs... [ 12.207906] fedora systemd[1]: pre-initoverlayfs-switch-root.service: Deactivated successfully. diff --git a/initoverlayfs-setup.c b/initoverlayfs.c similarity index 99% rename from initoverlayfs-setup.c rename to initoverlayfs.c index 6b679ca..38b64ec 100644 --- a/initoverlayfs-setup.c +++ b/initoverlayfs.c @@ -2,7 +2,7 @@ #define _GNU_SOURCE #endif -#include "initoverlayfs-setup.h" +#include "initoverlayfs.h" #include #include #include diff --git a/initoverlayfs-setup.h b/initoverlayfs.h similarity index 100% rename from initoverlayfs-setup.h rename to initoverlayfs.h diff --git a/initoverlayfs.spec.in b/initoverlayfs.spec.in index 779d73e..05c686f 100644 --- a/initoverlayfs.spec.in +++ b/initoverlayfs.spec.in @@ -22,11 +22,11 @@ Requires: dracut %build RPM_OPT_FLAGS="${RPM_OPT_FLAGS/-flto=auto /}" -gcc ${RPM_OPT_FLAGS} initoverlayfs-setup.c -o initoverlayfs-setup +gcc ${RPM_OPT_FLAGS} initoverlayfs.c -o initoverlayfs %install install -D -m755 bin/initoverlayfs-install ${RPM_BUILD_ROOT}/%{_bindir}/initoverlayfs-install -install -D -m755 initoverlayfs-setup ${RPM_BUILD_ROOT}/%{_sbindir}/initoverlayfs-setup +install -D -m755 initoverlayfs ${RPM_BUILD_ROOT}/%{_sbindir}/initoverlayfs install -D -m755 lib/dracut/modules.d/81initoverlayfs/module-setup.sh ${RPM_BUILD_ROOT}/%{_prefix}/lib/dracut/modules.d/81initoverlayfs/module-setup.sh install -D -m644 lib/systemd/system/pre-initoverlayfs.target ${RPM_BUILD_ROOT}/%{_prefix}/lib/systemd/system/pre-initoverlayfs.target install -D -m644 lib/systemd/system/pre-initoverlayfs.service ${RPM_BUILD_ROOT}/%{_prefix}/lib/systemd/system/pre-initoverlayfs.service @@ -37,7 +37,7 @@ install -D -m644 lib/systemd/system/pre-initoverlayfs-switch-root.service ${RPM_ %doc README.md %attr(0755,root,root) %{_bindir}/initoverlayfs-install -%{_sbindir}/initoverlayfs-setup +%{_sbindir}/initoverlayfs %{_prefix}/lib/dracut/modules.d/81initoverlayfs/ %{_prefix}/lib/systemd/system/pre-initoverlayfs.target %{_prefix}/lib/systemd/system/pre-initoverlayfs.service diff --git a/integration/tests/boot-validation/test.sh b/integration/tests/boot-validation/test.sh index 671946d..d15f571 100755 --- a/integration/tests/boot-validation/test.sh +++ b/integration/tests/boot-validation/test.sh @@ -4,10 +4,10 @@ set -x if [ "${TMT_REBOOT_COUNT}" == "1" ];then echo -n "machine is up" - storage_init=$(journalctl -r | grep "init -> usr/sbin/initoverlayfs-setup" | tail -1) + storage_init=$(journalctl -r | grep "init -> usr/sbin/initoverlayfs" | tail -1) exit_code="$?" if [ "$exit_code" != "0" ]; then - echo -n "initoverlayfs, initoverlayfs-setup messages not found in journal" + echo -n "initoverlayfs, initoverlayfs messages not found in journal" exit "$exit_code" fi echo -n "initoverlayfs boot complete" diff --git a/lib/dracut/modules.d/81initoverlayfs/module-setup.sh b/lib/dracut/modules.d/81initoverlayfs/module-setup.sh index 12ea0be..dc98511 100644 --- a/lib/dracut/modules.d/81initoverlayfs/module-setup.sh +++ b/lib/dracut/modules.d/81initoverlayfs/module-setup.sh @@ -10,7 +10,7 @@ depends() { } install() { - inst_multiple -o /etc/initoverlayfs.conf /usr/sbin/initoverlayfs-setup \ + inst_multiple -o /etc/initoverlayfs.conf /usr/sbin/initoverlayfs \ "$systemdsystemunitdir/pre-initoverlayfs.target" \ "$systemdsystemunitdir/pre-initoverlayfs.service" \ "$systemdsystemunitdir/pre-initoverlayfs-switch-root.service" diff --git a/lib/systemd/system/pre-initoverlayfs.service b/lib/systemd/system/pre-initoverlayfs.service index 71ba9f4..a20ab6d 100644 --- a/lib/systemd/system/pre-initoverlayfs.service +++ b/lib/systemd/system/pre-initoverlayfs.service @@ -10,7 +10,7 @@ After=systemd-journald.service [Service] Type=oneshot -ExecStart=/usr/sbin/initoverlayfs-setup +ExecStart=/usr/sbin/initoverlayfs --systemd StandardInput=null StandardOutput=journal+console StandardError=journal+console diff --git a/scripts/build-bin-only.sh b/scripts/build-bin-only.sh index bafa76d..af6d985 100755 --- a/scripts/build-bin-only.sh +++ b/scripts/build-bin-only.sh @@ -2,18 +2,18 @@ set -ex -clang++ -o a -O3 -pedantic -fno-exceptions -fno-rtti -Wall -Wextra -Werror -Wno-write-strings -Wno-language-extension-token -Wno-deprecated -std=c++20 initoverlayfs-setup.c & -g++ -o b -O0 -ggdb -pedantic -fno-exceptions -fno-rtti -Wall -Wextra -Werror -Wno-write-strings -Wno-language-extension-token -std=c++20 initoverlayfs-setup.c & -clang -o c -O3 -pedantic -fno-exceptions -Wall -Wextra -Werror -Wno-language-extension-token initoverlayfs-setup.c & +clang++ -o a -O3 -pedantic -fno-exceptions -fno-rtti -Wall -Wextra -Werror -Wno-write-strings -Wno-language-extension-token -Wno-deprecated -std=c++20 initoverlayfs.c & +g++ -o b -O0 -ggdb -pedantic -fno-exceptions -fno-rtti -Wall -Wextra -Werror -Wno-write-strings -Wno-language-extension-token -std=c++20 initoverlayfs.c & +clang -o c -O3 -pedantic -fno-exceptions -Wall -Wextra -Werror -Wno-language-extension-token initoverlayfs.c & if [ -e /usr/lib/rpm/redhat/redhat-hardened-cc1 ]; then - gcc -O2 -fanalyzer -fno-exceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection initoverlayfs-setup.c -o d & + gcc -O2 -fanalyzer -fno-exceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection initoverlayfs.c -o d & else - gcc -O2 -fanalyzer -fno-exceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection initoverlayfs-setup.c -o d & + gcc -O2 -fanalyzer -fno-exceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection initoverlayfs.c -o d & fi wait -gcc -O0 -fno-exceptions -ggdb -pedantic -Wall -Wextra -Werror -fanalyzer initoverlayfs-setup.c +gcc -O0 -fno-exceptions -ggdb -pedantic -Wall -Wextra -Werror -fanalyzer initoverlayfs.c sudo valgrind ./a.out diff --git a/scripts/build.sh b/scripts/build.sh index ce3496e..cd97c8f 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -94,10 +94,10 @@ set -ex cd ~/git/initoverlayfs if [ "$2" = "initramfs" ]; then - sudo clang -O3 -pedantic -Wall -Wextra -Werror -Wno-language-extension-token initoverlayfs-setup.c -o /usr/sbin/initoverlayfs-setup - sudo gcc -O3 -pedantic -Wall -Wextra -Werror -Wno-language-extension-token -fanalyzer initoverlayfs-setup.c -o /usr/sbin/initoverlayfs-setup + sudo clang -O3 -pedantic -Wall -Wextra -Werror -Wno-language-extension-token initoverlayfs.c -o /usr/sbin/initoverlayfs + sudo gcc -O3 -pedantic -Wall -Wextra -Werror -Wno-language-extension-token -fanalyzer initoverlayfs.c -o /usr/sbin/initoverlayfs - sudo cp -r lib/dracut/modules.d/81initoverlayfs-setup /usr/lib/dracut/modules.d/ + sudo cp -r lib/dracut/modules.d/81initoverlayfs /usr/lib/dracut/modules.d/ sudo cp -r lib/dracut/modules.d/81kamoso /usr/lib/dracut/modules.d/ du -sh /boot/initramfs* sudo dd if=/dev/urandom of=/usr/bin/random-file count=1 bs="$1" @@ -110,14 +110,14 @@ fi UNLOCK_OVERLAYDIR="$DIR_TO_DUMP_INITRAMFS" extract_initrd_into_initoverlayfs sudo mkdir -p "$UNLOCK_OVERLAYDIR/upper" "$UNLOCK_OVERLAYDIR/work" -# sudo valgrind /usr/sbin/initoverlayfs-setup -# sudo ln -sf initoverlayfs-setup $DIR_TO_DUMP_INITRAMFS/usr/sbin/init -# sudo ln -sf usr/bin/initoverlayfs-setup $DIR_TO_DUMP_INITRAMFS/init +# sudo valgrind /usr/sbin/initoverlayfs +# sudo ln -sf initoverlayfs $DIR_TO_DUMP_INITRAMFS/usr/sbin/init +# sudo ln -sf usr/bin/initoverlayfs $DIR_TO_DUMP_INITRAMFS/init if [ $fs == "erofs" ]; then sudo mkfs."$fs" /boot/initoverlayfs-"$release".img /run/initoverlayfs/ fi #sudo losetup -fP /boot/initoverlayfs-"$release".img -# ln -s init /usr/sbin/initoverlayfs-setup +# ln -s init /usr/sbin/initoverlayfs initramfs=$(sudo ls /boot/initramfs-* | grep -v rescue | tail -n1) sudo du -sh "$initramfs" #sudo dracut -v -f --strip $initramfs -M @@ -129,14 +129,14 @@ sudo rm -rf /usr/lib/dracut/modules.d/*pre-initoverlayfs set -x -sudo clang -O3 -pedantic -Wall -Wextra -Werror -Wno-language-extension-token initoverlayfs-setup.c -o /usr/sbin/initoverlayfs-setup -sudo gcc -O3 -pedantic -Wall -Wextra -Werror -Wno-language-extension-token -fanalyzer initoverlayfs-setup.c -o /usr/sbin/initoverlayfs-setup -#sudo dracut $decompressor_dracut -v -m "kernel-modules udev-rules initoverlayfs-setupramfs" -f --strip -M -o "nss-softokn bash i18n kernel-modules-extra rootfs-block dracut-systemd usrmount base fs-lib shutdown systemd systemd-initrd" # systemd-initrd (req by systemd) +sudo clang -O3 -pedantic -Wall -Wextra -Werror -Wno-language-extension-token initoverlayfs.c -o /usr/sbin/initoverlayfs +sudo gcc -O3 -pedantic -Wall -Wextra -Werror -Wno-language-extension-token -fanalyzer initoverlayfs.c -o /usr/sbin/initoverlayfs +#sudo dracut $decompressor_dracut -v -m "kernel-modules udev-rules initoverlayfsramfs" -f --strip -M -o "nss-softokn bash i18n kernel-modules-extra rootfs-block dracut-systemd usrmount base fs-lib shutdown systemd systemd-initrd" # systemd-initrd (req by systemd) boot_partition=$(mount | grep "on /boot type" | awk '{print $1}') sudo /bin/bash -c "echo -e \"bootfs $boot_partition\nbootfstype ext4\n\" > /etc/initoverlayfs.conf" sudo dracut $decompressor_dracut -v -f --strip -M sudo du -sh /boot/initramfs* -sudo lsinitrd | grep "initoverlayfs-setup" +sudo lsinitrd | grep "initoverlayfs" sudo du -sh "$initramfs" # sed -i '/^initrd /d' /boot/loader/entries/9c03d22e1ec14ddaac4f0dabb884e434-$release.conf @@ -145,7 +145,7 @@ bls_file=$(sudo ls /boot/loader/entries/ | grep -v rescue | tail -n1) #uuid=$(grep "boot.*ext4" /etc/fstab | awk '{print $1}' | sed s/UUID=//g) #sudo sed -i '/boot.*ext4/d' /etc/fstab sudo systemctl daemon-reload -#sudo sed -i "s#options #options initoverlayfs=UUID=$uuid initoverlayfstype=ext4 rdinit=/usr/sbin/initoverlayfs-setup #g" /boot/loader/entries/$bls_file -#sudo sed -i "s#options #options initoverlayfs=$boot_partition initoverlayfstype=ext4 rdinit=/usr/sbin/initoverlayfs-setup #g" /boot/loader/entries/$bls_file +#sudo sed -i "s#options #options initoverlayfs=UUID=$uuid initoverlayfstype=ext4 rdinit=/usr/sbin/initoverlayfs #g" /boot/loader/entries/$bls_file +#sudo sed -i "s#options #options initoverlayfs=$boot_partition initoverlayfstype=ext4 rdinit=/usr/sbin/initoverlayfs #g" /boot/loader/entries/$bls_file sudo sed -i "s/ quiet/ console=ttyS0/g" /boot/loader/entries/$bls_file sudo cat /boot/loader/entries/$bls_file