[Solved] Where should I put kernel postinstall scripts?

Post Reply
User avatar
mad_ady
Posts: 6401
Joined: Wed Jul 15, 2015 5:00 pm
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1, H2, N2
Location: Bucharest, Romania
Has thanked: 150 times
Been thanked: 109 times
Contact:

[Solved] Where should I put kernel postinstall scripts?

Unread post by mad_ady » Fri Jun 21, 2019 1:25 am

Back when I was running kernel 3.14, I could put shell scripts in /etc/kernel/postinst.d/ and they were run automatically by dpkg when updating the kernel (I need them to make some changes to the dtb).
After migrating to 18.04/kernel 3.16 those scripts no longer get called after kernel upgrade.
What is the correct mechanism to run something after a kernel upgrade?
Should I poke around in /usr/share/initramfs-tools? Not sure if initramfs update runs after the dtb is copied...
Last edited by mad_ady on Fri Jun 21, 2019 9:43 pm, edited 1 time in total.

User avatar
meveric
Posts: 10402
Joined: Mon Feb 25, 2013 2:41 pm
languages_spoken: german, english
ODROIDs: X2, U2, U3, XU-Lite, XU3, XU3-Lite, C1, XU4, C2, C1+, XU4Q, HC1, N1, Go, H2 (N4100), N2
Has thanked: 15 times
Been thanked: 121 times
Contact:

Re: Where should I put kernel postinstall scripts?

Unread post by meveric » Fri Jun 21, 2019 3:05 am

The "correct" mechanism is still /etc/kernel/postinst.d/ but since HardKernel no longer uses "regular" kernel packages but in fact just makes their own packages with their own scripts. I doubt there is any "official" way they do things anymore.
They probably have to add a set of new scripts to run other external scripts, like they did with the dkms packages for the ODROID N2.
In fact you might just be able to put your scripts into the dkms script and each time a kernel updates starts that "fake" dkms script triggers your stuff.
Although I'm not sure if HK adapted their changes for N2 dkms for C2 as well.

Edit:
Just checked the code of the linux-odroid-c2 package...
Nope there's nothing that would help you the postinst from hardkernel does nothing useful:

