Grub:从 CD-ROM 启动,然后继续从 SD 卡启动?

Grub:从 CD-ROM 启动,然后继续从 SD 卡启动?

我的问题与Grub:使用 USB 盘启动,然后继续从 SD 卡启动?除此之外,我正在尝试创建一个 grub iso 文件,稍后我会将其刻录到 CD 上,这应该是我启动 Linux 的方式。

我对 grub 和内核有点新手,我不确定是否可以从 CD 启动安装在 SDCard 上的 Ubuntu。

到目前为止,我尝试的是从我的 SDCard 上的 LiveUSB 安装 Ubuntu,其中分区如下所示:

Ubuntu分区

其次,基于这个线程:https://www.linuxquestions.org/questions/linux-general-1/creating-a-grub2-boot-cd-with-a-grub-cfg-menu-my-solution-754835/我能够创建一个 grub iso 文件,我可以通过 Brasero 将其刻录到 CD。我认为问题可能出在这里,因为我刚刚从 /dev/sdb5 复制了启动文件夹,这是安装的 Ubuntu 的根 (/) 分区,然后我运行了命令:

grub-mkrescue --modules="linux ext2 fshelp ls boot pc" --output=grub2-boot.iso ~/Desktop/boot

然而,运行上面的命令后,我得到:

