再次,这应该进入 EFI 分区:

再次,这应该进入 EFI 分区:
ubuntu@ubuntu:~$ lsblk -po NAME,SIZE,TYPE,FSTYPE,PARTLABEL
NAME          SIZE TYPE FSTYPE   PARTLABEL
/dev/loop0    1.9G loop squashfs 
/dev/loop1   27.1M loop squashfs 
/dev/loop2     55M loop squashfs 
/dev/loop3  240.8M loop squashfs 
/dev/loop4   62.1M loop squashfs 
/dev/loop5   49.8M loop squashfs 
/dev/sda    465.8G disk          
├─/dev/sda1   292M part vfat     CLR_BOOT
├─/dev/sda2   512M part swap     CLR_SWAP
├─/dev/sda3 108.6G part ext4     CLR_ROOT
├─/dev/sda4    16M part          Microsoft reserved partition
├─/dev/sda5    79G part ntfs     Basic data partition
└─/dev/sda6 277.4G part ntfs     Basic data partition
/dev/sdb     30.2G disk iso9660  
├─/dev/sdb1   2.5G part iso9660  
├─/dev/sdb2   3.9M part vfat     
└─/dev/sdb3  27.7G part ext4     
/dev/sr0     1024M rom           
ubuntu@ubuntu:~$ 

答案1

关注后本指南

# Everything in this tutorial should be done as root:
sudo -i

# Now hop on into the EFI partition root.
cd /boot/efi

# Configuration files will go here:
mkdir -p loader/entries

# And kernels will go here:
mkdir ubuntu

将以下内容输入/boot/efi/loader/loader.conf(将超时值更改为您想要的值)

default ubuntu
timeout 1
editor 0

把以下内容/etc/kernel/postinst.d/zz-update-systemd-boot 确保改变CHANGEME。

#!/bin/bash
#
# This is a simple kernel hook to populate the systemd-boot entries
# whenever kernels are added or removed.
#
       
# The UUID of your disk.
UUID="CHANGEME"

# The LUKS volume slug you want to use, which will result in the
# partition being mounted to /dev/mapper/CHANGEME.
VOLUME="CHANGEME"

# Any rootflags you wish to set.
ROOTFLAGS="CHANGEME"    

# Our kernels.
KERNELS=()
FIND="find /boot -maxdepth 1 -name 'vmlinuz-*' -type f -print0 | sort -rz"
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 GNOME
linux   /ubuntu/vmlinuz
initrd  /ubuntu/initrd.img
options cryptdevice=UUID=${UUID}:${VOLUME} root=/dev/mapper/${VOLUME} ro rootflags=${ROOTFLAGS}
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 GNOME ${VERSION}
linux   /ubuntu/vmlinuz-${VERSION}
initrd  /ubuntu/initrd.img-${VERSION}
options cryptdevice=UUID=${UUID}:${VOLUME} root=/dev/mapper/${VOLUME} ro rootflags=${ROOTFLAGS}
EOF
        done
    done
fi

# Success!
exit 0

如果您的设置很简单,您可能不需要任何 ROOTFLAGS 和 VOLUME,并且脚本中的相应行可能如下所示:options root=UUID=${UUID} ro

注意权限:

chown root: /etc/kernel/postinst.d/zz-update-systemd-boot
chmod 0755 /etc/kernel/postinst.d/zz-update-systemd-boot
cd /etc/kernel/postrm.d/ && ln -s ../postinst.d/zz-update-systemd-boot zz-update-systemd-boot
[ -d "/etc/initramfs/post-update.d" ] || mkdir -p /etc/initramfs/post-update.d
cd /etc/initramfs/post-update.d/ && ln -s ../../kernel/postinst.d/zz-update-systemd-boot zz-update-systemd-boot

然后你/boot/efi/loader/entries/ubuntu.conf看起来应该像这样(显然,你需要更改 UUID):

title   Ubuntu GNOME
linux   /ubuntu/vmlinuz
initrd  /ubuntu/initrd.img
options root=UUID=81c4bc1c-1a7e-4822-acae-220bbe572240 ro

查看 UUID

ubuntu@ubuntu:~$ lsblk -f
名称 FSTYPE 标签 UUID FSAVAIL FSUSE% 挂载点
loop0 squashfs 0 100% /rofs
loop1 squashfs 0 100% /snap/snapd/7264
loop2 squashfs 0 100% /snap/core18/1705
loop3 squashfs 0 100% /snap/gnome-3-34-1804/24
loop4 squashfs 0 100% /snap/gtk-common-themes/1
loop5 squashfs 0 100% /snap/snap-store/433
星展银行                                                                                        
─sda1 vfat 1A74-A270 113.2M 61% /media/ubuntu/1A74-A270
─sda2 交换 10842320-1286-413f-bf08-3e0ca76bcf2f [SWAP]
─sda3 ext4 81c4bc1c-1a7e-4822-acae-220bbe572240 87.6G 13% /media/ubuntu/81c4bc1c-1a
─sda4                                                                                     
─sda5 ntfs 80D47B63D47B59FC                                    
└─sda6 ntfs 路由器数据 4416017316016770                                    
sdb iso9660 Ubuntu 20.04 LTS amd64 2020-04-23-07-51-42-00                              
─sdb1 iso9660 Ubuntu 20.04 LTS amd64 2020-04-23-07-51-42-00 0 100% /cdrom
─sdb2 vfat 1AC3-20ED                                           
└─sdb3 ext4 可写 b8474e17-164a-4fb3-94ff-d4e68f2e1548 25.7G 0% /var/崩溃
sr0

查找当前内核并重新安装它以触发刚刚创建的钩子:sudo apt install --reinstall linux-image-5.13.0-22-generic

实际安装 systemd-boot 对于大多数人来说,安装只需一个命令:

再次,这应该进入 EFI 分区:

bootctl install --path=/boot/efi

要验证系统上安装的引导加载程序及其顺序,请运行:

efibootmgr

reboot

一旦一切正常,您就可以删除系统中的 grub

# Purge the packages.
apt-get purge grub*

# Purge any obsolete dependencies.
apt-get autoremove --purge

相关内容