如何在缩小的 RAID1 磁盘上安装 GRUB2?

如何在缩小的 RAID1 磁盘上安装 GRUB2?

长话短说: 尝试在 RAID1 中的块设备上安装 GRUB2。卡在安装引导加载程序上。

目标

用较小的 SSD 替换 HDD。以下是我已采取的步骤:

# Booted into rescue mode 
# failed and removed the partition from md array
mdadm --manage /dev/md1 -f /dev/sdb2
mdadm --manage /dev/md1 -r /dev/sdb2

# took out the HDD
# shrunk the filesystem and then the md
resize2fs -f /dev/md1 85G
mdadm --grow /dev/md1 -z 88G

# md1 mounted fine, no issues there. Didn't try to mount /dev/sdd2, as it's Linux RAID type
# recreated partitions on SSD as they are on HDD

# added to array
mdadm --add /dev/md1 /dev/sdb2

# waited for the sync to finish.
# recreated partitions on second SSD
# removed remaining HDD once synced, added SSD to array

gdisk -l

Partition table scan:
  MBR: protective
  GPT: present

Disk label type: GPT
#    Start          End    Size          Type
1     2048         6143      2M      Linux fs
2     6144    195371534   93.2G    Linux RAID

问题

如何在 SSD-s 上安装 Bootloader?我面临的错误:

grub2-install --directory /mnt/sysimage/boot/grub2/i386-pc /dev/sdd
Installing for i386-pc platform.
grub2-install error: cannot open `/mnt/sysimage/boot/grub2/i386-pc/kernel.img': No such file or directory.

眼镜

  • 操作系统7
  • mdadm v4.1
  • 无LVM

编辑:添加了gdisk -l修剪输出

更新#1

mount --bind-ing/{proc,dev,sys}并运行后grub2-install,出现以下错误。也许我配置错误了?

grub2-install: warning: Couldn't find physical volume `(null)'. Some modules may be missing from core image.. (2x)
grub2-install: warning: this GPT partition label contains no BIOS Boot Partition; embedding won't be psosible.
grub2-install: error: embedding is not possible, but this is rquired for RAID and LVM install.

更新#2

咨询后手册 grub2-install成功了!

为了子孙后代,我做了什么:

gdisk /dev/sdd
# t - changed partition 1 type to ef02 -- BIOS boot partition
chroot /mnt/sysimage/
grub2-install /dev/sdd
# grub2-install warned about not finding physical volume `(null)' but installation finished without any errors.
# added to md, failed, removed the other disk, repeated grub2-install

服务器启动!感谢您的时间和指导,@telcoM!

现在需要检查一切是否正常:)

答案1

--directory选项定义grub2-installGRUB 组件文件的位置, while--boot-directory定义了它们的放置位置

设置救援 chroot 比键入直接从救援环境运行所需的所有长路径名要容易得多:除了 和 之外,您grub2-install可能还需要指定--grub-setup,--grub-mkrelpath和。所以:--grub-probe--directory--boot-directory

mount --rbind /dev /mnt/sysimage/dev
mount -t proc none /mnt/sysimage/proc
mount -t sysfs none /mnt/sysimage/sys
chroot /mnt/sysimage /bin/bash
grub2-install /dev/sdd

但如果你想按照自己的方式来做:(\为了可读性而标记行分割)

grub2-install --directory=/mnt/sysimage/usr/lib/grub/i386-pc \
    --grub-setup=/mnt/sysimage/usr/bin/grub2-setup \
    --grub-mkrelpath=/mnt/sysimage/usr/bin/grub2-mkrelpath \
    --grub-probe=/mnt/sysimage/usr/sbin/grub2-probe \
    --boot-directory=/mnt/sysimage/boot \
    /dev/sdd

相关内容