grub-mkrescue: error: cannot open `/usr/lib/grub/i386-pc/pc.mod': No such file or directory.

我对这个问题进行了一些研究,并且可能正在运行它的修复程序

sudo apt-get install grub-pc-bin

但它没有创建 pc.mod 所以我从命令中删除了该模块(同样,我不确定我到底在做什么以及 pc 模块应该做什么)。

最后,当我重新启动系统时,我发现 grub 是从 CD 启动的,但问题是(至少其中之一)在 grub 中执行“ls”时,我的 grub.cfg 中的 (hd1,msdos5) 不会出现。唯一可用的文件系统是 (cd1) (cd1,msdos1),我认为这可能与启动阶段不存在的 SDCard 读卡器驱动程序有关。不知何故,该解决方案将在 grub iso 中集成 SDCard 驱动程序,但我不确定这是否可行。

这是 /dev/sdb5 启动文件夹中的完整 grub.cfg,它安装为 /media/ca8dc83c-7795-4dbd-8ee9-3e59ec526e6d (我认为是 UUID):

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

### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
  set have_grubenv=true
  load_env
fi
if [ "${next_entry}" ] ; then
   set default="${next_entry}"
   set next_entry=
   save_env next_entry
   set boot_once=true
else
   set default="0"
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 recordfail {
  set recordfail=1
  if [ -n "${have_grubenv}" ]; then if [ -z "${boot_once}" ]; then save_env recordfail; fi; 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_msdos
insmod ext2
set root='hd1,msdos5'
if [ x$feature_platform_search_hint = xy ]; then
  search --no-floppy --fs-uuid --set=root --hint-bios=hd1,msdos5 --hint-efi=hd1,msdos5 --hint-baremetal=ahci1,msdos5  ca8dc83c-7795-4dbd-8ee9-3e59ec526e6d
else
  search --no-floppy --fs-uuid --set=root ca8dc83c-7795-4dbd-8ee9-3e59ec526e6d
fi
    font="/usr/share/grub/unicode.pf2"
fi

if loadfont $font ; then
  set gfxmode=auto
  load_video
  insmod gfxterm
  set locale_dir=$prefix/locale
  set lang=en_US
  insmod gettext
fi
terminal_output gfxterm
if [ "${recordfail}" = 1 ] ; then
  set timeout=30
else
  if [ x$feature_timeout_style = xy ] ; then
    set timeout_style=hidden
    set timeout=0
  # Fallback hidden-timeout code in case the timeout_style feature is
  # unavailable.
  elif sleep --interruptible 0 ; then
    set timeout=0
  fi
fi
### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/05_debian_theme ###
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
if background_color 44,0,30,0; then
  clear
fi
### END /etc/grub.d/05_debian_theme ###

### BEGIN /etc/grub.d/10_linux ###
function gfxmode {
    set gfxpayload="${1}"
    if [ "${1}" = "keep" ]; then
        set vt_handoff=vt.handoff=1
    else
        set vt_handoff=
    fi
}
if [ "${recordfail}" != 1 ]; then
  if [ -e ${prefix}/gfxblacklist.txt ]; then
    if hwmatch ${prefix}/gfxblacklist.txt 3; then
      if [ ${match} = 0 ]; then
        set linux_gfx_mode=keep
      else
        set linux_gfx_mode=text
      fi
    else
      set linux_gfx_mode=text
    fi
  else
    set linux_gfx_mode=keep
  fi
else
  set linux_gfx_mode=text
fi
export linux_gfx_mode
menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-ca8dc83c-7795-4dbd-8ee9-3e59ec526e6d' {
    recordfail
    load_video
    gfxmode $linux_gfx_mode
    insmod gzio
    if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
    insmod part_msdos
    insmod ext2
    set root='hd1,msdos5'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd1,msdos5 --hint-efi=hd1,msdos5 --hint-baremetal=ahci1,msdos5  ca8dc83c-7795-4dbd-8ee9-3e59ec526e6d
    else
      search --no-floppy --fs-uuid --set=root ca8dc83c-7795-4dbd-8ee9-3e59ec526e6d
    fi
        linux   /boot/vmlinuz-5.4.0-122-generic root=UUID=ca8dc83c-7795-4dbd-8ee9-3e59ec526e6d ro  quiet splash $vt_handoff
    initrd  /boot/initrd.img-5.4.0-122-generic
}
submenu 'Advanced options for Ubuntu' $menuentry_id_option 'gnulinux-advanced-ca8dc83c-7795-4dbd-8ee9-3e59ec526e6d' {
    menuentry 'Ubuntu, with Linux 5.4.0-122-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-122-generic-advanced-ca8dc83c-7795-4dbd-8ee9-3e59ec526e6d' {
        recordfail
        load_video
        gfxmode $linux_gfx_mode
        insmod gzio
        if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
        insmod part_msdos
        insmod ext2
        set root='hd1,msdos5'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd1,msdos5 --hint-efi=hd1,msdos5 --hint-baremetal=ahci1,msdos5  ca8dc83c-7795-4dbd-8ee9-3e59ec526e6d
        else
          search --no-floppy --fs-uuid --set=root ca8dc83c-7795-4dbd-8ee9-3e59ec526e6d
        fi
        echo    'Loading Linux 5.4.0-122-generic ...'
            linux   /boot/vmlinuz-5.4.0-122-generic root=UUID=ca8dc83c-7795-4dbd-8ee9-3e59ec526e6d ro  quiet splash $vt_handoff
        echo    'Loading initial ramdisk ...'
        initrd  /boot/initrd.img-5.4.0-122-generic
    }
    menuentry 'Ubuntu, with Linux 5.4.0-122-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-122-generic-recovery-ca8dc83c-7795-4dbd-8ee9-3e59ec526e6d' {
        recordfail
        load_video
        insmod gzio
        if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
        insmod part_msdos
        insmod ext2
        set root='hd1,msdos5'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd1,msdos5 --hint-efi=hd1,msdos5 --hint-baremetal=ahci1,msdos5  ca8dc83c-7795-4dbd-8ee9-3e59ec526e6d
        else
          search --no-floppy --fs-uuid --set=root ca8dc83c-7795-4dbd-8ee9-3e59ec526e6d
        fi
        echo    'Loading Linux 5.4.0-122-generic ...'
            linux   /boot/vmlinuz-5.4.0-122-generic root=UUID=ca8dc83c-7795-4dbd-8ee9-3e59ec526e6d ro recovery nomodeset dis_ucode_ldr 
        echo    'Loading initial ramdisk ...'
        initrd  /boot/initrd.img-5.4.0-122-generic
    }
    menuentry 'Ubuntu, with Linux 5.4.0-42-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-42-generic-advanced-ca8dc83c-7795-4dbd-8ee9-3e59ec526e6d' {
        recordfail
        load_video
        gfxmode $linux_gfx_mode
        insmod gzio
        if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
        insmod part_msdos
        insmod ext2
        set root='hd1,msdos5'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd1,msdos5 --hint-efi=hd1,msdos5 --hint-baremetal=ahci1,msdos5  ca8dc83c-7795-4dbd-8ee9-3e59ec526e6d
        else
          search --no-floppy --fs-uuid --set=root ca8dc83c-7795-4dbd-8ee9-3e59ec526e6d
        fi
        echo    'Loading Linux 5.4.0-42-generic ...'
            linux   /boot/vmlinuz-5.4.0-42-generic root=UUID=ca8dc83c-7795-4dbd-8ee9-3e59ec526e6d ro  quiet splash $vt_handoff
        echo    'Loading initial ramdisk ...'
        initrd  /boot/initrd.img-5.4.0-42-generic
    }
    menuentry 'Ubuntu, with Linux 5.4.0-42-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-42-generic-recovery-ca8dc83c-7795-4dbd-8ee9-3e59ec526e6d' {
        recordfail
        load_video
        insmod gzio
        if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
        insmod part_msdos
        insmod ext2
        set root='hd1,msdos5'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd1,msdos5 --hint-efi=hd1,msdos5 --hint-baremetal=ahci1,msdos5  ca8dc83c-7795-4dbd-8ee9-3e59ec526e6d
        else
          search --no-floppy --fs-uuid --set=root ca8dc83c-7795-4dbd-8ee9-3e59ec526e6d
        fi
        echo    'Loading Linux 5.4.0-42-generic ...'
            linux   /boot/vmlinuz-5.4.0-42-generic root=UUID=ca8dc83c-7795-4dbd-8ee9-3e59ec526e6d ro recovery nomodeset dis_ucode_ldr 
        echo    'Loading initial ramdisk ...'
        initrd  /boot/initrd.img-5.4.0-42-generic
    }
}

### 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+ ###
menuentry 'Memory test (memtest86+)' {
    insmod part_msdos
    insmod ext2
    set root='hd1,msdos5'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd1,msdos5 --hint-efi=hd1,msdos5 --hint-baremetal=ahci1,msdos5  ca8dc83c-7795-4dbd-8ee9-3e59ec526e6d
    else
      search --no-floppy --fs-uuid --set=root ca8dc83c-7795-4dbd-8ee9-3e59ec526e6d
    fi
    knetbsd /boot/memtest86+.elf
}
menuentry 'Memory test (memtest86+, serial console 115200)' {
    insmod part_msdos
    insmod ext2
    set root='hd1,msdos5'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd1,msdos5 --hint-efi=hd1,msdos5 --hint-baremetal=ahci1,msdos5  ca8dc83c-7795-4dbd-8ee9-3e59ec526e6d
    else
      search --no-floppy --fs-uuid --set=root ca8dc83c-7795-4dbd-8ee9-3e59ec526e6d
    fi
    linux16 /boot/memtest86+.bin console=ttyS0,115200n8
}
### END /etc/grub.d/20_memtest86+ ###

### BEGIN /etc/grub.d/30_os-prober ###
### END /etc/grub.d/30_os-prober ###

### BEGIN /etc/grub.d/30_uefi-firmware ###
### END /etc/grub.d/30_uefi-firmware ###

### 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/41_custom ###
if [ -f  ${config_directory}/custom.cfg ]; then
  source ${config_directory}/custom.cfg
elif [ -z "${config_directory}" -a -f  $prefix/custom.cfg ]; then
  source $prefix/custom.cfg;
fi
### END /etc/grub.d/41_custom ###

谢谢你的时间!

答案1

我想我设法解决了我的问题,似乎 /boot 中所有需要的文件都位于 grub 中

ls /

现在我面临的是每次我都必须输入 grub

linux /vmlinuz-5.4.0-122-generic root=/dev/sda5
initrd /initrd.img-5.4.0-122-generic
boot

以便在 Ubuntu 中启动。有什么办法可以让我自动完成这一步吗?也许在 grub.cfg 中添加这些命令并制作一个新的 iso?

相关内容