Skip to content

Instantly share code, notes, and snippets.

@bitjockey42
Last active September 25, 2019 10:07
Show Gist options
  • Save bitjockey42/7f1c27ac24f05a42ed43aa73946a7033 to your computer and use it in GitHub Desktop.
Save bitjockey42/7f1c27ac24f05a42ed43aa73946a7033 to your computer and use it in GitHub Desktop.
Ubuntu 16.04 using systemd-boot instead of grubby

You do not need a separate /boot partition unless you have an LVM setup (used in dm-crypt setups).

Run ubiquity -b to open the installer with the option of skipping grub installation (since we're using systemd-boot).

When you get to the screen "Ubuntu has finished installation" choose Continue testing.

Open a Terminal.

Chroot into the new system.

mount /dev/sda5 /mnt # replace /dev/sda5 with wherever it is you installed Ubuntu
mount /dev/sda1 /mnt/boot/efi # this is where Ubuntu mounts the ESP
for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done
chroot /mnt

This will set systemd-boot to be our default:

aj@aj-MacbookPro $ sudo -i
root@aj-MacBookPro:~# history
    1  cd boot
    2  ls
    3  cd efi
    4  ls
    5  cat /etc/fstab # check entries
    6  ls
    7  cd ..
    8  ls
    9  cp abi-4.4.0-22-generic efi
   10  cp config-4.4.0-22-generic efi
   11  cp initrd.img-4.4.0-22-generic efi
   12  cp System.map-4.4.0-22-generic efi
   13  cp vmlinuz-4.4.0-22-generic efi
   14  ls efi
   15  cd efi
   16  ls
   17  bootctl --help
   18  cd
   19  cd /boot/efi
   20  ls
   21  mkdir -p loader/entries
   22  ls
   23  vi loader/loader.conf
   24  vi loader/entries/ubuntu.conf
   25  tree
   26  apt install tree
   27  tree
   28  bootctl install --path=/boot/efi
   29  efibootmgr
   30  ls
   31  cd /
   32  ls
   33  cd boo
   34  cd boot
   35  ls
   36  ls -l
   37  cp initrd.img-4.4.0-22-generic efi
   38  tree efi
   39  bootctl install --path=/boot/efi
   40  cd efi
   41  ls
   42  ls EFI
   43  ls EFI/systemd/
   51  efibootmgr -c -d /dev/sda1 -p 1 -l EFI/systemd/systemd-bootx64.efi -L "Linux Boot Manager"
   52  efibootmgr -o 0000
   53  ls
   54  history
root@aj-MacBookPro:~# 
@anxanywhere
Copy link

anxanywhere commented Aug 28, 2018

Hi @0x715C and @hashhar,

Thank you for shared code.

Question about shared code:

Why repeating the line that writes latest kernel entry to /boot/efi/loader/entries/ubuntu.conf? The latest kernel entry is expected to be written only once, so that part of code could be moved out of first FOR block.

Regards,
ANx

Suggesting the code below:

#!/bin/bash

vmlinuz=$(find /boot -maxdepth 1 -name "vmlinuz-*-generic")
version=$(echo $vmlinuz | grep -o -P "\d+\.\d+\.\d+\-\d+" | sort -V | head -n -1)
latest=$(echo $vmlinuz | grep -o -P "\d+\.\d+\.\d+\-\d+" | sort -V | tail -n 1)

echo ">> COPYING ${latest}-generic. LATEST VERSION."

cat << EOF > /boot/efi/loader/entries/ubuntu.conf
title   Ubuntu
linux   /ubuntu/vmlinuz-generic
initrd  /ubuntu/initrd.img-generic
options root=/dev/VG0/lvROOT rw
EOF

for file in initrd.img vmlinuz; do
    cp "/boot/${file}-${latest}-generic" "/boot/efi/ubuntu/${file}-generic"
done

for ver in $version; do

    echo ">> COPYING ${ver}-generic."

cat << EOF > /boot/efi/loader/entries/ubuntu-${ver}.conf
title   Ubuntu ${ver}
linux   /ubuntu/vmlinuz-${ver}-generic
initrd  /ubuntu/initrd.img-${ver}-generic
options root=/dev/VG0/lvROOT rw
EOF

    for file in initrd.img vmlinuz; do
        cp "/boot/${file}-${ver}-generic" "/boot/efi/ubuntu/${file}-${ver}-generic"
    done
done

exit 0

@jeremyb31
Copy link

pepa65 the abi files are not needed and are not included with Ubuntu kernel 4.15.0-43

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment