Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 593866 - sys-kernel/genkernel: initrd cdupdate.sh script not executed since v3.4.52
Summary: sys-kernel/genkernel: initrd cdupdate.sh script not executed since v3.4.52
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Hosted Projects
Classification: Unclassified
Component: genkernel (show other bugs)
Hardware: All Linux
: Normal normal with 2 votes (vote)
Assignee: Gentoo Genkernel Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-15 09:17 UTC by JY
Modified: 2021-07-31 15:50 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description JY 2016-09-15 09:17:28 UTC
In livecd mode, the genkernel initrd init script used to execute cdupdate.sh script before switching root.

Since 3.4.52 and commit 5070080b5bef3ee5c0231f11833f227e3e055520, the command :

mount --move "$CDROOT_PATH" "$NEW_ROOT$CDROOT_PATH"

is executed,  instead of mount --bind, but the cdupdate function called after the move still looks for cdupdate.sh script in the old path :

if [ -x /${CDROOT_PATH}/cdupdate.sh ]




Reproducible: Always

Steps to Reproduce:
1. Get a recent (2016) minimal install livecd
2. drop a cdupdate.sh script in the livecd/liveusb rootdir doing some echo "Hello World"
3. Boot the livecd


Actual Results:  
No cdupdate.sh script found, skipping...

Expected Results:  
Running cdupdate.sh
Hello World
Comment 1 Christian Nilsson 2017-07-24 19:54:54 UTC
This just bit me today (are no one else using cdupdate.sh since it seems to have been broken for so long?)

Downloaded install-amd64-minimal-20170720.iso
Modified it to add usual cdupdate script, and no go.
After a few hours of trying to figure out what is going on I finally found the mount --move part which in turn then lead me here.

JY already provided a simple testcase, but will add my scenario as well since some other things seems to have changed which might cause my usecase to not work even after fix.

To reproduce my issue,
* download this git repo: https://github.com/ASoft-se/Gentoo-HAI
* run sh get_minimal_cd.sh (to download the latest iso)
* run sh gentoocd_unpack.sh auto (this will ask for root, unpack iso and squashfs add some files including the gentoo_cdupdate.sh as cdupdate.sh and then repack everything, and finally start a vm to test it out.

When it runs the livecd it should automatically start installation in the vm
but instead it just ends up in the prompt.
Comment 2 Larry the Git Cow gentoo-dev 2017-09-04 05:54:28 UTC
Bug has been closed via the following commit:
    https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=3a005bbaea41cf1e87e6a256bbf9e53cd26584a9

    commit 3a005bbaea41cf1e87e6a256bbf9e53cd26584a9
Author:     Robin H. Johnson <robbat2@gentoo.org>
AuthorDate: 2017-09-04 05:52:41 +0000
Commit:     Robin H. Johnson <robbat2@gentoo.org>
CommitDate: 2017-09-04 05:52:41 +0000

    initrd.scripts: fix cdupdate.sh path check
    
    This has been broken since the v3.4.52 release, more than 2 years ago.
    Looks like cdupdate.sh gets very little use.
    
    Fixes: https://bugs.gentoo.org/show_bug.cgi?id=593866
    Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>

 defaults/initrd.scripts | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
Comment 3 Christian Nilsson 2021-07-30 09:19:29 UTC
Thanks for the fixing, and sorry for not getting back earlier, wow time flies.
Unfortunately this still has issues.
(and as a result of that other workarounds have been used and not gone back to this - unsquashing, modifying, and resquashing, now I would like to make another try to get this resolved to avoid the squash mangling.)

Getting:
 >> Running cdupdate.sh (////cdupdate.sh)
 /init: line 1010: ////cdupdate.sh: not found
 !! Executing cdupdate.sh failed!

Tests
 * Get latest minimal livecd
 * Extract image.squashfs /boot/gentoo + .igz
 * Combine initrd+squashfs: (cat boot/gentoo.igz; (echo image.squashfs | cpio -H newc -o)) > gentoo.igz
 * Create cdupdate.sh with some contents and make it executable: chmod a+x cdupdate.sh
 * append cdupdate.sh: echo cdupdate.sh | cpio -H newc -o >> gentoo.igz

boot.ipxe is:
    #!ipxe
    kernel gentoo root=/dev/ram0 init=/linuxrc looptype=squashfs loop=/image.squashfs  cdroot initrd=gentoo.igz vga=791
    initrd gentoo.igz
    boot

Testing with:
    qemu-system-x86_64 -enable-kvm -M q35 -m 1024 -cpu host -nic user,model=virtio,tftp=.,bootfile=boot.ipxe -boot menu=on -usb

Tracking this at: https://github.com/ASoft-se/Gentoo-HAI/issues/8#issuecomment-889750826
Comment 4 Christian Nilsson 2021-07-30 11:41:33 UTC
One workaround is to add etc/initrd.splash and override cdupdate() function

I tried to patch the existing cdupdate() function and came up with:
https://github.com/NiKiZe/gentoo-pxe-builder/commit/a7048f558204a678e4ad2d53343af32f619d7f34
But not sure of the implications of doing it like this.
Also tried to use run sh instead of run ., but got not found error

        cdupdate_path=''
        for p in /${NEW_ROOT}/${CDROOT_PATH}/ /${CDROOT_PATH}/
        do
-           [ -x "${p}/cdupdate.sh" ] && cdupdate_path="${p}/cdupdate.sh" && break
+           [ -x "${p}cdupdate.sh" ] && cdupdate_path="${p}cdupdate.sh" && break
        done

        if [ -n "${cdupdate_path}" ]
        then
            good_msg "Running cdupdate.sh (${cdupdate_path})"
-           run ${cdupdate_path}
+           run . ${cdupdate_path}
            if [ "$?" != '0' ]
            then
                bad_msg "Executing cdupdate.sh failed!"
Comment 5 Christian Nilsson 2021-07-31 15:50:59 UTC
Turns out my latest issue was a shebang.
Don't use #!/bin/bash, best is probably to don't have anything at all at the top of cdupdate.sh

Which means that everything is working - and sorry for the noise.