Grub2

如何在縮小的 RAID1 磁碟上安裝 GRUB2?

  • July 28, 2021

TL;DR: 嘗試在 RAID1 中的塊設備上安裝 GRUB2。卡在安裝引導載入程序。

目標

用更小的 SSD-s 替換 HDD-s。以下是我已採取的步驟:

# 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 上安裝引導載入程序?我面臨的錯誤:

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.

眼鏡

  • CentOS 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!

現在需要檢查一切是否正常 :)

--directory選項定義了從哪裡獲取grub2-installGRUB 組件文件,同時定義了將它們放在哪裡--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

引用自:https://unix.stackexchange.com/questions/660141