PS : you can check it on archwiki actually.
Assumming you still don't have dracut and mkinitcpio, you can install dracut using pacman.
# pacman -S dracut (other packages blablabla)
We need to make 2 scripts for removing and installing vmlinuz and initramfs when kernel upgrade is available. We can place them under /usr/local/bin
and call them as dracut-install.sh
and dracut-remove.sh
.
-
dracut install.sh (for installing vmlinuz and generate initramfs).
#!/usr/bin/env bash args=('--force' '--no-hostonly-cmdline') 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-${pkgbase}" dracut "${args[@]}" --hostonly "/boot/initramfs-${pkgbase}.img" --kver "$kver" dracut "${args[@]}" --no-hostonly "/boot/initramfs-${pkgbase}-fallback.img" --kver "$kver" fi done
-
dracut-remove.sh (for removing vmlinuz and initramfs).
#!/usr/bin/env bash while read -r line; do if [[ "$line" == 'usr/lib/modules/'+([^/])'/pkgbase' ]]; then read -r pkgbase < "/${line}" rm -f "/boot/vmlinuz-${pkgbase}" "/boot/initramfs-${pkgbase}.img" "/boot/initramfs-${pkgbase}-fallback.img" fi done
We should not forget to set their permission to rwxr-xr-x
.
We can do it by using chmod
command :
# chmod 755 /usr/local/bin/dracut-install.sh
# chmod 755 /usr/local/bin/dracut-remove.sh
We need to make two hooks so pacman will automatically run the previous scripts (dracut-install.sh
and dracut-remove.sh
) when kernel upgrade is available. We can call them as 90-dracut-install.hook
and 60-dracut-remove.hook
. We can place them under /etc/pacman.d/hooks/
.
-
90-dracut-install.hook
[Trigger] Type = Path Operation = Install Operation = Upgrade Target = usr/lib/modules/*/pkgbase [Action] Description = Updating linux initcpios (with dracut!)... When = PostTransaction Exec = /usr/local/bin/dracut-install.sh Depends = dracut NeedsTargets
-
60-dracut-remove.hook
[Trigger] Type = Path Operation = Remove Target = usr/lib/modules/*/pkgbase [Action] Description = Removing linux initcpios... When = PreTransaction Exec = /usr/local/bin/dracut-remove.sh NeedsTargets