Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # This is a simple kernel hook to populate the systemd-boot entries
- # whenever kernels are added or removed.
- # The UUID of your root "/" disk.
- UUID="852b5870-0055-4d5b-91f7-101e5ead3b6f"
- # Any rootflags you wish to set. For example, mine are currently
- # "subvol=@ quiet splash intel_pstate=enable".
- #ROOTFLAGS="subvol=@"
- # Our kernels.
- KERNELS=()
- FIND="find /boot -maxdepth 1 -name 'vmlinuz-*' -type f -not -name '*.dpkg-tmp' -print0 | sort -Vrz"
- while IFS= read -r -u3 -d $'\0' LINE; do
- KERNEL=$(basename "${LINE}")
- KERNELS+=("${KERNEL:8}")
- done 3< <(eval "${FIND}")
- # There has to be at least one kernel.
- if [ ${#KERNELS[@]} -lt 1 ]; then
- echo -e "\e[2msystemd-boot\e[0m \e[1;31mNo kernels found.\e[0m"
- exit 1
- fi
- # Perform a nuclear clean to ensure everything is always in
- # perfect sync.
- rm /boot/efi/loader/entries/*.conf
- rm -rf /boot/efi/ubuntu
- mkdir /boot/efi/ubuntu
- # Copy the latest kernel files to a consistent place so we can
- # keep using the same loader configuration.
- LATEST="${KERNELS[@]:0:1}"
- echo -e "\e[2msystemd-boot\e[0m \e[1;32m${LATEST}\e[0m"
- for FILE in config initrd.img System.map vmlinuz; do
- cp "/boot/${FILE}-${LATEST}" "/boot/efi/ubuntu/${FILE}"
- cat << EOF > /boot/efi/loader/entries/ubuntu.conf
- title Ubuntu
- linux /ubuntu/vmlinuz
- initrd /ubuntu/initrd.img
- options root=UUID=${UUID} rw
- EOF
- done
- # Copy any legacy kernels over too, but maintain their version-
- # based names to avoid collisions.
- if [ ${#KERNELS[@]} -gt 1 ]; then
- LEGACY=("${KERNELS[@]:1}")
- for VERSION in "${LEGACY[@]}"; do
- echo -e "\e[2msystemd-boot\e[0m \e[1;32m${VERSION}\e[0m"
- for FILE in config initrd.img System.map vmlinuz; do
- cp "/boot/${FILE}-${VERSION}" "/boot/efi/ubuntu/${FILE}-${VERSION}"
- cat << EOF > /boot/efi/loader/entries/ubuntu-${VERSION}.conf
- title Ubuntu ${VERSION}
- linux /ubuntu/vmlinuz-${VERSION}
- initrd /ubuntu/initrd.img-${VERSION}
- options root=UUID=${UUID} rw
- EOF
- done
- done
- fi
- # reset the boot order so "ubuntu" comes first. It's difficult to predict
- # other entry situations, so we'll just focus on this one goal. This assumes
- # that the ubuntu boot option is "active" (has an asterisk after it).
- curorder=`efibootmgr | grep ^BootOrder | cut -d" " -f2`
- ubuntu=`efibootmgr | grep " ubuntu$" | cut -c5-8`
- # remove the current ubuntu entry (3 ways) if present, and prepend ubuntu and trim more than 5th entry
- tmporder=`echo $curorder | sed "s/,$ubuntu,/,/" | sed "s/$ubuntu,//" | sed "s/,$ubuntu//" | sed "s/^/$ubuntu,/" | cut -d"," -f1-5`
- efibootmgr --bootorder $tmporder
- # Success!
- echo -e "\e[2m---\e[0m"
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement