修复 Grub 安装失败

修复 Grub 安装失败

我正在尝试修复惠普的拙劣安装。他们为笔记本电脑配备了 Ubuntu 14.04LTS,而我刚拿到它时没有足够的智慧删除并重新安装整个系统。

我遇到的主要问题是 /boot 分区和文件系统只有 200MB,而 Ubuntu 需要 100MB 用于当前内核,需要 100MB+ 用于下一个更新的内核,所以我的 Ubuntu 系统更新停止了工作。

我刻录了一张 Knoppix 7.6 DVD,以帮助我重新分区和重新排列内容以获得更大的分区。我能够成功将 /、/home 和交换分区(HP 预装)移动到 LVM 卷组中。这是成功的,并且可以使用新的 /、/home 和交换 LV 成功启动。

接下来,我尝试将现有的 /boot 分区扩大到 2 GB,这很有效,但 Knoppix 不会扩大其下的 fat32 文件系统。因此,我删除了它(首先备份它),并在其自己的分区(不是 LVM 的一部分)中将其重新创建为 2G ext4 文件系统。

现在,我无法让 grub 工作。事实上,我可以启动 Knoppix,但笔记本电脑固件似乎根本看不到 grub(“未找到操作系统”错误消息)。它表现得好像我没有安装操作系统。然而,在 Knoppix 下,grub 似乎已安装。

