Grub引导Win7+XP+Ubuntu多系统的问题解决

  今天为了这破事儿弄了一下午,最终还是靠在Ubuntu中文论坛发帖解决了。

  我用的台式机有两块硬盘,Win7+XP+Ubuntu。以前只有一块硬盘的时候,先安装的XP,然后安装Ubuntu(现已更新到11.04)。后来觉得硬盘不够用,就新增加了一块硬盘,在新的硬盘上安装了Win7,系统引导变成Win7的启动引导。后来用光盘修复为Grub引导,默认进入Win7的启动选项,然后Win7的启动选项中设置XP系统为默认启动,然后一直以来正常的启动就是默认进入XP。

  结果昨天因为某些原因卸下有Win7的那块硬盘,然后进入Ubuntu弄点东西,再重新装回有Win7的那块硬盘。至此Grub就不能设置默认引导到Win7的启动选项了,就是默认进入Ubuntu,但是在Grub倒计时那时选择Win7的话也能正常进入选择Win7或者XP来正常进入Windows系统。

  在“启动管理器”里面设置了默认进入Win7启动,重启之后还是自动进入Ubuntu。

后来执行了“fdisk -l”之后结果如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
candura@canbuntu:~$ sudo fdisk -l

Disk /dev/sda: 300.1 GB, 300069052416 bytes
255 heads, 63 sectors/track, 36481 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xbcebcd9f

Device Boot Start End Blocks Id System
/dev/sda1 * 1 5100 40965718+ 7 HPFS/NTFS
/dev/sda2 5101 36481 252067882+ f W95 Ext'd (LBA)
/dev/sda5 5101 10200 40965718+ 7 HPFS/NTFS
/dev/sda6 10201 22949 102406311 7 HPFS/NTFS
/dev/sda7 22950 36481 108695758+ 7 HPFS/NTFS

Disk /dev/sdb: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x624aa2e0

Device Boot Start End Blocks Id System
/dev/sdb1 * 1 3825 30724281 7 HPFS/NTFS
/dev/sdb2 3826 30402 213474057 f W95 Ext'd (LBA)
/dev/sdb5 3826 8925 40965718+ 7 HPFS/NTFS
/dev/sdb6 8926 17849 71681998+ 7 HPFS/NTFS
/dev/sdb7 17850 26773 71681998+ 7 HPFS/NTFS
/dev/sdb8 26774 30246 27894784 83 Linux
/dev/sdb9 30246 30402 1248256 82 Linux swap / Solaris

其中sdb是我安装了XP+Ubuntu的那块硬盘,sda是安装了Win7的那块硬盘。

后来在网上找,说是可以用Grub Customizer来修改尝试,于是就用Grub Customizer来配置。

