cyber-monk
May 12th, 2010, 06:49 AM
I recently installed Ubuntu 10.04 on my dual boot system and noticed that my boot options were changed. I typically have Windows XP as the default OS. Here are the steps that worked for me to get Windows XP as the default boot using Grub2.
During my initial Window XP install I had partitioned my hard drive into 3 partitions:
Partition 1: NTFS format (Windows XP installation) in Linux it is called /dev/sda1
Partition 2: NTFS format (Data for Windows XP) in Linux is is called /dev/sda5
Partition 3: Unformatted (I left this because I knew I wanted to install Linux)
This is how those partitions looked when booting to the Ubuntu installer (I used the Ubuntu installer to create the /swap and ext3 partitions on Partition 3 which was unformatted):
/dev/sda1 (Windows-XP OS NTFS)
/dev/sda5 (Windows-XP Data NTFS)
/swap
/dev/sda7 (Ubuntu 10.04 OS ext3)
After installation I noticed that Ubuntu was being booted by default. The default boot entries are created from the files in the /etc/grub.d/ directory. The files need to be executable (have a * at the end of the file name) to be included in the boot menu. To make a file executable type: sudo chmod +x <filename>
$> cd /etc/grub.d/
$> ll
total 56
drwxr-xr-x 2 root root 4096 2010-05-11 21:35 ./
drwxr-xr-x 130 root root 12288 2010-05-11 21:42 ../
-rwxr-xr-x 1 root root 4444 2010-04-13 06:57 00_header*
-rwxr-xr-x 1 root root 1416 2010-04-13 06:38 05_debian_theme*
-rwxr-xr-x 1 root root 4594 2010-04-13 06:57 10_linux*
-rwxr-xr-x 1 root root 918 2010-03-23 02:40 20_memtest86+*
-rwxr-xr-x 1 root root 6605 2010-04-13 06:57 30_os-prober*
-rwxr-xr-x 1 root root 214 2010-04-13 06:57 40_custom*
-rw-r--r-- 1 root root 483 2010-04-13 06:57 README
I didn't want the memory tests to be on the boot menu so I removed the executable bit on 20_memtest86+. You could also disable the 30_os-prober since we are adding Windows XP manually but that is optional. I left that file active in case I screwed something up.
$> sudo chmod -x 20_memtest86+
I wanted Windows XP to stay at the top of the menu because with each kernel update it will get pushed further down the boot list. By naming the file with 06_... it gets sorted to the top of the boot list so when we edit /etc/default/grub we can set the default boot option to be 0 which is the top of the list.
$> sudo cp 40_custom 06_windowsxp
$> sudo vim 06_windowsxp
Then I copied the menuentry for Windows XP section of /boot/grub/grub.cfg into 06_windowsxp. The /etc/grub/grub.cfg file is auto-generated so it does no good to edit it directly. After editing, my 06_windowsxp file looked like this:
#!/bin/sh
exec tail -n +3 $0
# 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.
# copied from /boot/grub/grub.cfg
menuentry "Windows XP Professional x64 Edition (on /dev/sda1)" {
insmod ntfs
set root='(hd0,1)'
search --no-floppy --fs-uuid --set 0060ff4060ff3acc
drivemap -s (hd0) ${root}
chainloader +1
}
Now I needed to ensure that we will always default to the 0th entry in the boot list. This is done by setting GRUB_DEFAULT to 0. Zero is the default value so you probably don't need to edit this. I also decreased the GRUB_TIMEOUT to 4 and increased the resolution GRUB_GFXMODE=1024x768 (both are optional).
$> cd /etc/default/
$> sudo vim grub
The resulting grub file should look similar to this (changes in bold):
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
GRUB_DEFAULT=0
#GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=4
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""
# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console
# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
GRUB_GFXMODE=1024x768
# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true
# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_LINUX_RECOVERY="true"
# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"
The final step is to run update-grub to write our changes into the /boot/grub/grub.cfg file.
$> sudo update-grub
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-2.6.32-22-generic
Found initrd image: /boot/initrd.img-2.6.32-22-generic
Found linux image: /boot/vmlinuz-2.6.32-21-generic
Found initrd image: /boot/initrd.img-2.6.32-21-generic
Found Windows XP Professional x64 Edition on /dev/sda1
done
You can check that your changes worked by re-examining the /boot/grub/grub.cfg file.
May the force be with you...
During my initial Window XP install I had partitioned my hard drive into 3 partitions:
Partition 1: NTFS format (Windows XP installation) in Linux it is called /dev/sda1
Partition 2: NTFS format (Data for Windows XP) in Linux is is called /dev/sda5
Partition 3: Unformatted (I left this because I knew I wanted to install Linux)
This is how those partitions looked when booting to the Ubuntu installer (I used the Ubuntu installer to create the /swap and ext3 partitions on Partition 3 which was unformatted):
/dev/sda1 (Windows-XP OS NTFS)
/dev/sda5 (Windows-XP Data NTFS)
/swap
/dev/sda7 (Ubuntu 10.04 OS ext3)
After installation I noticed that Ubuntu was being booted by default. The default boot entries are created from the files in the /etc/grub.d/ directory. The files need to be executable (have a * at the end of the file name) to be included in the boot menu. To make a file executable type: sudo chmod +x <filename>
$> cd /etc/grub.d/
$> ll
total 56
drwxr-xr-x 2 root root 4096 2010-05-11 21:35 ./
drwxr-xr-x 130 root root 12288 2010-05-11 21:42 ../
-rwxr-xr-x 1 root root 4444 2010-04-13 06:57 00_header*
-rwxr-xr-x 1 root root 1416 2010-04-13 06:38 05_debian_theme*
-rwxr-xr-x 1 root root 4594 2010-04-13 06:57 10_linux*
-rwxr-xr-x 1 root root 918 2010-03-23 02:40 20_memtest86+*
-rwxr-xr-x 1 root root 6605 2010-04-13 06:57 30_os-prober*
-rwxr-xr-x 1 root root 214 2010-04-13 06:57 40_custom*
-rw-r--r-- 1 root root 483 2010-04-13 06:57 README
I didn't want the memory tests to be on the boot menu so I removed the executable bit on 20_memtest86+. You could also disable the 30_os-prober since we are adding Windows XP manually but that is optional. I left that file active in case I screwed something up.
$> sudo chmod -x 20_memtest86+
I wanted Windows XP to stay at the top of the menu because with each kernel update it will get pushed further down the boot list. By naming the file with 06_... it gets sorted to the top of the boot list so when we edit /etc/default/grub we can set the default boot option to be 0 which is the top of the list.
$> sudo cp 40_custom 06_windowsxp
$> sudo vim 06_windowsxp
Then I copied the menuentry for Windows XP section of /boot/grub/grub.cfg into 06_windowsxp. The /etc/grub/grub.cfg file is auto-generated so it does no good to edit it directly. After editing, my 06_windowsxp file looked like this:
#!/bin/sh
exec tail -n +3 $0
# 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.
# copied from /boot/grub/grub.cfg
menuentry "Windows XP Professional x64 Edition (on /dev/sda1)" {
insmod ntfs
set root='(hd0,1)'
search --no-floppy --fs-uuid --set 0060ff4060ff3acc
drivemap -s (hd0) ${root}
chainloader +1
}
Now I needed to ensure that we will always default to the 0th entry in the boot list. This is done by setting GRUB_DEFAULT to 0. Zero is the default value so you probably don't need to edit this. I also decreased the GRUB_TIMEOUT to 4 and increased the resolution GRUB_GFXMODE=1024x768 (both are optional).
$> cd /etc/default/
$> sudo vim grub
The resulting grub file should look similar to this (changes in bold):
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
GRUB_DEFAULT=0
#GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=4
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""
# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console
# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
GRUB_GFXMODE=1024x768
# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true
# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_LINUX_RECOVERY="true"
# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"
The final step is to run update-grub to write our changes into the /boot/grub/grub.cfg file.
$> sudo update-grub
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-2.6.32-22-generic
Found initrd image: /boot/initrd.img-2.6.32-22-generic
Found linux image: /boot/vmlinuz-2.6.32-21-generic
Found initrd image: /boot/initrd.img-2.6.32-21-generic
Found Windows XP Professional x64 Edition on /dev/sda1
done
You can check that your changes worked by re-examining the /boot/grub/grub.cfg file.
May the force be with you...