You are not logged in.
I'm playing with using dracut and I've created a new initramfs-linux-dracut.img so I can test and still use the standard mkinitcpo to automatically generate the default initramfs-linux.img
I've been using the following, which is working well for my needs:
# dracut -H --lz4 -f /boot/initramfs-linux-dracut.img
I'm trying to figure out how to regenerate the dracut initramfs when the kernel has just been updated without rebooting first.
For instance I just updated linux from 5.1.7.arch-1 to 5.1.8.arch1-1 and tried to regenerate dracut initramfs.
$ sudo pacman -Syu
...
:: Starting full system upgrade...
resolving dependencies...
looking for conflicting packages...
Package (8) Old Version New Version Net Change Download Size
core/glib2 2.60.3-1 2.60.3-2 -0.06 MiB 2.39 MiB
extra/libevdev 1.6.0-1 1.7.0-1 0.00 MiB 0.05 MiB
extra/libmm-glib 1.10.0-1 1.10.2-1 0.79 MiB 0.38 MiB
core/linux 5.1.7.arch1-1 5.1.8.arch1-1 0.00 MiB 71.73 MiB
core/linux-lts 4.19.48-1 4.19.49-1 0.00 MiB 74.95 MiB
core/linux-lts-docs 4.19.48-1 4.19.49-1 0.00 MiB 6.19 MiB
core/linux-lts-headers 4.19.48-1 4.19.49-1 0.00 MiB 8.74 MiB
extra/modemmanager 1.10.0-1 1.10.2-1 0.09 MiB 1.06 MiB
Total Download Size: 165.51 MiB
Total Installed Size: 321.82 MiB
...
# dracut -H --lz4 -f /boot/initramfs-linux-dracut.img 5.1.8.arch1-1
dracut: Cannot find module directory /lib/modules/5.1.8.arch1-1/
dracut: and --no-kernel was not specified
# dracut -H --lz4 -f /boot/initramfs-linux-dracut.img 5.1.8.arch1-1-ARCH
dracut: Cannot find module directory /lib/modules/5.1.8.arch1-1-ARCH/
dracut: and --no-kernel was not specified
# dracut -H --lz4 -f /boot/initramfs-linux-dracut.img --kver 5.1.8.arch1-1
dracut: Cannot find module directory /lib/modules/5.1.8.arch1-1/
dracut: and --no-kernel was not specified
# dracut -H --lz4 -f /boot/initramfs-linux-dracut.img --kver 5.1.8.arch1-1-ARCH
dracut: Cannot find module directory /lib/modules/5.1.8.arch1-1-ARCH/
dracut: and --no-kernel was not specified
Do I have to reboot in order to do this? The module directory it complains about is there:
$ ls -al /lib/modules
total 264
drwxr-xr-x 6 root root 4096 Jun 10 18:05 .
drwxr-xr-x 201 root root 245760 Jun 10 18:05 ..
drwxr-xr-x 4 root root 4096 Jun 10 18:05 4.19.49-1-lts
drwxr-xr-x 3 root root 4096 Jun 10 18:05 5.1.8-arch1-1-ARCH
drwxr-xr-x 2 root root 4096 Jun 10 18:05 extramodules-4.19-lts
drwxr-xr-x 2 root root 4096 Jun 10 18:05 extramodules-ARCH
I understand that I'm still ?technically on the old kernel until reboot?:
$ uname -a
Linux 5510 5.1.7-arch1-1-ARCH #1 SMP PREEMPT Tue Jun 4 15:47:45 UTC 2019 x86_64 GNU/Linux
but feel like this should be possible, as obviously mkinitcpio is doing this, and I'm just missing something obvious.
Last edited by CarbonChauvinist (2019-06-20 21:22:37)
"the wind-blown way, wanna win? don't play"
Offline
I use a pacman hook:
[trigger]
operation = upgrade
type = package
target = linux-jwr
[action]
description = regenerate initrd after kernel build
depends = dracut
when = posttransaction
exec = /usr/share/libalpm/scripts/dracut-jwr
And the script uses --kver to point to the correct modules. Your third invocation should work. I don't have access to my laptop at the moment, but I don't see any obvious flaw.
edit: the script just generates this line:
dracut -H -f --no-hostonly-cmdline --kver 5.1.7-1-JWR /boot/initramfs-dracut.img
It works without rebooting into the newly installed kernel.
Offline
Look carefully, the package version and the kernel version are subtly different. There is a dash instead of a dot in addition to the appended -ARCH.
5.1.8.arch1-1
5.1.8-arch1-1-ARCH
Last edited by progandy (2019-06-10 23:31:43)
| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |
Offline
@jasonwryan Thanks, this is very helpful (and I'm definitely going to go the hook route once I feel comfortable with the manual process). So, just to confirm -- your script isn't hard-coded to that kernel version when rebuilding (i.e. 5.1.7-1-JWR) and instead you have some logic that parses out and uses the updated kernel's version/name?
@progandy, Wow, I knew it had to be something I wasn't seeing - thanks a lot - I'm sure this is the issue. I'll verify and update this thread on the next linux update.
Last edited by CarbonChauvinist (2019-06-10 23:39:47)
"the wind-blown way, wanna win? don't play"
Offline
@jasonwryan Thanks, this is very helpful (and I'm definitely going to go the hook route once I feel comfortable with the manual process). So, just to confirm -- your script isn't hard-coded to that kernel version when rebuilding (i.e. 5.1.7-1-JWR) and instead you have some logic that parses out and uses the updated kernel's version/name?
Yes, I just parse pacman -Q. There is probably a better way to do it, but it does the job
Offline
This works for me:
dracut -H -f --no-hostonly-cmdline --kver $(ls /lib/modules| grep ARCH) /boot/initramfs-linux.img
Offline
You really should not parse `ls`. And that relies on only one kernel having ARCH in its name...
Offline
I would probably use something like this for a universal hook. Converting the package version would require knowledge on which elements have to be changed.
This way, I can get away with the assumption that the kernel package creates a copy of the kernel image in /usr/lib/modules/${KERNELVERSION}/vmlinuz
pacman -Qql ${kernelpackage} | sed -n 's#^/usr/lib/modules/\([^/]*\)/vmlinuz$#\1#p'
The official mkinitcpio hooks have the version string hardcoded.
A dynamic hook specifically for the linux package could use this:
expac -Q "%v-ARCH" linux | sed 's/\.arch/-arch/'
Edit: Improved with ideas from fjvinal and jasonwryan.
Last edited by progandy (2019-06-12 22:26:25)
| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |
Offline
A bit ugly, but works:
dracut -H -f /boot/initramfs-linux.img $(pacman -Ql linux|grep /usr/lib/modules|grep vmlinuz| cut -d '/' -f 5)
Offline
Only because I like complicating things...
#!/usr/bin/bash
type expac > /dev/null 2>&1 || { printf "%s\n" "No expac, bailing..."; exit 1;}
kver=$(expac -Q "%v" linux-jwr)-JWR
imgname="/boot/initramfs-dracut.img"
/usr/bin/dracut -q --kver "${kver}" "$imgname"
Offline
A pacman hook:
[Trigger]
Operation = Upgrade
Type = Package
Target = linux
[Action]
Description = regenerate initrd after kernel build
Depends = dracut
When = PostTransaction
Exec = /usr/bin/bash -c "dracut -H -f /boot/initramfs-linux.img $(pacman -Ql linux|grep /usr/lib/modules|grep vmlinuz| cut -d '/' -f 5)"
Last edited by fjvinal (2019-06-12 22:11:23)
Offline
Thanks all for your input - I have been watching silently and came up with the following last night. Please give your input on the below snippets (first time to write a Bash script, use `awk` and `sed` and to write a Pacman hook) - after all, this is the Newbie Corner and I'd be happy to learn
#!/bin/bash
# Get the version number of the currently installed Linux kernel and store it in a variable
linuxver="$(pacman -Q linux | awk '{print $2}' | sed 's/.arch/-arch/')-ARCH"
# run dracut to generate a initramfs (source: https://bbs.archlinux.org/viewtopic.php?id=247015)
sudo dracut -H -f --no-hostonly-cmdline --kver $linuxver /boot/initramfs-dracut.img
And the Pacman hook:
[Trigger]
Operation = Install
Operation = Upgrade
Type = Package
Target = linux
[Action]
Description = Generate initrd with dracut after kernel upgrade
Depends = dracut
When = PostTransaction
Exec = /usr/share/libalpm/scripts/dracut-ejjl
Last edited by lquidfire (2019-06-13 10:58:32)
Offline
grep and awk are redundant:
pacman -Q linux | awk '{sub(/.arch/,"-arch"); print $2}'
Offline
And the Pacman hook:
[Trigger] Operation = Install Operation = Upgrade Type = Package Target = linux [Action] Description = Generate initrd with dracut after kernel upgrade Depends = dracut When = PostTransaction Exec = /usr/share/libalpm/scripts/dracut-ejjl
With this hook, dracut will regenerate the initramfs when linux is updated. As far as I know the mkinitcpio pacman hook also runs when other packages are updated (eg systemd, lvm2, cryptsetup ...). Is this necessary in order to get a working initramfs? I think this could easily be added with more packages listed as Targets
Offline
Thank you, Jason, I have changed that and will look more deeply into awk.
Thank you, too, sepplgruber - that is a fair point and I will look into that!
Offline
Marking this as solved. Thanks to all for the insight and examples -- really helpful. Thanks to those, I've been able to set up some pacman hooks that work really well for my needs.
"the wind-blown way, wanna win? don't play"
Offline
Do you mind sharing them with us?
Frumpus ♥ addict
[mu'.krum.pus], [frum.pus]
Offline
lquidfire wrote:And the Pacman hook:
[Trigger] Operation = Install Operation = Upgrade Type = Package Target = linux [Action] Description = Generate initrd with dracut after kernel upgrade Depends = dracut When = PostTransaction Exec = /usr/share/libalpm/scripts/dracut-ejjl
With this hook, dracut will regenerate the initramfs when linux is updated. As far as I know the mkinitcpio pacman hook also runs when other packages are updated (eg systemd, lvm2, cryptsetup ...). Is this necessary in order to get a working initramfs? I think this could easily be added with more packages listed as Targets
Yes. Depending on the setup intel-ucode/amd-ucode are also needed (in addition to cryptsetup/lvm).
Offline
... what is the content of /usr/share/libalpm/scripts/dracut-ejjl?
Frumpus ♥ addict
[mu'.krum.pus], [frum.pus]
Offline
@Moo-Crumpus
I can certainly share mine when I'm back home in front of my box, but mine was not perfect - there were times were the name wasn't parsed correctly and I had to manually rebuild dracut (normally when arch1-1 or arch2-1 or something came up) on a kernel upgrade.
I'd suggest looking at this page, as @krathalan's approach (quoted below) seems like it would be more robust.
~/.local/bin/90-dracut-linux.script
#!/bin/bash
args=('-H' '--no-hostonly-cmdline')
while read -r line; do
if [[ $line = usr/lib/modules/+([^/])/pkgbase ]]; then
mapfile -O ${#pkgbase[@]} -t pkgbase < "/$line"
kver=${line#"usr/lib/modules/"}
kver=${kver%"/pkgbase"}
fi
done
dracut "${args[@]}" -f /boot/initramfs-"${pkgbase[@]}".img --kver "${kver[@]}"
dracut -f /boot/initramfs-"${pkgbase[@]}"-fallback.img --kver "${kver[@]}"
/etc/pacman.d/hooks/90-dracut-linux.hook
[Trigger]
Type = File
Operation = Install
Operation = Upgrade
Target = usr/lib/modules/*/pkgbase
[Action]
Description = Updating linux initcpios (with dracut!)...
When = PostTransaction
Exec = /home/username/.local/bin/90-dracut-linux.script
NeedsTargets
You will also have to copy the new vmlinuz kernel file from /usr/lib/modules/[kver]/vmlinuz to /boot/vmlinuz-linux every kernel upgrade, as the linux package is no longer responsible for that -- 90-mkinitcpio-install.hook is. From the arch-general mailing list:
I've meant to incorporate this strat in my hook -- just haven't gotten around to it yet.
Last edited by CarbonChauvinist (2020-01-13 18:03:49)
"the wind-blown way, wanna win? don't play"
Offline
thank you
Frumpus ♥ addict
[mu'.krum.pus], [frum.pus]
Offline
Hm, those are the scripts offered at the wiki, they freeze...
Frumpus ♥ addict
[mu'.krum.pus], [frum.pus]
Offline
@Moo-Crumpus, I'm not sure what you mean by freeze - I have no issues with the following which were all copied from the wiki (I only changed the generated initramfs file names to also include the string dracut and also added `usr/lib/dracut/*` as targets for both hooks):
$ cat /etc/pacman.d/hooks/60-dracut-remove.hook
[Trigger]
Type = Path
Operation = Remove
Target = usr/lib/modules/*/pkgbase
Target = usr/lib/dracut/*
[Action]
Description = Removing linux initcpios...
When = PreTransaction
Exec = /usr/local/bin/dracut-remove.sh
NeedsTargets
$ cat /etc/pacman.d/hooks/90-dracut-install.hook
[Trigger]
Type = Path
Operation = Install
Operation = Upgrade
Target = usr/lib/modules/*/pkgbase
Target = usr/lib/dracut/*
[Action]
Description = Updating linux initcpios (with dracut!)...
When = PostTransaction
Exec = /usr/local/bin/dracut-install.sh
NeedsTargets
$ cat /usr/local/bin/dracut-install.sh
#!/usr/bin/env bash
while read -r line; do
if [[ "$line" == 'usr/lib/modules/'+([^/])'/pkgbase' ]]; then
read -r pkgbase < "/${line}"
kver="${line#'usr/lib/modules/'}"
kver="${kver%'/pkgbase'}"
install -Dm0644 "/${line%'/pkgbase'}/vmlinuz" "/boot/vmlinuz-dracut-${pkgbase}"
dracut --force "/boot/initramfs-dracut-${pkgbase}.img" --kver "$kver"
dracut --no-hostonly --force "/boot/initramfs-dracut-${pkgbase}-fallback.img" --kver "$kver"
fi
done
$ cat /usr/local/bin/dracut-remove.sh
#!/usr/bin/env bash
while read -r line; do
if [[ "$line" == 'usr/lib/modules/'+([^/])'/pkgbase' ]]; then
read -r pkgbase < "/${line}"
rm -f "/boot/vmlinuz-dracut-${pkgbase}" "/boot/initramfs-dracut-${pkgbase}.img" "/boot/initramfs-dracut-${pkgbase}-fallback.img"
fi
done
$ cat /etc/dracut.conf.d/myflags.conf
hostonly_cmdline="yes"
compress="lz4"
force_drivers+=" i915 "
omit_dracutmodules+=" network iscsi "
early_microcode="yes"
install_optional_items+=" /etc/environment /etc/modprobe.d/modprobe.conf /usr/bin/systemd-tty-ask-password-agent "
For my dracut flags above^^^, I'm only adding systemd-tty-ask-password-agent to get rid of a informational warning message. This work around should not be necessary when new version of dracut is released on Arch AFAICT.
I'd suggest if you're still having issues to open a new thread so you can get more focused attention.
"the wind-blown way, wanna win? don't play"
Offline
$ cat /etc/dracut.conf.d/myflags.conf hostonly_cmdline="yes" compress="lz4" force_drivers+=" i915 " omit_dracutmodules+=" network iscsi " early_microcode="yes" install_optional_items+=" /etc/environment /etc/modprobe.d/modprobe.conf /usr/bin/systemd-tty-ask-password-agent "
For my dracut flags above^^^, I'm only adding systemd-tty-ask-password-agent to get rid of a informational warning message. This work around should not be necessary when new version of dracut is released on Arch AFAICT.
Thanks for this, @CarbonChauvinist. I was getting tired of those warnings, too.
Eenie meenie, chili beanie, the spirits are about to speak -- Bullwinkle J. Moose
It's a big club...and you ain't in it -- George Carlin
Registered Linux user #149839
perl -e 'print$i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10); '
Offline