You are not logged in.

#1 2021-04-20 21:52:56

maros
Member
Registered: 2020-12-08
Posts: 2

alpm-hook not working, but why?

Hello,

I am trying to write an alpm-hook that will move /boot/vmlinuz-linux-lts to /boot/arch-zfs/vmlinuz-linux-lts every time a new kernel is installed.

# cat /etc/pacman.d/hooks/89-move-kernel.hook 
[Trigger]
Operation = Install
Operation = Remove
Operation = Upgrade
Type = Package
Target = linux-lts

[Action]
Description = moving vmlinz-linux-lts to boot-arch-zfs
When = PostTransaction
Depends = linux-lts
Exec = /bin/mv -f /boot/vmlinuz-linux-lts /boot/arch-zfs/vmlinuz-linux-lts

First the good news: The hook is being executed every time the kernel is upgraded! The bad news is that it that the "mv" fails. It seems that is because "/boot/vmlinuz-linux-lts" is not created up until the moment pacman is finished. That seems... odd. Can somebody explain to me what is happening here?

# pacman -Syu
[...]
(21/21) upgrading vulkan-intel                                                    [##############################################] 100%
:: Running post-transaction hooks...
( 1/18) Creating system user accounts...
( 2/18) Updating journal message catalog...
( 3/18) Reloading system manager configuration...
( 4/18) Updating udev hardware database...
( 5/18) Applying kernel sysctl settings...
Not setting net/ipv4/conf/all/rp_filter (explicit setting exists).
Not setting net/ipv4/conf/default/rp_filter (explicit setting exists).
Not setting net/ipv4/conf/all/accept_source_route (explicit setting exists).
Not setting net/ipv4/conf/default/accept_source_route (explicit setting exists).
Not setting net/ipv4/conf/all/promote_secondaries (explicit setting exists).
Not setting net/ipv4/conf/default/promote_secondaries (explicit setting exists).
( 6/18) Creating temporary files...
( 7/18) Reloading device manager configuration...
( 8/18) Arming ConditionNeedsUpdate...
( 9/18) Updating module dependencies...
(10/18) Install DKMS modules
==> dkms install --no-depmod -m zfs -v git -k 5.4.82-1-lts
==> dkms install --no-depmod -m vboxhost -v 6.0.14_OSE -k 5.4.82-1-lts
==> depmod 5.4.82-1-lts
(11/18) moving vmlinz-linux-lts to boot-arch-zfs
/bin/mv: cannot stat '/boot/vmlinuz-linux-lts': No such file or directory
error: command failed to execute correctly
(12/18) Updating linux initcpios...
==> Building image from preset: /etc/mkinitcpio.d/linux-lts.preset: 'default'
  -> -k /boot/arch-zfs/vmlinuz-linux-lts -c /etc/mkinitcpio.conf -g /boot/arch-zfs/initramfs-linux-lts.img
==> ERROR: '/lib/modules/5.4.81-1-lts' is not a valid kernel module directory
[...]

Offline

#2 2021-04-20 23:27:06

Scimmia
Bug Wrangler
Registered: 2012-09-01
Posts: 8,495

Re: alpm-hook not working, but why?

Because it's happening too early, the mkinitcpio hook is what moves it there.

Online

#3 2021-04-21 00:23:43

maros
Member
Registered: 2020-12-08
Posts: 2

Re: alpm-hook not working, but why?

Hello Scimmia

thank you very much for your reply!
Seems like you're right:

$ pacman -Ql linux
[...]
linux /usr/lib/modules/5.5.13-arch2-1/modules.symbols
linux /usr/lib/modules/5.5.13-arch2-1/modules.symbols.bin
linux /usr/lib/modules/5.5.13-arch2-1/pkgbase
linux /usr/lib/modules/5.5.13-arch2-1/vmlinuz

Apparently, the linux package installs the kernel to /usr/lib/modules and then it gets moved to /boot by a script.

/usr/share/libalpm/hooks/90-mkinitcpio-install.hook calls /usr/share/libalpm/scripts/mkinitcpio-install and there we find the following line:

cat /usr/share/libalpm/scripts/mkinitcpio-install
#!/bin/bash -e

args=()
all=0

[...]
    # always install the kernel
    install -Dm644 "${line}" "/boot/vmlinuz-${pkgbase}"
[...]

Thank you very much for pointing me in the right direction!

Last edited by maros (2021-04-21 00:24:58)

Offline

Board footer

Powered by FluxBB