在 debootstrap chroot 中安装和配置 grub

在 debootstrap chroot 中安装和配置 grub

我在引导加载方面有很大的知识差距,这就是为什么我实际上正在练习边做边学。我有一个专用的测试服务器,并尝试使用 debootstrap 通过 hetznerrescue 安装 linux。 (写成bash脚本)

我的问题是,我不知道如何为 UEFI/GPT 正确安装 grub。我已经阅读了 ArchWiki 的相关内容:

https://wiki.archlinux.org/title/Installation_guide#
https://wiki.archlinux.org/title/Advanced_Format#
https://wiki.archlinux.org/title/Partitioning#
https://wiki.archlinux.org/title/GRUB

第一个错误是在安装固件 Linux 时出现的:

ln: failed to create hard link '/boot/initrd.img-6.1.0-13-amd64.dpkg-bak' => '/boot/initrd.img-6.1.0-13-amd64': Operation not permitted

那么我如何将 /boot 挂载到 chroot 的 / 中可能存在问题?

第二个问题是安装 grub 时的问题:

root@rescue:/# grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB
Installing for x86_64-efi platform.
grub-install: warning: efivarfs_get_variable: open(/sys/firmware/efi/efivars/blk0-47c7b225-c42a-11d2-8e57-00a0c969723b): No such file or directory.
grub-install: warning: efi_get_variable: ops->get_variable failed: No such file or directory.
grub-install: warning: efi_va_generate_file_device_path_from_esp: could not open device for ESP: Bad address.
grub-install: warning: efi_generate_file_device_path_from_esp: could not generate File DP from ESP: Bad address.
grub-install: error: failed to register the EFI boot entry: Bad address.

这是我正在执行的完整步骤:($disk_list/$disk是 /dev/nvme0n1 和 /dev/nvme1n1)

parted -s $disk mklabel gpt
parted -s $disk mkpart primary fat32 1M 1024M
parted -s $disk mkpart primary linux-swap 1025M 5120M
parted -s $disk mkpart primary ext4 5121M 100%

mdadm --create /dev/md0 --metadata=0.90 --level=1 --raid-devices=2 /dev/nvme0n1p1 /dev/nvme1n1p1
mkfs.fat -F32 /dev/md0

mkswap /dev/nvme0n1p2
mkswap /dev/nvme1n1p2

mdadm --create /dev/md2 --level=1 --raid-devices=2 /dev/nvme0n1p3 /dev/nvme1n1p3
mkfs.ext4 /dev/md2

mount --mkdir /dev/md2 /mnt/md2
mount --mkdir /dev/md0 /mnt/md2/boot

debootstrap --arch amd64 --include=linux-image-amd64,locales,locales-all,bash-completion,pwgen,htop,sudo,screen,rsync,ncdu,openssh-server,openssh-client,iotop,zip,unzip,zstd,mdadm,initramfs-tools bookworm /mnt/md2 https://deb.debian.org/debian

mount --make-rslave --rbind /proc /mnt/md2/proc
mount --make-rslave --rbind /sys /mnt/md2/sys
mount --make-rslave --rbind /dev /mnt/md2/dev
mount --make-rslave --rbind /run /mnt/md2/run

/etc/fstab
UUID=UUID-of-/dev/md0 /boot vfat defaults 0 2
UUID=UUID-of-/dev/nvme0n1p2 none swap sw 0 0
UUID=UUID-of-/dev/nvme1n1p2 none swap sw 0 0
UUID=UUID-of-/dev/md2 / ext4 defaults 0 1

sources.list
deb http://deb.debian.org/debian bookworm main non-free-firmware
deb-src http://deb.debian.org/debian bookworm main non-free-firmware
deb http://deb.debian.org/debian-security/ bookworm-security main non-free-firmware
deb-src http://deb.debian.org/debian-security/ bookworm-security main non-free-firmware
deb http://deb.debian.org/debian bookworm-updates main non-free-firmware
deb-src http://deb.debian.org/debian bookworm-updates main non-free-firmware

chroot /mnt/md2 /bin/bash
export TMPDIR="/tmp"
localectl set-locale LANG=de_DE.UTF-8 && \
timedatectl set-timezone UTC && \
apt-get update && \
apt-get upgrade -y && \
apt-get install firmware-linux && \
apt-get install grub-common grub-efi-amd64 os-prober -y && \
grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB

有人可以看一下并解释我做错了什么或缺少什么吗?

相关内容