配置完保存后“/boot/gurb/grub.cfg”文件内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#
# 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="6"
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/sda,msdos8)'
search --no-floppy --fs-uuid --set=root 46ed6e0f-6930-446b-9129-58167c489c00
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/sda,msdos8)'
search --no-floppy --fs-uuid --set=root 46ed6e0f-6930-446b-9129-58167c489c00
set locale_dir=($root)/boot/grub/locale
set lang=zh_CN
insmod gettext
if [ "${recordfail}" = 1 ]; then
set timeout=-1
else
set timeout=1
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,Linux 2.6.38-10-generic' --class ubuntu --class gnu-linux --class gnu --class os {
recordfail
set gfxpayload=$linux_gfx_mode
insmod part_msdos
insmod ext2
set root='(/dev/sda,msdos8)'
search --no-floppy --fs-uuid --set=root 46ed6e0f-6930-446b-9129-58167c489c00
linux /boot/vmlinuz-2.6.38-10-generic root=UUID=46ed6e0f-6930-446b-9129-58167c489c00 ro quiet splash vt.handoff=7
initrd /boot/initrd.img-2.6.38-10-generic
}
menuentry 'Ubuntu,Linux 2.6.38-10-generic (恢复模式)' --class ubuntu --class gnu-linux --class gnu --class os {
recordfail
set gfxpayload=$linux_gfx_mode
insmod part_msdos
insmod ext2
set root='(/dev/sda,msdos8)'
search --no-floppy --fs-uuid --set=root 46ed6e0f-6930-446b-9129-58167c489c00
echo 'Loading Linux 2.6.38-10-generic ...'
linux /boot/vmlinuz-2.6.38-10-generic root=UUID=46ed6e0f-6930-446b-9129-58167c489c00 ro single
echo 'Loading initial ramdisk ...'
initrd /boot/initrd.img-2.6.38-10-generic
}
submenu "Previous Linux versions" {
menuentry 'Ubuntu,Linux 2.6.35-29-generic' --class ubuntu --class gnu-linux --class gnu --class os {
recordfail
set gfxpayload=$linux_gfx_mode
insmod part_msdos
insmod ext2
set root='(/dev/sda,msdos8)'
search --no-floppy --fs-uuid --set=root 46ed6e0f-6930-446b-9129-58167c489c00
linux /boot/vmlinuz-2.6.35-29-generic root=UUID=46ed6e0f-6930-446b-9129-58167c489c00 ro quiet splash vt.handoff=7
initrd /boot/initrd.img-2.6.35-29-generic
}
menuentry 'Ubuntu,Linux 2.6.35-29-generic (恢复模式)' --class ubuntu --class gnu-linux --class gnu --class os {
recordfail
set gfxpayload=$linux_gfx_mode
insmod part_msdos
insmod ext2
set root='(/dev/sda,msdos8)'
search --no-floppy --fs-uuid --set=root 46ed6e0f-6930-446b-9129-58167c489c00
echo 'Loading Linux 2.6.35-29-generic ...'
linux /boot/vmlinuz-2.6.35-29-generic root=UUID=46ed6e0f-6930-446b-9129-58167c489c00 ro single
echo 'Loading initial ramdisk ...'
initrd /boot/initrd.img-2.6.35-29-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/sda,msdos8)'
search --no-floppy --fs-uuid --set=root 46ed6e0f-6930-446b-9129-58167c489c00
linux16 /boot/memtest86+.bin
}
menuentry "Memory test (memtest86+, serial console 115200)" {
insmod part_msdos
insmod ext2
set root='(/dev/sda,msdos8)'
search --no-floppy --fs-uuid --set=root 46ed6e0f-6930-446b-9129-58167c489c00
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/sda1)" --class windows --class os {
insmod part_msdos
insmod ntfs
set root='(/dev/sda,msdos1)'
search --no-floppy --fs-uuid --set=root 12EC809FEC807F2B
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 ###

  然后重启依旧默认进入的是Ubuntu。

  我看了一下“/boot/grub/”里面的文件,是有“grub.cfg”,没有“menu.lst”的,说明应该已经是用了Grub2来引导的。但是后来用了“sodu update-grub”命令之后,系统提示说找不到“menu.lst”是否创建。

  后来系统自动创建的“menu.lst”文件内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
menu.lst - See: grub(8), info grub, update-grub(8)
# grub-install(8), grub-floppy(8),
# grub-md5-crypt, /usr/share/doc/grub
# and /usr/share/doc/grub-legacy-doc/.

## default num
# Set the default entry to the entry number NUM. Numbering starts from 0, and
# the entry number 0 is the default if the command is not used.
#
# You can specify 'saved' instead of a number. In this case, the default entry
# is the entry saved with the command 'savedefault'.
# WARNING: If you are using dmraid do not use 'savedefault' or your
# array will desync and will not let you boot your system.
default 0

## timeout sec
# Set a timeout, in SEC seconds, before automatically booting the default entry
# (normally the first entry defined).
timeout 3

## hiddenmenu
# Hides the menu by default (press ESC to see the menu)
hiddenmenu

# Pretty colours
#color cyan/blue white/blue

## password ['--md5'] passwd
# If used in the first section of a menu file, disable all interactive editing
# control (menu entry editor and command-line) and entries protected by the
# command 'lock'
# e.g. password topsecret
# password --md5 $1$gLhU0/$aW78kHK1QfV3P2b2znUoe/
# password topsecret

#
# examples
#
# title Windows 95/98/NT/2000
# root (hd0,0)
# makeactive
# chainloader +1
#
# title Linux
# root (hd0,1)
# kernel /vmlinuz root=/dev/hda2 ro
#

#
# Put static boot stanzas before and/or after AUTOMAGIC KERNEL LIST

### BEGIN AUTOMAGIC KERNELS LIST
## lines between the AUTOMAGIC KERNELS LIST markers will be modified
## by the debian update-grub script except for the default options below

## DO NOT UNCOMMENT THEM, Just edit them to your needs

## ## Start Default Options ##
## default kernel options
## default kernel options for automagic boot options
## If you want special options for specific kernels use kopt_x_y_z
## where x.y.z is kernel version. Minor versions can be omitted.
## e.g. kopt=root=/dev/hda1 ro
## kopt_2_6_8=root=/dev/hdc1 ro
## kopt_2_6_8_2_686=root=/dev/hdc2 ro
# kopt=root=UUID=46ed6e0f-6930-446b-9129-58167c489c00 ro