Code: Select all

        cp /boot/Image /media/boot/Image
        cp /boot/*.dtb /media/boot
        update-initramfs -c -k $version
        mkimage -A arm64 -O linux -T ramdisk -C none -a 0 -e 0 -n uInitrd -d /boot/initrd.img-$version /boot/uInitrd-$version
        cp /boot/uInitrd-$version /media/boot/uInitrd
These users thanked the author meveric for the post:
mad_ady (Fri Jun 21, 2019 3:07 am)
Donate to support my work on the ODROID GameStation Turbo Image for U2/U3 XU3/XU4 X2 X C1 as well as many other releases.
Check out the Games and Emulators section to find some of my work or check the files in my repository to find the software i build for ODROIDs.
If you want to add my repository to your image read my HOWTO integrate my repo into your image.

User avatar
mad_ady
Posts: 6401
Joined: Wed Jul 15, 2015 5:00 pm
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1, H2, N2
Location: Bucharest, Romania
Has thanked: 150 times
Been thanked: 109 times
Contact:

Re: Where should I put kernel postinstall scripts?

Unread post by mad_ady » Fri Jun 21, 2019 3:09 am

I wonder why they gave up on standard kernel packages...

User avatar
meveric
Posts: 10402
Joined: Mon Feb 25, 2013 2:41 pm
languages_spoken: german, english
ODROIDs: X2, U2, U3, XU-Lite, XU3, XU3-Lite, C1, XU4, C2, C1+, XU4Q, HC1, N1, Go, H2 (N4100), N2
Has thanked: 15 times
Been thanked: 121 times
Contact:

Re: Where should I put kernel postinstall scripts?

Unread post by meveric » Fri Jun 21, 2019 3:14 am

mad_ady wrote:
Fri Jun 21, 2019 3:09 am
I wonder why they gave up on standard kernel packages...
Cause they had issues building linux-headers packages that "work" so they simply copy everything manually and distribute it as their own package.
Donate to support my work on the ODROID GameStation Turbo Image for U2/U3 XU3/XU4 X2 X C1 as well as many other releases.
Check out the Games and Emulators section to find some of my work or check the files in my repository to find the software i build for ODROIDs.
If you want to add my repository to your image read my HOWTO integrate my repo into your image.

User avatar
mad_ady
Posts: 6401
Joined: Wed Jul 15, 2015 5:00 pm
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1, H2, N2
Location: Bucharest, Romania
Has thanked: 150 times
Been thanked: 109 times
Contact:

Re: Where should I put kernel postinstall scripts?

Unread post by mad_ady » Fri Jun 21, 2019 3:55 am

Well, update-initramfs runs after copying the dtb, so I'll try to plug my scripts there... Will let you know how it goes.

User avatar
mad_ady
Posts: 6401
Joined: Wed Jul 15, 2015 5:00 pm
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1, H2, N2
Location: Bucharest, Romania
Has thanked: 150 times
Been thanked: 109 times
Contact:

Re: Where should I put kernel postinstall scripts?

Unread post by mad_ady » Fri Jun 21, 2019 9:42 pm

Ok, I gave it a test. Copied over my scripts from /etc/kernel/postinst.d/ to /usr/share/initramfs-tools/hooks/ and reinstalled the kernel. Output shows my scripts were run and they made the necessary changes. So, it's a viable workaround, though it's not "clean":

Code: Select all

root@uy-scuti:~# apt-get install --reinstall linux-odroid-c2
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libllvm7 linux-tools-4.15.0-47 linux-tools-4.15.0-47-generic
  linux-tools-4.15.0-48 linux-tools-4.15.0-48-generic linux-tools-4.15.0-51
  linux-tools-4.15.0-51-generic
Use 'apt autoremove' to remove them.
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 3 not upgraded.
Need to get 0 B/18.1 MB of archives.
After this operation, 0 B of additional disk space will be used.
(Reading database ... 259759 files and directories currently installed.)
Preparing to unpack .../linux-odroid-c2_3.16.68-41_arm64.deb ...
Unpacking linux-odroid-c2 (3.16.68-41) over (3.16.68-41) ...
Setting up linux-odroid-c2 (3.16.68-41) ...
update-initramfs: Generating /boot/initrd.img-3.16.68-41
I: The initramfs will attempt to resume from /dev/zram3
I: (UUID=df736890-bcc8-4a7e-87e4-2be89b50e5f1)
I: Set the RESUME variable to override this.
Setting 1wire GPIO to J7 header
Disabling I2S support from the device tree
Image Name:   uInitrd
Created:      Fri Jun 21 15:38:29 2019
Image Type:   AArch64 Linux RAMDisk Image (uncompressed)
Data Size:    12016348 Bytes = 11734.71 KiB = 11.46 MiB
Load Address: 00000000
Entry Point:  00000000
root@uy-scuti:~# fdtdump /media/boot/meson64_odroidc2.dtb | grep -A 3 onewire

**** fdtdump is a low-level debugging tool, not meant for general use.
**** If you want to decompile a dtb, you probably want
****     dtc -I dtb -O dts <filename>

    onewire {
        compatible = "w1-gpio";
        gpios = <0x00000025 0x0000000a 0x00000000>;
    };

These users thanked the author mad_ady for the post:
tobetter (Fri Jun 21, 2019 10:10 pm)

User avatar
meveric
Posts: 10402
Joined: Mon Feb 25, 2013 2:41 pm
languages_spoken: german, english
ODROIDs: X2, U2, U3, XU-Lite, XU3, XU3-Lite, C1, XU4, C2, C1+, XU4Q, HC1, N1, Go, H2 (N4100), N2
Has thanked: 15 times
Been thanked: 121 times
Contact:

Re: [Solved] Where should I put kernel postinstall scripts?

Unread post by meveric » Sat Jun 22, 2019 8:10 pm

This will also be triggered each time you trigger a update-initramfs... which can be quite often.
Installing and updating certain applications have a habit to do this.
So make sure your script doesn't cause any issue if it's run without installing a new Kernel.
Donate to support my work on the ODROID GameStation Turbo Image for U2/U3 XU3/XU4 X2 X C1 as well as many other releases.
Check out the Games and Emulators section to find some of my work or check the files in my repository to find the software i build for ODROIDs.
If you want to add my repository to your image read my HOWTO integrate my repo into your image.

User avatar
mad_ady
Posts: 6401
Joined: Wed Jul 15, 2015 5:00 pm
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1, H2, N2
Location: Bucharest, Romania
Has thanked: 150 times
Been thanked: 109 times
Contact:

Re: [Solved] Where should I put kernel postinstall scripts?

Unread post by mad_ady » Sat Jun 22, 2019 10:10 pm

Thanks. In my case it's fine. It's just changing the dtb via fdtset.

Post Reply

Return to “Ubuntu”

Who is online

Users browsing this forum: No registered users and 3 guests