如何让 grub2/opensuse 启动过程忽略非主磁盘上的 raid 分区?

如何让 grub2/opensuse 启动过程忽略非主磁盘上的 raid 分区?

我需要了解如何让 grub2/opensuse 启动过程忽略非主磁盘上的 raid 分区。我的系统有 /dev/sda 和 /dev/sdb,它们是从 grub2 启动 UEFI 的主磁盘和一系列辅助磁盘。它们看起来像这样:

NAME              MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
sda                 8:0    0 465.8G  0 disk  
├─sda1              8:1    0     2G  0 part  /boot/efi
└─sda2              8:2    0 463.8G  0 part  
  └─md0             9:0    0 463.8G  0 raid1 
    ├─system-root 254:0    0 455.8G  0 lvm   /
    └─system-swap 254:1    0     8G  0 lvm   [SWAP]
sdb                 8:16   0 465.8G  0 disk  
├─sdb1              8:17   0     2G  0 part  
└─sdb2              8:18   0 463.8G  0 part  
  └─md0             9:0    0 463.8G  0 raid1 
    ├─system-root 254:0    0 455.8G  0 lvm   /
    └─system-swap 254:1    0     8G  0 lvm   [SWAP]
sdc                 8:32   0   1.8T  0 disk  
├─sdc1              8:33   0   399M  0 part  
└─sdc2              8:34   0   1.8T  0 part  
sdd                 8:48   0   1.8T  0 disk  
├─sdd1              8:49   0   399M  0 part  
└─sdd2              8:50   0   1.8T  0 part  
sde                 8:64   0   1.8T  0 disk  
sdf                 8:80   0   1.8T  0 disk  

磁盘 /dev/sdc - /dev/sdf 是外部主机上运行的虚拟主机使用的磁盘。原因是外部主机充当路由器,而内部主机是加密的根服务器,可以通过 ssh 进入外部主机远程启动。外部主机没有根加密,但显然不托管任何关键数据。

问题在于磁盘 /dev/sdc - /dev/sdf 有 raid 分区(加密 + lvm 等),当外部系统启动时,它会尝试构建 raid 阵列、解密等。必须先解构这些 raid 阵列,然后才能启动虚拟主机。此外,当这些 raid 阵列上的卷无法解密时,启动会失败。

问题:如何设置 grub2 启动过程以忽略磁盘 /dev/sdc - /dev/sdf 上的分区并仅基于主磁盘 /dev/sda 和 /dev/sdb 设置系统。目标是自动启动,结构如上。

这是 /boot/grub2/grub.cfg

#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub2-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
if [ -f ${config_directory}/grubenv ]; then
  load_env -f ${config_directory}/grubenv
elif [ -s $prefix/grubenv ]; then
  load_env
fi

if [ "${env_block}" ] ; then
  load_env -f "${env_block}"
fi

if [ "${next_entry}" ] ; then
   set default="${next_entry}"
   set next_entry=
   save_env next_entry
   if [ "${env_block}" ] ; then
     save_env -f "${env_block}" next_entry
   fi
   set boot_once=true
else
   set default="${saved_entry}"
fi

if [ x"${feature_menuentry_id}" = xy ]; then
  menuentry_id_option="--id"
else
  menuentry_id_option=""
fi

export menuentry_id_option

if [ "${prev_saved_entry}" ]; then
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
fi

function savedefault {
  if [ -z "${boot_once}" ]; then
    saved_entry="${chosen}"
    save_env saved_entry
  fi
}

function load_video {
  if [ x$feature_all_video_module = xy ]; then
    insmod all_video
  else
    insmod efi_gop
    insmod efi_uga
    insmod ieee1275_fb
    insmod vbe
    insmod vga
    insmod video_bochs
    insmod video_cirrus
  fi
}

if [ x$feature_default_font_path = xy ] ; then
   font=unicode
