使用 GRUB2 启动 Ubuntu:如何将启动项添加到 GRUB2?

Dav*_*ner 5 boot grub2 dual-boot 11.04 bootloader

昨晚,我决定冒险一试,安装 Ubuntu 作为我的双引导系统(使用 Windows 7)的免费部分。不幸的是,整个过程一直在艰难地进行,即正确配置引导加载程序。

简短的历史概要,以了解情况的全部背景:

  1. 在 Windows 7 机器上通过 USB 驱动器设置生成并安装 Ubuntu 11.04 x64。我什至无法启动安装程序,直到我了解到我无法使用我的 USB3.0 端口。切换到USB2.0端口,继续安装。

  2. 我有一个 1TB 的 HDD,为了双启动,我将它分成两半:500GB 分区用于 Windows 7,500GB 用于 Ubuntu(不包括启动/交换文件分区)。Ubuntu分区安装了ext4文件系统,安装完成没有任何明显问题,并提示重启。

  3. 重新启动后,我进入了旧的 Windows 引导加载程序,它立即启动了 Windows。我尝试了一个名为 EasyBCD 的实用程序,试图将 Linux 条目添加到我新安装的分区,但无济于事。

  4. 然后,我直接从 USB 驱动器启动 Ubuntu,并按照此处概述的步骤将 GRUB2 安装到启动分区。我还运行了步骤(“update-grub”)以生成一个新的“grub.cfg”文件,该文件向我的旧“Windows 7”引导加载程序添加了一个条目,但没有为我的新 Ubuntu 分区添加一个条目!当我重新启动时,GRUB2 引导加载程序成功启动,但在可用操作系统列表下仍然无法找到/引导我的 Ubuntu。

任何人都知道我应该如何更改/更新此配置以使其正确指向我的新 Ubuntu 安装?

一些有用的信息...

“fdisk -l”:

磁盘 /dev/sdd:1000.2 GB,1000204886016 字节

255 个磁头,63 个扇区/磁道,121601 个柱面

单位 = 16065 * 512 = 8225280 字节的柱面

扇区大小(逻辑/物理):512 字节 / 512 字节

I/O 大小(最小/最佳):512 字节 / 512 字节

磁盘标识符:0xb209a592

  Device Boot      Start         End      Blocks   Id  System

  /dev/sdd1   *           1          13      102400    7  HPFS/NTFS

  Partition 1 does not end on cylinder boundary.

  /dev/sdd2              13       60555   486297600    7  HPFS/NTFS

  /dev/sdd3           60555      120143   478642176   83  Linux

  /dev/sdd4          120143      121602    11717633    5  Extended

  /dev/sdd5          120143      121602    11717632   82  Linux swap / Solaris
Run Code Online (Sandbox Code Playgroud)

“grub.cfg”条目:

### BEGIN /etc/grub.d/30_os-prober ### menuentry "Windows 7 (loader) (on /dev/sdd1)" --class windows --class os {   insmod part_msdos   insmod ntfs     set root='(/dev/sdd,msdos1)'    search --no-floppy
--fs-uuid --set=root 08BAB5B0BAB59B20   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 ###
Run Code Online (Sandbox Code Playgroud)

"boot_info_script 输出:

                  Boot Info Script 0.60    from 17 May 2011


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

 => Windows is installed in the MBR of /dev/sda.
 => Windows is installed in the MBR of /dev/sdb.
 => Windows is installed in the MBR of /dev/sdc.
 => Grub2 (v1.99) is installed in the MBR of /dev/sdd and looks at sector 1 of 
    the same hard drive for core.img. core.img is at this location and looks 
    for (,msdos1)/grub on this drive.
 => Syslinux MBR (4.04 and higher) is installed in the MBR of /dev/sde.

sda1: __________________________________________________________________________

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

sdb1: __________________________________________________________________________

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

sdb2: __________________________________________________________________________

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

sdc1: __________________________________________________________________________

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

sdd1: __________________________________________________________________________

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

sdd2: __________________________________________________________________________

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

sdd3: __________________________________________________________________________

    File system:       ext4
    Boot sector type:  -
    Boot sector info:  
    Operating System:  Ubuntu 11.04
    Boot files:        /boot/grub/grub.cfg /etc/fstab

sdd4: __________________________________________________________________________

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

sdd5: __________________________________________________________________________

    File system:       swap
    Boot sector type:  -
    Boot sector info:  

sde1: __________________________________________________________________________

    File system:       vfat
    Boot sector type:  SYSLINUX 4.04 2011-04-18
    Boot sector info:   Syslinux looks at sector 8448 of /dev/sde1 for its 
                       second stage. SYSLINUX is installed in the  directory. 
                       The integrity check of the ADV area failed. No errors 
                       found in the Boot Parameter Block.
    Operating System:  
    Boot files:        /boot/grub/grub.cfg /syslinux/syslinux.cfg /ldlinux.sys

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

