systemd-boot updater

#81

i have just added support for systemd-boot-manager’s config file to pacui:

4 Likes

#82

Sorry if that’s a bit off-topic. Just in case someone needs a very simplistic kernel version update solution for systemd-boot. Built this last autumn after not finding anything similar, but had no time to share this until now.

/usr/local/etc/pacman.d/hooks/linux-post.hook

[Trigger]
Operation = Install
Operation = Upgrade
Type = Package
Target = linux*
[Action]
Description = Update Bootloader Entries
When = PostTransaction
Exec = /usr/local/sbin/linux-post-hook.sh

/usr/local/sbin/linux-post-hook.sh

#!/bin/bash

uuid=$(blkid -o value -s UUID /dev/nvme0n1p2)
root=$(findmnt -no SOURCE -r /)
major_versions=$(pacman -Qe | awk '$1 ~ /^linux[0-9]+/ {split($2,v,"."); print v[1] "." v[2];}')
arch=$(uname -m)

# generate entries
for major in $major_versions; do
    version="$major-$arch"
    # main
    cat > /boot/loader/entries/manjaro-$version.conf <<EOF
title	Manjaro Linux $major
linux	/vmlinuz-$version
initrd	/intel-ucode.img
initrd	/initramfs-$version.img
options	cryptdevice=UUID=$uuid:cryptroot root=$root rw
EOF
    # fallback
    cat > /boot/loader/entries/manjaro-$version-fallback.conf <<EOF
title	Manjaro Linux $major
linux	/vmlinuz-$version
initrd	/intel-ucode.img
initrd	/initramfs-$version-fallback.img
options	cryptdevice=UUID=$uuid:cryptroot root=$root rw
EOF
done

# generate loader.conf
cat > /boot/loader/loader.conf << EOF
default  manjaro-$major-$arch
timeout  1
EOF

# clean up the obsolete entries
for f in /boot/loader/entries/manjaro-*.conf; do
    major=${${f#*manjaro-}%-$arch*}
    for m in $major_versions; do
        [[ $major == $m ]] && continue 2
    done
    rm $f
done
0 Likes

#83

Thanks for sharing your script. I’ve never written any script but a few questions (if hopefully that makes sense :grinning: )

That’s for nvme disk. So the user will have to modify it to /dev/sdxy for non-nvme disk?
What happens if the user has several disks? Wouldn’t device mapping be inconsistent?
Is there any way to ensure the right mapping or to use uuid’s?

That’s for encrypted partition. And I guess a simpler
root=$root rw
would do for unencrypted partition? But again that’s using device mapping. Any way to use uuid’s?

Thanks and cheers.

ps: I also have a few (non-systemd-boot manjaro’s) that I can boot from systemd-boot as well as several non-manjaro OS’s that is either systemd-boot or non-systemd-boot that I can boot from systemd-boot. I have to manually change the entries.conf for them but I’ll won’t trouble you for now on this. Thought I’d mention it.

0 Likes

#84

@tagirb

Forgot my key question. Sorry about that.
How about entries for 2 or more kernels?
Of course we can manually write in for these.
Can you automate these also?

Thanks.

0 Likes

#85

The systemd-boot-manager includes similar functionality except it discovers the root disk information without having to hard code it.

0 Likes

#86

That is what he is doing here:

major_versions=$(pacman -Qe | awk '$1 ~ /^linux[0-9]+/ {split($2,v,"."); print v[1] "." v[2];}')

He finds all the installed kernels and then later removes any entries not on this list.

2 Likes

#87

Thanks for explaining to a non-coder. Cheers.

1 Like

#88

Does this remove the quiet flag in the config file? Forgive my ignorance but when the kernel is updated I have to re-add quiet splash.

0 Likes

#89

Kernel options are persistent in /boot/loader/entries/*.conf files.
I had no problems so far.

0 Likes

#90

It generates using the options in /etc/sdboot-manage.conf

By default, that section looks like this:

# kernel options to be appended to the "options" line
#LINUX_OPTIONS=""
#LINUX_FALLBACK_OPTIONS=""

You may be wanting something like this instead:

# kernel options to be appended to the "options" line
LINUX_OPTIONS="quiet"
#LINUX_FALLBACK_OPTIONS=""
2 Likes

#91

Perfect, thank you.

1 Like

#92

Just tested this handy tool. It correctly detected most vital options including cryptdevice=blah-blah-blah:lvm, but without :allow-discards parameter. Got a couple of seconds gain compared to rEFInd haha.

1 Like

#93

Can you show me what a working line looks like? If it is detectable, I should be able to add support.

0 Likes

#94

Well, it is quite simple and looks like the following:
cryptdevice=deviceUUID:lvmNAME:allow-discards.
What I also noticed is rw option. For rEFInd I have to use ro, because with rw fsck systemd skips root partition. As far as I know, only grub allows using rw and it does not affect fsck checking of a root partition. Maybe I am wrong and systemd boot also allows this, could you please check? I have a screenshot in order to show what I mean:


The last log entry was generated when booting with ro (rEFInd), all the previous ones are rw/systemd.

0 Likes