else
insmod part_gpt
insmod part_gpt
insmod diskfilter
insmod mdraid1x
insmod lvm
insmod ext2
set root='lvmid/36Ndwy-2YD2-onbC-3fKp-BdXl-Kmra-aELGxs/Pt4neo-JhAd-I4G4-02S8-X8eb-5xeY-wRpDWz'
if [ x$feature_platform_search_hint = xy ]; then
  search --no-floppy --fs-uuid --set=root --hint='lvmid/36Ndwy-2YD2-onbC-3fKp-BdXl-Kmra-aELGxs/Pt4neo-JhAd-I4G4-02S8-X8eb-5xeY-wRpDWz'  95092080-6e02-43c0-8e97-730fd53cb61f
else
  search --no-floppy --fs-uuid --set=root 95092080-6e02-43c0-8e97-730fd53cb61f
fi
    font="/usr/share/grub2/unicode.pf2"
fi

if loadfont $font ; then
echo "Please press t to show the boot menu on this console"
  set gfxmode=auto
  load_video
  insmod gfxterm
  set locale_dir=$prefix/locale
  set lang=POSIX
  insmod gettext
fi
terminal_output gfxterm
insmod part_gpt
insmod part_gpt
insmod diskfilter
insmod mdraid1x
insmod lvm
insmod ext2
set root='lvmid/36Ndwy-2YD2-onbC-3fKp-BdXl-Kmra-aELGxs/Pt4neo-JhAd-I4G4-02S8-X8eb-5xeY-wRpDWz'
if [ x$feature_platform_search_hint = xy ]; then
  search --no-floppy --fs-uuid --set=root --hint='lvmid/36Ndwy-2YD2-onbC-3fKp-BdXl-Kmra-aELGxs/Pt4neo-JhAd-I4G4-02S8-X8eb-5xeY-wRpDWz'  95092080-6e02-43c0-8e97-730fd53cb61f
else
  search --no-floppy --fs-uuid --set=root 95092080-6e02-43c0-8e97-730fd53cb61f
fi
insmod gfxmenu
loadfont ($root)/boot/grub2/themes/openSUSE/DejaVuSans-Bold14.pf2
loadfont ($root)/boot/grub2/themes/openSUSE/DejaVuSans10.pf2
loadfont ($root)/boot/grub2/themes/openSUSE/DejaVuSans12.pf2
loadfont ($root)/boot/grub2/themes/openSUSE/ascii.pf2
insmod png
set theme=($root)/boot/grub2/themes/openSUSE/theme.txt
export theme
if [ x${boot_once} = xtrue ]; then
  set timeout=0
elif [ x$feature_timeout_style = xy ] ; then
  set timeout_style=menu
  set timeout=8
# Fallback normal timeout code in case the timeout_style feature is
# unavailable.
else
  set timeout=8
fi


### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/00_tuned ###
set tuned_params=""
### END /etc/grub.d/00_tuned ###