Drive: sda _____________________________________________________________________

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 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                  63 1,953,520,064 1,953,520,002   7 NTFS / exFAT / HPFS


Drive: sdb _____________________________________________________________________

Disk /dev/sdb: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders, total 488397168 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/sdb1               2,048       206,847       204,800   7 NTFS / exFAT / HPFS
/dev/sdb2    *        206,848   488,394,751   488,187,904   7 NTFS / exFAT / HPFS


Drive: sdc _____________________________________________________________________

Disk /dev/sdc: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 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/sdc1                  63 1,953,520,064 1,953,520,002   7 NTFS / exFAT / HPFS


Drive: sdd _____________________________________________________________________

Disk /dev/sdd: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 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/sdd1    *          2,048       206,847       204,800   7 NTFS / exFAT / HPFS
/dev/sdd2             206,848   972,802,047   972,595,200   7 NTFS / exFAT / HPFS
/dev/sdd3         972,802,048 1,930,086,399   957,284,352  83 Linux
/dev/sdd4       1,930,088,446 1,953,523,711    23,435,266   5 Extended
/dev/sdd5       1,930,088,448 1,953,523,711    23,435,264  82 Linux swap / Solaris


Drive: sde _____________________________________________________________________

Disk /dev/sde: 3926 MB, 3926949888 bytes
16 heads, 16 sectors/track, 29960 cylinders, total 7669824 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/sde1    *          8,064     7,669,823     7,661,760   c W95 FAT32 (LBA)


"blkid" output: ________________________________________________________________

Device           UUID                                   TYPE       LABEL

/dev/loop0                                              squashfs   
/dev/sda1        36BA3C8CBA3C4A9F                       ntfs       Data Storage (Backup)
/dev/sdb1        90A09285A0927188                       ntfs       System Reserved
/dev/sdb2        88E09C67E09C5D6E                       ntfs       Old OS HDD
/dev/sdc1        1CEE7227EE71F8FA                       ntfs       Data Storage
/dev/sdd1        08BAB5B0BAB59B20                       ntfs       System Reserved
/dev/sdd2        30EEC43AEEC3F65E                       ntfs       Operating System
/dev/sdd3        fb62baf1-e6a7-4e0d-ada2-2efb52ab12fa   ext4       
/dev/sdd5        086c0085-650b-495f-b9e8-e7e637fac705   swap       
/dev/sde1        FC8F-97FE                              vfat       PENDRIVE

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

Device           Mount_Point              Type       Options

/dev/loop0       /rofs                    squashfs   (ro,noatime)
/dev/sde1        /cdrom                   vfat       (ro,noatime,fmask=0022,dmask=0022,codepage=cp437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)


============================= sdd1/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='(/dev/sdd,msdos5)'
search --no-floppy --fs-uuid --set=root 43000377-e88b-4373-975e-66146de829ce
if loadfont /usr/share/grub/unicode.pf2 ; then
  set gfxmode=auto
  load_video
  insmod gfxterm
fi
terminal_output gfxterm
insmod part_msdos
insmod ntfs
set root='(/dev/sdd,msdos1)'
search --no-floppy --fs-uuid --set=root 08BAB5B0BAB59B20
set locale_dir=($root)/grub/locale
set lang=en_US
insmod gettext
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 ###
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/20_memtest86+ ###
### END /etc/grub.d/20_memtest86+ ###

### BEGIN /etc/grub.d/30_os-prober ###
# menuentry "Windows 7 (loader) (on /dev/sdb1)" --class windows --class os {
#   insmod part_msdos
#   insmod ntfs
#   set root='(/dev/sdb,msdos1)'
#   search --no-floppy --fs-uuid --set=root 90A09285A0927188
#   chainloader +1
# }
menuentry "Windows 7 (loader) (on /dev/sdd1)" --class windows --class os {
    insmod part_msdos
    insmod ntfs
    set root='(/dev/sdd,msdos1)'
    search --no-floppy --fs-uuid --set=root 08BAB5B0BAB59B20
    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 ###
--------------------------------------------------------------------------------

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

           GiB - GB             File                                 Fragment(s)

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

=========================== sdd3/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 efi_gop
  insmod efi_uga
  insmod video_bochs
  insmod video_cirrus
}

insmod part_msdos
insmod ext2
set root='(/dev/sdd,msdos3)'
search --no-floppy --fs-uuid --set=root fb62baf1-e6a7-4e0d-ada2-2efb52ab12fa
if loadfont /usr/share/grub/unicode.pf2 ; then
  set gfxmode=auto
  load_video
  insmod gfxterm