我正在按照这里的说明进行操作(http://howtoubuntu.org/how-to-repair-restore-reinstall-grub-2-with-a-ubuntu-live-cd),因此我将 lvm vg1-root 挂载为 /media/root,将 /dev/sda1 挂载为 /media/root/boot。然后我将 dev、dev/pts、proc 和 sys 挂载在 /media/root 下。最后我将 chroot 到 /media/root。

现在,当我运行 grub-install(在 chrooted 窗口中以 root 身份运行)和 grub-install --recheck 时,我得到:

root@Microknoppix:/# grub-install /dev/sda
Installing for i386-pc platform.
Installation finished. No error reported.
root@Microknoppix:/# grub-install --recheck /dev/sda
Installing for i386-pc platform.
Installation finished. No error reported.

检查生成的 /boot/grub/grub.cfg 文件,所有 UUID 引用都与 blkid 的预期相符。当然,启动似乎还没有进行到那一步。笑笑:

knoppix@Microknoppix:~$ sudo blkid
/dev/cloop0: UUID="2016-01-20-01-28-35-89" LABEL="KNOPPIX_FS" TYPE="iso9660"
/dev/cloop1: UUID="2015-12-30-05-31-30-00" LABEL="KNOPPIX_FS1" TYPE="iso9660"
/dev/zram0: UUID="d006c8b0-f899-48f1-a7d1-2327b72126f0" TYPE="swap"
/dev/sda1: LABEL="BOOT" UUID="5bd116ab-46ef-4b4e-ac70-711cd0085a55" TYPE="ext4" PARTUUID="64a7963a-01"
/dev/sda4: SEC_TYPE="msdos" LABEL="HP_TOOLS" UUID="7930-F46B" TYPE="vfat" PARTUUID="64a7963a-04"
/dev/sda5: LABEL="LINUX_OLD" UUID="d519b0f8-e1a4-443b-975c-8df2af1def4e" TYPE="ext4" PARTUUID="64a7963a-05"
/dev/sda6: UUID="dxe30Q-xL3c-AzwH-ZPyy-Z2rv-4z3R-Y2LY2T" TYPE="LVM2_member" PARTUUID="64a7963a-06"
/dev/sr0: UUID="2016-01-24-15-29-37-00" LABEL="KNOPPIX" TYPE="iso9660"
/dev/mapper/vg1-home: LABEL="HOME" UUID="503b3f2f-77b1-40c2-a064-c4fe34980b69" TYPE="ext4"
/dev/mapper/vg1-root: LABEL="LINUX" UUID="f55ffea3-bf95-435a-bb3f-d0123f1822d7" TYPE="ext4"
/dev/mapper/vg1-swap: LABEL="SWAP" UUID="79b246cb-2ac3-4152-97c7-b3b8e009d33e" TYPE="swap"

以下是生成的 /boot/grub/grub.cfg:

#
# 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 lvm
insmod ext2
set root='lvmid/nFNWNq-E4w8-3z7b-IuV2-2F6T-z0Mu-GqxJHK/5vOz1c-nclp-Qee2-PGjc-oXFP-Skav-K2wend'
if [ x$feature_platform_search_hint = xy ]; then
  search --no-floppy --fs-uuid --set=root --hint='lvmid/nFNWNq-E4w8-3z7b-IuV2-2F6T-z0Mu-GqxJHK/5vOz1c-nclp-Qee2-PGjc-oXFP-Skav-K2wend'  f55ffea3-bf95-435a-bb3f-d0123f1822d7
else
  search --no-floppy --fs-uuid --set=root f55ffea3-bf95-435a-bb3f-d0123f1822d7
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=5
else
  if [ x$feature_timeout_style = xy ] ; then
    set timeout_style=hidden
    set timeout=3
  # Fallback hidden-timeout code in case the timeout_style feature is
  # unavailable.
  elif sleep --interruptible 3 ; 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
### END /etc/grub.d/05_debian_theme ###

### BEGIN /etc/grub.d/10_linux ###
if [ ! -d /boot/efi ]; then
if hwmatch /boot/grub/nomodesetsystemlist.txt 3; then
if [ ${match} != 0 ]; then
set nomodeset="nomodeset"
fi
fi
fi
function gfxmode {
    set gfxpayload="${1}"
    if [ "${1}" = "keep" ]; then
        set vt_handoff=vt.handoff=7
    else
        set vt_handoff=
    fi
}
set linux_gfx_mode=keep
export linux_gfx_mode
menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-f55ffea3-bf95-435a-bb3f-d0123f1822d7' {
    recordfail
    load_video
    gfxmode $linux_gfx_mode
    insmod gzio
    insmod part_msdos
    insmod ext2
    set root='hd0,msdos1'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  5bd116ab-46ef-4b4e-ac70-711cd0085a55
    else
      search --no-floppy --fs-uuid --set=root 5bd116ab-46ef-4b4e-ac70-711cd0085a55
    fi
    linux   /vmlinuz-4.2.0-35-generic root=/dev/mapper/vg1-root ro   quiet splash pciehp.pciehp_force=1 radeon.modeset=0 nouveau.modeset=0 $vt_handoff $nomodeset
    initrd  /initrd.img-4.2.0-35-generic
}
submenu 'Advanced options for Ubuntu' $menuentry_id_option 'gnulinux-advanced-f55ffea3-bf95-435a-bb3f-d0123f1822d7' {
    menuentry 'Ubuntu, with Linux 4.2.0-35-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.2.0-35-generic-advanced-f55ffea3-bf95-435a-bb3f-d0123f1822d7' {
        recordfail
        load_video
        gfxmode $linux_gfx_mode
        insmod gzio
        insmod part_msdos
        insmod ext2
        set root='hd0,msdos1'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  5bd116ab-46ef-4b4e-ac70-711cd0085a55
        else
          search --no-floppy --fs-uuid --set=root 5bd116ab-46ef-4b4e-ac70-711cd0085a55
        fi
        echo    'Loading Linux 4.2.0-35-generic ...'
        linux   /vmlinuz-4.2.0-35-generic root=/dev/mapper/vg1-root ro   quiet splash pciehp.pciehp_force=1 radeon.modeset=0 nouveau.modeset=0 $vt_handoff $nomodeset
        echo    'Loading initial ramdisk ...'
        initrd  /initrd.img-4.2.0-35-generic
    }
    menuentry 'Ubuntu, with Linux 4.2.0-35-generic (safe mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.2.0-35-generic-recovery-f55ffea3-bf95-435a-bb3f-d0123f1822d7' {
        recordfail
        load_video
        insmod gzio
        insmod part_msdos
        insmod ext2
        set root='hd0,msdos1'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  5bd116ab-46ef-4b4e-ac70-711cd0085a55
        else
          search --no-floppy --fs-uuid --set=root 5bd116ab-46ef-4b4e-ac70-711cd0085a55
        fi
        echo    'Loading Linux 4.2.0-35-generic ...'
        linux   /vmlinuz-4.2.0-35-generic root=/dev/mapper/vg1-root ro recovery nomodeset 
        echo    'Loading initial ramdisk ...'
        initrd  /initrd.img-4.2.0-35-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='hd0,msdos1'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  5bd116ab-46ef-4b4e-ac70-711cd0085a55
    else
      search --no-floppy --fs-uuid --set=root 5bd116ab-46ef-4b4e-ac70-711cd0085a55
    fi
    knetbsd /memtest86+.elf
}
menuentry 'Memory test (memtest86+, serial console 115200)' {
    insmod part_msdos
    insmod ext2
    set root='hd0,msdos1'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  5bd116ab-46ef-4b4e-ac70-711cd0085a55
    else
      search --no-floppy --fs-uuid --set=root 5bd116ab-46ef-4b4e-ac70-711cd0085a55
    fi
    linux16 /memtest86+.bin console=ttyS0,115200n8
}
### END /etc/grub.d/20_memtest86+ ###

我也检查了 EFI,但 /sys/firmware/efi* 不存在(这是 HP zBook15)。

我没什么主意了,而且我真的不想因为无法正确安装 grub 而毁掉整个系统。对于我遗漏了什么,有什么有用的想法吗?

更新 1

应该在我最初的问题中包含这个。以下是 update-grub 的输出:

root@Microknoppix:/# update-grub
Generating grub configuration file ...
  /dev/sda2: open failed: No such device or address
  /dev/sda7: open failed: No such device or address
  /dev/sda8: open failed: No such device or address
  /dev/sda2: open failed: No such device or address
  /dev/sda7: open failed: No such device or address
  /dev/sda8: open failed: No such device or address
  /dev/sda2: open failed: No such device or address
  /dev/sda7: open failed: No such device or address
  /dev/sda8: open failed: No such device or address
  /dev/sda2: open failed: No such device or address
  /dev/sda7: open failed: No such device or address
  /dev/sda8: open failed: No such device or address
  /dev/sda2: open failed: No such device or address
  /dev/sda7: open failed: No such device or address
  /dev/sda8: open failed: No such device or address
  /dev/sda2: open failed: No such device or address
  /dev/sda7: open failed: No such device or address
  /dev/sda8: open failed: No such device or address
  /dev/sda2: open failed: No such device or address
  /dev/sda7: open failed: No such device or address
  /dev/sda8: open failed: No such device or address
  /dev/sda2: open failed: No such device or address
  /dev/sda7: open failed: No such device or address
  /dev/sda8: open failed: No such device or address
Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
  /dev/sda2: open failed: No such device or address
  /dev/sda7: open failed: No such device or address
  /dev/sda8: open failed: No such device or address
  /dev/sda2: open failed: No such device or address
  /dev/sda7: open failed: No such device or address
  /dev/sda8: open failed: No such device or address
Found linux image: /boot/vmlinuz-4.2.0-35-generic
Found initrd image: /boot/initrd.img-4.2.0-35-generic
  /dev/sda2: open failed: No such device or address
  /dev/sda7: open failed: No such device or address
  /dev/sda8: open failed: No such device or address
  /dev/sda2: open failed: No such device or address
  /dev/sda7: open failed: No such device or address
  /dev/sda8: open failed: No such device or address
Found memtest86+ image: /memtest86+.elf
Found memtest86+ image: /memtest86+.bin
done

/dev/sda2、7 和 8 都是我已删除的分区。

这是我的 fdisk 输出:

root@Microknoppix:/# fdisk -l

Disk /dev/sda: 512.1 GB, 512110190592 bytes
255 heads, 63 sectors/track, 62260 cylinders, total 1000215216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x64a7963a

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     4196351     2097152   83  Linux
/dev/sda3         8802304   999215103   495206400    f  W95 Ext'd (LBA)
/dev/sda4       999215104  1000214527      499712    c  W95 FAT32 (LBA)
/dev/sda5       911216640   991215615    39999488   83  Linux
/dev/sda6         8804352   911214591   451205120   8e  Linux LVM

Partition table entries are not in disk order

Disk /dev/mapper/vg1-home: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders, total 419430400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/vg1-home doesn't contain a valid partition table

Disk /dev/mapper/vg1-root: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders, total 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/vg1-root doesn't contain a valid partition table

Disk /dev/mapper/vg1-swap: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders, total 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/vg1-swap doesn't contain a valid partition table

答案1

检查事项:

  • 将启动选项从 UEFI 切换为 Normal
  • 检查启动设备列表和顺序
  • 确保 GRUB 菜单没有被隐藏(您可以在启动时按住箭头键)

答案2

所以我在第一个分区中添加了启动标志(是的,那个过时的标志),这似乎已经解决了问题。我们怀疑 BIOS 在检查 MBR 以查找启动加载程序之前,已经在分区表中的某个地方寻找它。

有些东西永远不会消亡......

相关内容