Announcement

Collapse
No announcement yet.

Manually configure GRUB for multi-boot, persistent to kernel updates

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [System] Manually configure GRUB for multi-boot, persistent to kernel updates


    Hello everyone!

    I have a laptop with Windows 11, vanilla OS 2, and kubuntu 26.04 LTS (in order of installation). I want to make a manual grub configuration, that will offer all three operating systems during boot up and that will be able to boot any future kernel and initrd without needing further modifications. I looked it up and prompted chatGPT, and now I think it is best to ask for some advice before I commit.

    I got the idea from John Little in this thread. I considered it best to create a new thread because manual grub configuration could prove future-proof (according to what John mentioned there) and therefore helpful to other members not just myself. Additionally, that specific thread was about partitioning and pre-install, so I felt we were starting to go off-topic.

    Following suggestions were produced by the AI tool, with the first one to backup my configuration files:

    Code:
    sudo cp /etc/default/grub /etc/default/grub.bak
    sudo cp -r /etc/grub.d /etc/grub.d.bak
    sudo cp /boot/grub/grub.cfg /boot/grub/grub.cfg.bak
    
    Backup ESP (example ESP = /dev/nvme0n1p1):
    sudo mkdir -p /mnt/esp && sudo mount /dev/nvme0n1p1 /mnt/esp
    sudo cp -r /mnt/esp /root/esp-backup
    sudo umount /mnt/esp
    After that, the tool suggested that I ¨use /etc/grub.d/40_custom¨ on which I could copy+paste the text it provided and then make it executable and then run update-grub.

    I didn´t copy paste blindly,I copied the entries from the kubuntu grub file (regarding kubuntu and windows entries) and then booted to vanilla and copied the vanilla entries too.
    Code:
    #!/bin/sh
    exec tail -n +3 $0
    
    menuentry 'Kubuntu 26.04' --class kubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-[UUID of kubuntu root partition]' {
            recordfail
            load_video
            set gfxpayload=$linux_gfx_mode
            insmod gzio
            if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
            insmod part_gpt
            insmod ext2
            search --no-floppy --fs-uuid --set=root [UUID of kubuntu root partition]
            linux /boot/vmlinuz root=UUID=[UUID of kubuntu root partition] ro  quiet splash $vt_handoff{
            initrd /boot/initrd.img
    #For the last two lines, I followed this advice: https://help.ubuntu.com/community/Grub2/CustomMenus
    }
    #linux /vmlinuz root=UUID=[UUID of kubuntu root partition] ro quiet splash
    #initrd /initrd.img
    
    
    menuentry "Vanilla OS - Current State (A)" --class abroot-a {
    search --fs-uuid --no-floppy --set=root(lvm/vos--root-init)
    configfile "/vos-a/abroot.cfg"
    chainloader /boot/efi/EFI/vanilla/grub.cfg # I am not sure about this one... Copied from within Vanilla.
    }
    
    menuentry "Vanilla OS - Previous State (B)" --class abroot-b {
    search --fs-uuid --no-floppy --set=root(lvm/vos--root-init)
    configfile "/vos-b/abroot.cfg"​
    chainloader /boot/efi/EFI/vanilla/grub.cfg # I am not sure about this one... Copied from within Vanilla.
    }​
    
    # COMMENT: the ai tool suggested I chainloaded Vanilla´s EFI bootloader, but I copied the above from vanilla´s boot partition. Not sure if it will work...
    # AI said: Replace /EFI/OtherDistro/grubx64.efi below with the actual path found under /boot/efi/EFI
    # I need to understand what the above line does, haven´t figured it out yet!​
    #chainloader /boot/efi/EFI/vanilla/grub.cfg # I am not sure about this one... Copied from within Vanilla.
    
    
    menuentry "Windows 11 - chainload Windows Boot Manager" {
    search --fs-uuid --no-floppy --set=root *****
    chainloader /EFI/Microsoft/Boot/bootmgfw.efi
    }
    # COMMENT: no changes for the win menuentry
    The ai tool suggested I should then run:
    • sudo chmod +x /etc/grub.d/40_custom
    • sudo update-grub

    I have no idea if any of the above will work well... Do they look okay? Did I miss anything important?

    Thank you in advance!
    Last edited by zahtar; Today, 04:52 PM. Reason: updated candidate grub configuration file

    #2
    Firstly, a general note. Manually coding grub files suggests one should learn about
    • sudo efibootmgr
    • /etc/fstab
    • /etc/default/grub
    • grub.cfg as it is generated by Kubuntu
    The menu entry for Kubuntu looks like it will work. It assumes Kubuntu is on ext4 ("insmod ext2"). I'd take out all the lines before the search statement as being redundant or unnecessary, except possibly the "recordfail" (I use btrfs and the recordfail stuff, which avoids boot loops, doesn't work on btrfs.)

    The entries for Vanilla OS have problems:
    • They should not have chainloader statements; the configfile statements should bring up the Vanilla OS grub menus. If you wanted to chain load vanilla OS it would be the .efi file in the ESP somewhere.
    • I'm not sure about the syntax in those search statements; looks quite wrong.
    I suggest turning on the OS prober in Kubuntu (GRUB_DISABLE_OS_PROBER=false in /etc/default/grub, run update-grub) and see what gets generated.

    Presumably in the Windows entry "*****" stands for the ID of the ESP where the bootmgfw.efi is.
    Regards, John Little

    Comment

    Users Viewing This Topic

    Collapse

    There are 0 users viewing this topic.

    Working...
    X