fi
terminal_output gfxterm
insmod part_msdos
insmod ext2
set root='(/dev/sdd,msdos3)'
search --no-floppy --fs-uuid --set=root fb62baf1-e6a7-4e0d-ada2-2efb52ab12fa
set locale_dir=($root)/boot/grub/locale
set lang=en_US
insmod gettext
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 ###
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
menuentry 'Ubuntu, with Linux 2.6.38-8-generic' --class ubuntu --class gnu-linux --class gnu --class os {
    recordfail
    set gfxpayload=$linux_gfx_mode
    insmod part_msdos
    insmod ext2
    set root='(/dev/sdd,msdos3)'
    search --no-floppy --fs-uuid --set=root fb62baf1-e6a7-4e0d-ada2-2efb52ab12fa
    linux   /boot/vmlinuz-2.6.38-8-generic root=UUID=fb62baf1-e6a7-4e0d-ada2-2efb52ab12fa ro   quiet splash vt.handoff=7
    initrd  /boot/initrd.img-2.6.38-8-generic
}
menuentry 'Ubuntu, with Linux 2.6.38-8-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os {
    recordfail
    set gfxpayload=$linux_gfx_mode
    insmod part_msdos
    insmod ext2
    set root='(/dev/sdd,msdos3)'
    search --no-floppy --fs-uuid --set=root fb62baf1-e6a7-4e0d-ada2-2efb52ab12fa
    echo    'Loading Linux 2.6.38-8-generic ...'
    linux   /boot/vmlinuz-2.6.38-8-generic root=UUID=fb62baf1-e6a7-4e0d-ada2-2efb52ab12fa ro single 
    echo    'Loading initial ramdisk ...'
    initrd  /boot/initrd.img-2.6.38-8-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='(/dev/sdd,msdos3)'
    search --no-floppy --fs-uuid --set=root fb62baf1-e6a7-4e0d-ada2-2efb52ab12fa
    linux16 /boot/memtest86+.bin
}
menuentry "Memory test (memtest86+, serial console 115200)" {
    insmod part_msdos
    insmod ext2
    set root='(/dev/sdd,msdos3)'
    search --no-floppy --fs-uuid --set=root fb62baf1-e6a7-4e0d-ada2-2efb52ab12fa
    linux16 /boot/memtest86+.bin console=ttyS0,115200n8
}
### END /etc/grub.d/20_memtest86+ ###

### BEGIN /etc/grub.d/30_os-prober ###
menuentry "Windows 7 (loader) (on /dev/sdb1)" --class windows --class os {
    insmod part_msdos
    insmod ntfs
    set root='(/dev/sdb,msdos1)'
    search --no-floppy --fs-uuid --set=root 90A09285A0927188
    chainloader +1
}
menuentry "Windows 7 (loader) (on /dev/sdd1)" --class windows --class os {
    insmod part_msdos
    insmod ntfs
    set root='(/dev/sdd,msdos1)'
    search --no-floppy --fs-uuid --set=root 08BAB5B0BAB59B20
    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 ###
--------------------------------------------------------------------------------

=============================== sdd3/etc/fstab: ================================

--------------------------------------------------------------------------------
# /etc/fstab: static file system information.
#
# Use 'blkid -o value -s UUID' 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/sdd3 during installation
UUID=fb62baf1-e6a7-4e0d-ada2-2efb52ab12fa /               ext4    errors=remount-ro 0       1
# swap was on /dev/sdd5 during installation
UUID=086c0085-650b-495f-b9e8-e7e637fac705 none            swap    sw              0       0
--------------------------------------------------------------------------------

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

           GiB - GB             File                                 Fragment(s)

 476.025924683 = 511.128944640  boot/grub/grub.cfg                             1
 465.547851562 = 499.878199296  boot/initrd.img-2.6.38-8-generic               2
 686.000980377 = 736.587943936  boot/vmlinuz-2.6.38-8-generic                  1
 465.547851562 = 499.878199296  initrd.img                                     2
 686.000980377 = 736.587943936  vmlinuz             

arr*_*nge 4

我会使用那里发布的教程,程序号 2。在发出命令之前,请确保该/dev/sdd驱动器是预期的 1TB 驱动器。

sudo mount /dev/sdd3 /mnt
sudo grub-install --root-directory=/mnt/ /dev/sdd
Run Code Online (Sandbox Code Playgroud)

这会将 Grub 加载程序安装到驱动器的开头和/boot上的目录sdd3

您不需要update-grub在那里运行该部分。然后进入 BIOS 并将该sdd驱动器标记为主要启动设备。