Ubuntu 被 os-prober 识别,但 grub 无法识别

Ubuntu 被 os-prober 识别,但 grub 无法识别

我正在双启动 Windows 7 和 Ubuntu 12.04。我使用 12.04 live CD 中的 gparted 缩小了 Windows 7 分区并增加了 Ubuntu 分区。大约一个星期内一切都很顺利。然后有一天我启动时遇到了“grub rescue”。我按照网上的许多教程清除并重新安装了 grub 和 grub2,但所有努力都得到了相同的结果:os-prober 似乎可以看到我的 2 个 Windows 7(实际和恢复)分区以及 Ubuntu 12.04 LTS 分区;但是当我运行任何版本的 update-grub 或 update-grub2 时,它只会检测到 2 个 Windows 7 分区。因此我无法启动到 Ubuntu(我的 99% 的工作都在这里进行)。以下是 bootinfoscript 的输出:

    Boot Info Script 0.61      [1 April 2012]


============================= Boot Info Summary: ===============================

 => Grub2 (v1.99) is installed in the MBR of /dev/sda and looks at sector 1 of 
    the same hard drive for core.img. core.img is at this location and looks 
    for (,msdos5)/boot/grub on this drive.

sda1: __________________________________________________________________________

    File system:       ntfs
    Boot sector type:  Windows Vista/7: NTFS
    Boot sector info:  No errors found in the Boot Parameter Block.
    Operating System:  
    Boot files:        /bootmgr /Boot/BCD

sda2: __________________________________________________________________________

    File system:       ntfs
    Boot sector type:  Windows Vista/7: NTFS
    Boot sector info:  No errors found in the Boot Parameter Block.
    Operating System:  Windows 7
    Boot files:        /bootmgr /Boot/BCD /Windows/System32/winload.exe

sda3: __________________________________________________________________________

    File system:       ntfs
    Boot sector type:  Windows Vista/7: NTFS
    Boot sector info:  No errors found in the Boot Parameter Block.
    Operating System:  
    Boot files:        

sda4: __________________________________________________________________________

    File system:       Extended Partition
    Boot sector type:  -
    Boot sector info: 

sda5: __________________________________________________________________________

    File system:       ext4
    Boot sector type:  Grub2 (v1.99)
    Boot sector info:  Grub2 (v1.99) is installed in the boot sector of sda5 
                       and looks at sector 525161552 of the same hard drive 
                       for core.img. core.img is at this location and looks 
                       for (,msdos5)/boot/grub on this drive.
    Operating System:  Ubuntu 12.04 LTS
    Boot files:        /boot/grub/grub.cfg /etc/fstab /boot/grub/core.img

sda6: __________________________________________________________________________

    File system:       
    Boot sector type:  -
    Boot sector info: 
    Mounting failed:   mount: unknown filesystem type ''

============================ Drive/Partition Info: =============================

Drive: sda _____________________________________________________________________

Disk /dev/sda: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders, total 625142448 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes

Partition  Boot  Start Sector    End Sector  # of Sectors  Id System

/dev/sda1               2,048       206,847       204,800   7 NTFS / exFAT / HPFS
/dev/sda2             206,848   504,360,959   504,154,112   7 NTFS / exFAT / HPFS
/dev/sda3         591,218,688   625,137,663    33,918,976   7 NTFS / exFAT / HPFS
/dev/sda4         504,360,960   591,218,687    86,857,728   5 Extended
/dev/sda5    *    504,363,008   583,360,511    78,997,504  83 Linux
/dev/sda6         583,362,560   591,218,687     7,856,128  82 Linux swap / Solaris


"blkid" output: ________________________________________________________________

Device           UUID                                   TYPE       LABEL

/dev/loop0                                              squashfs   
/dev/sda1        DA669D8C669D69D1                       ntfs       System Reserved
/dev/sda2        BAAAA703AAA6BAF1                       ntfs       
/dev/sda3        8E22D1E022D1CCF9                       ntfs       OS Recovery
/dev/sda5        c35e7a0a-408c-4586-8a18-b3faa368ef3f   ext4       
/dev/sr0                                                iso9660    Ubuntu 12.04 LTS amd64

================================ Mount points: =================================

Device           Mount_Point              Type       Options

/dev/loop0       /rofs                    squashfs   (ro,noatime)
/dev             /mnt/dev                 none       (rw,bind)
/dev/pts         /mnt/dev/pts             none       (rw,bind)
/dev/sda2        /media/BAAAA703AAA6BAF1  fuseblk    (rw,nosuid,nodev,allow_other,default_permissions,blksize=4096)
/dev/sda5        /media/c35e7a0a-408c-4586-8a18-b3faa368ef3f ext4       (rw,nosuid,nodev,uhelper=udisks)
/dev/sda5        /mnt                     ext4       (rw)
/dev/sr0         /cdrom                   iso9660    (ro,noatime)