### BEGIN /etc/grub.d/10_linux ###
menuentry 'openSUSE LEAP 42.2'  --class opensuse --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-95092080-6e02-43c0-8e97-730fd53cb61f' {
        load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_gpt
        insmod part_gpt
        insmod diskfilter
        insmod mdraid1x
        insmod lvm
        insmod ext2
        set root='lvmid/36Ndwy-2YD2-onbC-3fKp-BdXl-Kmra-aELGxs/Pt4neo-JhAd-I4G4-02S8-X8eb-5xeY-wRpDWz'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint='lvmid/36Ndwy-2YD2-onbC-3fKp-BdXl-Kmra-aELGxs/Pt4neo-JhAd-I4G4-02S8-X8eb-5xeY-wRpDWz'  95092080-6e02-43c0-8e97-730fd53cb61f
        else
          search --no-floppy --fs-uuid --set=root 95092080-6e02-43c0-8e97-730fd53cb61f
        fi
        echo    'Loading Linux 4.4.27-2-default ...'
        linux   /boot/vmlinuz-4.4.27-2-default root=/dev/mapper/system-root  resume=/dev/system/swap splash=silent quiet showopts nomodeset
        echo    'Loading initial ramdisk ...'
        initrd  /boot/initrd-4.4.27-2-default
}
submenu 'Advanced options for openSUSE LEAP 42.2' --hotkey=1 $menuentry_id_option 'gnulinux-advanced-95092080-6e02-43c0-8e97-730fd53cb61f' {
        menuentry 'openSUSE LEAP 42.2, with Linux 4.4.27-2-default' --hotkey=2 --class opensuse --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.27-2-default-advanced-95092080-6e02-43c0-8e97-730fd53cb61f' {
                load_video
                set gfxpayload=keep
                insmod gzio
                insmod part_gpt
                insmod part_gpt
                insmod diskfilter
                insmod mdraid1x
                insmod lvm
                insmod ext2
                set root='lvmid/36Ndwy-2YD2-onbC-3fKp-BdXl-Kmra-aELGxs/Pt4neo-JhAd-I4G4-02S8-X8eb-5xeY-wRpDWz'
                if [ x$feature_platform_search_hint = xy ]; then
                  search --no-floppy --fs-uuid --set=root --hint='lvmid/36Ndwy-2YD2-onbC-3fKp-BdXl-Kmra-aELGxs/Pt4neo-JhAd-I4G4-02S8-X8eb-5xeY-wRpDWz'  95092080-6e02-43c0-8e97-730fd53cb61f
                else
                  search --no-floppy --fs-uuid --set=root 95092080-6e02-43c0-8e97-730fd53cb61f
                fi
                echo    'Loading Linux 4.4.27-2-default ...'
                linux   /boot/vmlinuz-4.4.27-2-default root=/dev/mapper/system-root  resume=/dev/system/swap splash=silent quiet showopts nomodeset
                echo    'Loading initial ramdisk ...'
                initrd  /boot/initrd-4.4.27-2-default
        }
}

### END /etc/grub.d/10_linux ###

### BEGIN /etc/grub.d/20_linux_xen ###

### END /etc/grub.d/20_linux_xen ###

### BEGIN /etc/grub.d/20_memtest86+ ###
### END /etc/grub.d/20_memtest86+ ###

### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
### END /etc/grub.d/40_custom ###

### BEGIN /etc/grub.d/50_bootcycle ###
# created for bootcycle detection
menuentry 'halt' {
        halt
}
### END /etc/grub.d/50_bootcycle ###

### BEGIN /etc/grub.d/80_suse_btrfs_snapshot ###
### END /etc/grub.d/80_suse_btrfs_snapshot ###

### BEGIN /etc/grub.d/90_persistent ###
### END /etc/grub.d/90_persistent ###

### BEGIN /etc/grub.d/95_textmode ###

    # On EFI systems we can only have graphics *or* serial, so allow the user
    # to switch between the two
    hiddenentry 'Text mode' --hotkey 't' {
        set textmode=true
        terminal_output console
    }
### END /etc/grub.d/95_textmode ###

请告诉我还有哪些其他信息可能有助于理解。

答案1

#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub2-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

这只是部分正确:你不应该修改它的原因只是因为它会被覆盖grub2-mkconfig。没有其他理由不手动创建它。你可以减少/boot/grub2/grub.cfg到只包含你需要的菜单项编写自己的配置文件

grub-mkconfig/etc/grub.d/40_custom确实有一些限制。虽然可以通过编辑或创建将额外的自定义菜单项添加到列表末尾 /boot/grub/custom.cfg,但更改菜单项的顺序或更改其标题可能需要对存储在中的 shell 脚本进行复杂的更改/etc/grub.d/。这可能会在未来得到改进。与此同时,grub.cfg鼓励那些认为直接编写更容易的人这样做(请参阅 启动, 和类似 Shell 的脚本) 并禁止其发行版提供的任何系统自动运行grub-mkconfig

创建的配置grub-mkconfig试图包含任何地方可检测到的所有内容,例如安装的每个内核等。但是,您的配置似乎更复杂,可能需要相对复杂的手动创建grub.cfg

相关内容