## default grub root device
## e.g. groot=(hd0,0)
# groot=46ed6e0f-6930-446b-9129-58167c489c00

## should update-grub create alternative automagic boot options
## e.g. alternative=true
## alternative=false
# alternative=true

## should update-grub lock alternative automagic boot options
## e.g. lockalternative=true
## lockalternative=false
# lockalternative=false

## additional options to use with the default boot option, but not with the
## alternatives
## e.g. defoptions=vga=791 resume=/dev/hda5
# defoptions=quiet splash

## should update-grub lock old automagic boot options
## e.g. lockold=false
## lockold=true
# lockold=false

## Xen hypervisor options to use with the default Xen boot option
# xenhopt=

## Xen Linux kernel options to use with the default Xen boot option
# xenkopt=console=tty0

## altoption boot targets option
## multiple altoptions lines are allowed
## e.g. altoptions=(extra menu suffix) extra boot options
## altoptions=(recovery) single
# altoptions=(recovery mode) single

## controls how many kernels should be put into the menu.lst
## only counts the first occurence of a kernel, not the
## alternative kernel options
## e.g. howmany=all
## howmany=7
# howmany=all

## specify if running in Xen domU or have grub detect automatically
## update-grub will ignore non-xen kernels when running in domU and vice versa
## e.g. indomU=detect
## indomU=true
## indomU=false
# indomU=detect

## should update-grub create memtest86 boot option
## e.g. memtest86=true
## memtest86=false
# memtest86=true

## should update-grub adjust the value of the default booted system
## can be true or false
# updatedefaultentry=false

## should update-grub add savedefault to the default options
## can be true or false
# savedefault=false

## ## End Default Options ##

title Ubuntu 11.04, kernel 2.6.38-10-generic
uuid 46ed6e0f-6930-446b-9129-58167c489c00
kernel /boot/vmlinuz-2.6.38-10-generic root=UUID=46ed6e0f-6930-446b-9129-58167c489c00 ro quiet splash
initrd /boot/initrd.img-2.6.38-10-generic

title Ubuntu 11.04, kernel 2.6.38-10-generic (recovery mode)
uuid 46ed6e0f-6930-446b-9129-58167c489c00
kernel /boot/vmlinuz-2.6.38-10-generic root=UUID=46ed6e0f-6930-446b-9129-58167c489c00 ro single
initrd /boot/initrd.img-2.6.38-10-generic

title Ubuntu 11.04, kernel 2.6.35-29-generic
uuid 46ed6e0f-6930-446b-9129-58167c489c00
kernel /boot/vmlinuz-2.6.35-29-generic root=UUID=46ed6e0f-6930-446b-9129-58167c489c00 ro quiet splash
initrd /boot/initrd.img-2.6.35-29-generic

title Ubuntu 11.04, kernel 2.6.35-29-generic (recovery mode)
uuid 46ed6e0f-6930-446b-9129-58167c489c00
kernel /boot/vmlinuz-2.6.35-29-generic root=UUID=46ed6e0f-6930-446b-9129-58167c489c00 ro single
initrd /boot/initrd.img-2.6.35-29-generic

title Chainload into GRUB 2
root 46ed6e0f-6930-446b-9129-58167c489c00
kernel /boot/grub/core.img

title Ubuntu 11.04, memtest86+
uuid 46ed6e0f-6930-446b-9129-58167c489c00
kernel /boot/memtest86+.bin

### END DEBIAN AUTOMAGIC KERNELS LIST

按理说用了Grub2的话,使用“sudo update-grub”应该是更新“grub.cfg”文件才对的阿,真奇怪。

后来论坛里面的“onshoestring”提醒我说,有可能是Grub和Grub2装乱了,试试重装。

然后就执行命令;

1
2
3
4
5
6
7
8
9
10
11
sudo apt-get purge grub
sudo apt-get purge grub-pc
sudo apt-get purge grub-common

sudo rm -rf /boot/grub/*
sudo rm -rf /etc/grub.d/*
sudo rm /etc/default/grub

sudo apt-get install grub-pc grub-common
sudo grub-install /dev/sda
sudo update-grub

  但是在执行“sudo apt-get purge grub”的时候它自动卸载了“启动管理器”,执行完这些之后需要需要再执行“sudo apt-get install startupmanager”来重新安装“启动管理器”,然后其他的一切照旧从“启动管理器”设置。
  结果再一重启,终于,默认经过Grub引导和Win7引导最终进入XP了。

文章目录
|