=========================== sda5/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
set default="0"
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 {
  insmod vbe
  insmod vga
  insmod video_bochs
  insmod video_cirrus
}

insmod part_msdos
insmod ext2
set root='(hd0,msdos5)'
search --no-floppy --fs-uuid --set=root c35e7a0a-408c-4586-8a18-b3faa368ef3f
if loadfont /usr/share/grub/unicode.pf2 ; then
  set gfxmode=auto
  load_video
  insmod gfxterm
  insmod part_msdos
  insmod ext2
  set root='(hd0,msdos5)'
  search --no-floppy --fs-uuid --set=root c35e7a0a-408c-4586-8a18-b3faa368ef3f
  set locale_dir=($root)/boot/grub/locale
  set lang=en_US
  insmod gettext
fi
terminal_output gfxterm
if [ "${recordfail}" = 1 ]; then
  set timeout=-1
else
  set timeout=10
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; 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=7
    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
if [ "${linux_gfx_mode}" != "text" ]; then load_video; fi
### END /etc/grub.d/10_linux ###

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

### BEGIN /etc/grub.d/30_os-prober ###
menuentry "Windows 7 (loader) (on /dev/sda1)" --class windows --class os {
    insmod part_msdos
    insmod ntfs
    set root='(hd0,msdos1)'
    search --no-floppy --fs-uuid --set=root DA669D8C669D69D1
    chainloader +1
}
### END /etc/grub.d/30_os-prober ###

### 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  $prefix/custom.cfg ]; then
  source $prefix/custom.cfg;
fi
### END /etc/grub.d/41_custom ###
--------------------------------------------------------------------------------

=============================== sda5/etc/fstab: ================================

--------------------------------------------------------------------------------
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    nodev,noexec,nosuid 0       0
# / was on /dev/sda5 during installation
UUID=c35e7a0a-408c-4586-8a18-b3faa368ef3f /               ext4    errors=remount-ro 0       1
# swap was on /dev/sda6 during installation
#UUID=a4d335d5-6a81-4af8-a1c7-3beeee8699a1 none            swap    sw              0       0
/dev/mapper/cryptswap1 none swap sw 0 0
--------------------------------------------------------------------------------

=================== sda5: Location of files loaded by Grub: ====================

           GiB - GB             File                                 Fragment(s)

               =                boot/grub/core.img                             1
               =                boot/grub/grub.cfg                             1

========= Devices which don't seem to have a corresponding hard drive: =========

sdb 

=============================== StdErr Messages: ===============================

xz: (stdin): Compressed data is corrupt
xz: (stdin): Compressed data is corrupt
awk: cmd. line:36: Math support is not compiled in
awk: cmd. line:36: Math support is not compiled in

来自 12.04 LiveCD 的 sudo os-prober:

/dev/sda1:Windows 7 (loader):Windows:chain
/dev/sda2:Windows 7 (loader):Windows1:chain
/dev/sda5:Ubuntu 12.04 LTS (12.04):Ubuntu:linux

我几乎读完了所有关于更新 grub 版本的指南、教程和问题,但都无济于事。但最令人困惑的是 os-prober 看到了安装;如果能在这方面提供帮助,我将不胜感激。

答案1

您是否尝试过menuentry通过编辑添加“自定义”来启动 Ubuntu grub.cfg


我决定最好建议这个,因为即使它不起作用,也许它会产生更有用的错误消息。

  1. 使用 12.04 LiveCD 启动您的系统。

  2. 挂载sda5安装 Ubuntu 的分区。在此示例中,我假设使用sda5以下方式挂载/mnt:例如sudo mount -t ext4 /dev/sda5 /mnt

  3. 通过列出目录内容来确定您已安装哪些内核/mnt/boot。您将需要此信息来完成下面的步骤 (5)。
    笔记:下面的命令是执行此操作的一种方法。

    ls /mnt/boot/{initrd*,vmlinuz*}
    
  4. 用于sudo编辑文件/mnt/boot/grub/grub.cfg(即您的Ubuntu 分区grub.cfg上的文件)。sda5

  5. 在文件中找到以下行。它们应该位于文件末尾前约 10 行。

    ### 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 ###
    

    将上面的内容替换为下面的 GRUB 命令menuentry
    重要的:在下面的例子中必须将和行?.?.?-??中的值替换为您要启动的内核的版本号(来自步骤(3))。linuxinitrd

    ### BEGIN /etc/grub.d/40_custom ###
    menuentry 'Ubuntu on sda5' --class ubuntu --class gnu-linux --class gnu --class os {
      recordfail
      insmod gzio
      insmod part_msdos
      insmod ext2
      set root='(hd0,msdos5)'
      search --no-floppy --fs-uuid --set=root c35e7a0a-408c-4586-8a18-b3faa368ef3f
      linux /boot/vmlinuz-?.?.?-??-generic root=UUID=c35e7a0a-408c-4586-8a18-b3faa368ef3f ro quiet splash
      initrd    /boot/initrd.img-?.?.?-??-generic
    }
    ### END /etc/grub.d/40_custom ###
    
  6. 重新启动并查看此自定义条目是否允许您从 启动 Ubuntu /dev/sda5


如果上述建议有效,那么我建议尝试以下操作。

  • 使用sudo编辑文件/etc/grub.d/40_cutom并将步骤 (5) 中的菜单项命令附加到文件末尾。这样,运行 时菜单项就不会丢失update-grub

    警告:不是删除下面两行!它们必须位于文件的开头40_custom才能update-grub正常工作。

    #!/bin/sh
    exec tail -n +3 $0
    
  • 尝试使用以下命令再次重新安装 GRUB。(为什么不呢?)

    sudo grub-install --recheck /dev/sda
    

更新对缺少内核文件的评论的回应/boot


我从未遇到过内核文件丢失的情况/boot。我首先担心的是,如果您的内核文件丢失,那么安装在 上的 Ubuntu 可能存在其他严重问题sda5

我建议您更新您的问题及其标题,以反映 中没有内核文件/boot。这样做会增加您从其他人那里获得更好答案的机会。

我在 AskUnbuntu 上搜索了类似的问题,但我只找到了下面链接的问题。
意外删除所有内核后如何恢复系统?

这个问题的最佳答案是,chroot然后尝试重新安装您说已经尝试过的内核。我唯一能建议的改变是您使用这些命令再试一次。(注意:sudo下面没有使用,因为如果您chroot已经是root。)

apt-get update
apt-get --reinstall install linux-generic linux-image-generic linux-headers-generic
  • 笔记:如果上述方法有效,那么最安全的方法可能是运行
    grub-install --recheck /dev/sda

的手册页更新-initramfs也可能有助于提供关于内核“安装”时发生的情况的一些背景信息。

事后看来,我应该意识到阅读您的 BootInfo 摘要时出了点问题。它以下面的摘录结尾。

=================== sda5: Location of files loaded by Grub: ====================

           GiB - GB             File                                 Fragment(s)

               =                boot/grub/core.img                             1
               =                boot/grub/grub.cfg                             1

========= Devices which don't seem to have a corresponding hard drive: =========

sdb 

=============================== StdErr Messages: ===============================

xz: (stdin): Compressed data is corrupt
xz: (stdin): Compressed data is corrupt
awk: cmd. line:36: Math support is not compiled in
awk: cmd. line:36: Math support is not compiled in

但是,我本应看到类似下面的摘录,而不是上述的错误,我创建的 BootInfo 摘要作为示例

=================== sda5: Location of files loaded by Grub: ====================

           GiB - GB             File                                 Fragment(s)

  23.440826416 = 25.169395712   boot/grub/core.img                             1
  23.440864563 = 25.169436672   boot/grub/grub.cfg                             1
  18.791522980 = 20.177244160   boot/initrd.img-3.2.0-23-generic               1
  25.439197540 = 27.315130368   boot/vmlinuz-3.2.0-23-generic                  1
  18.791522980 = 20.177244160   initrd.img                                     1
  25.439197540 = 27.315130368   vmlinuz                                        1


ADDITIONAL INFORMATION :
=================== log of boot-repair 2012-06-13__16h58 ===================
boot-repair version : 3.18-0ppa25~precise
boot-sav version : 3.19-0ppa14~precise
glade2script version : 0.3.2.1-0ppa7~precise
boot-repair is executed in live-session (Ubuntu 12.04 LTS , precise , Ubuntu , x86_64)

=================== OSPROBER:
/dev/sda1:Windows 7 (loader):Windows:chain
/dev/sda5:Ubuntu 12.04 LTS (12.04):Ubuntu:linux

... et cetera ....

答案2

跑步Boot-Repair 的“推荐修复”。这将重新安装 GRUB 并重新安装内核(如果需要)。如果有任何问题,请指出将出现的 URL。

相关内容