HOWTO Dual Boot met Windows Bootloader (NTLDR) en waarom
Uit Gentoo Linux Wiki
| Gentoo installeren na Windows • Windows installeren na Gentoo • Using Windows Loader • Using GRUB or LILO • coLinux |
Inhoud |
[bewerken] Introductie
Gentoo is een van de allerbeste manieren om Linux te leren, maar kan ook een van de lastigste zijn. Het is dus begrijpelijk dat je nog aan je Microsoft Windows XP systeem wilt vasthouden om een backup te hebben in het geval alles mis gaat, of gewoon omdat je je bij XP (nog) het meest thuisvoelt. Dual-boot is dus de ideale oplossing om je rustig te laten slapen, en je de kans te geven om Gentoo in je eigen tempo te verkennen. Er zijn twee fundamentele benaderingen om te dual-booten:
- XP en Gentoo op dezelfde fysieke harddisk
- Verschillende harddisks voor XP en Gentoo, mogelijk met verschillende combinaties van SATA en IDE schijven.
Welke je ook kiest, het in stand houden van XP en de mogelijkheid hebben om ernaar terug te keren, als je mocht ontdekken dat Linux niets voor jou is, is waarschijnlijk van belang. Gelukkig is er veel informatie te vinden over dual-boot; helaas is er een tekort aan een enkel, samenhangend document dat een veilige installatie beschrijft. Hopelijk, is dit het.
[bewerken] NTLDR - Wat is het en waarom?
Misschien heb je gehoord van GRUB, LILO and NTLDR. Wat ze gemeen hebben is dat ze boot loaders zijn; dwz ze initialiseren je systeem en zorgen dat het Operating System in het geheugen gehaald wordt, klaar voor gebruik. NTLDR (of NT Loader) is Microsoft’s boot loader voor op NT gebaseerde operating systems, waaronder 2000 en XP. Het is gebaseerd op drie belangrijke files:
- boot.ini – bevat configuratie opties voor een opstart menu
- NTDETECT.com – detecteert types hardware in je system
- NTLDR – de loader zelf
De boot loaders bevinden zich normaal gesproken in de het Master Boot Record (MBR) van je harddisk. Je MBR is een 512 byte grote boot sector van de disk die een serie commando's bevat om je operating system op te starten. Standaard gebruikt XP de NTLDR bootloader, dus het is logisch om deze te gebruiken om te bepalen met welk operating system je op wilt starten. Niet alleen vermijd je daarmee het overschrijven van je MBR met GRUB of LILO en mogelijke problemen met verloren partities niet meer in staat zijn om een operating system te starten, maar zorgt er ook voor, dat als je weer van Gentoo af wilt, een minimale inspanning vereist is om je systeem weer in de staat je brengen dat het had voordat je begon. Dus, over tot actie. Ik neem aan dat je het uitstekende Gentoo Handbook hebt gevolgd, bent aangekomen bij het onderdeel: “Configuring the Bootloader”.
[bewerken] GRLDR - Een eenvoudiger benadering
grldr zit in de grub4dos distributie, en is een gepatchte versie van de normale. ntldr kan verwijzen naar grldr, en daardoor hoef je niet te stoeien met dd, bootsectoren enzovoorts . grldr ondersteunt fat en ntfs, en gebruikte een normale grub-style 'menu.lst'. Dat is bijzonder nuutig als je een linux kernel en ramdisk van je Windows partitie wilt start, maar kan ook handig zijn in andere gevallen. Zoals wanneer je Linux op een machine met Windows wilt installeren, maar geen usb/floppy/cdrom hebt. Om grldr te gebruiken, zet grldr en menu.lst in de root van je windows partitie. Voeg dan: C:\grldr="Start Linux Loader (GRUB)" aan de boot.ini toe. Dat is alles. Dwz los van het bewerken van menu.lst. Zie de grub documentatie voor de menu.lst syntax. (menu.lst is hetzelfde als grub.conf, maar grldr gebruikt menu.lst.)
[bewerken] Installatie op een enkele harddisk
Scenario: XP and Gentoo installed on the same hard disk; XP in your first partition and Gentoo in subsequent partitions.
(Warning - contrary to what the handbook says, when setting up your partitions, you shouldn't set the /boot partition to be "bootable". You can only have one partition set as bootable - and this should be the Windows partition. If you have more than one partition set as bootable then your partition table will be invalid and you won't be able to boot up. If this happens, however, you can always boot from the livecd and use fdisk to correct the problem).
I will concentrate on using GRUB in this situation although you could equally use LILO; take a look at the separate disk installation section to get an idea of the configuration for LILO but remember you won’t be using separate disks so change the disk references accordingly.
[bewerken] GRUB Configuration
Firstly emerge grub and then create your configuration file using your favourite editor, in this case I use nano:
# emerge grub # nano -w /boot/grub/grub.conf
Using the Gentoo Handbook, or the sample below, your conf file will look something like this:
| File: /boot/grub/grub.conf |
default 0 # Default operating system to load: first entry timeout 5 # Timeout before loading default: 5 seconds title=Gentoo Linux # Title of OS: Gentoo Linux root (hd0,1) # Location of the kernel image: second partition on the first disk # Tell GRUB where the kernel image is before changing root to point to your root partition: # third partition (now using Linux notation) kernel /boot/kernel-2.6.16-gentoo-r5 root=/dev/hda3 |
Don’t forget GRUB references the first partition of your hard disk as hd0,0 and not hd0,1. GRUB also references SATA disks using the same notation i.e. hd0,1. If you are not sure which partitions boot and root lives in then use “fdisk –l” to remind yourself of your disk partitioning scheme and, if you are still unsure, “df –h” which will display your partitions and where they are mounted.
[bewerken] GRUB Installation
If you have not yet done so, create /etc/mtab which lists all mounted file systems.
# grep -v rootfs /proc/mounts > /etc/mtab
Now GRUB needs to be installed into the boot sector of the /boot partition and not your disk’s MBR, thus preserving the MBR. The boot sector of a partition is similar to the MBR in that it is the first 512 bytes although boot sectors of partitions can only be loaded by a bootloader from the MBR. To install GRUB use the following commands:
# grub grub> root (hd0,1) (Specify where your /boot partition resides) grub> setup (hd0,1) (Install GRUB in the boot sector of /boot) grub> quit (Exit the GRUB shell)
adjusting partition numbers if required.
[bewerken] Fooling Windows
Firstly, make sure you have a medium to transfer a small file from Gentoo to Windows e.g. a FAT formatted floppy disk or a partition readable from Windows and writeable from Gentoo. Now we shall make a copy of the boot sector of the boot partition containing GRUB:
# mount /dev/fd0 /mnt/floppy (mount your floppy disk, if required) # dd if=/dev/hda2 of=grub.mbr bs=512 count=1 (create a copy of the boot partition) # cp grub.mbr /mnt/floppy (copy grub.mbr to your floppy) # umount /dev/fd0 (un-mount the floppy, if required)
Now reboot your machine into Windows and copy the grub.mbr file to c:\, assuming this is where Windows lives on your system. Cast your mind back to the boot.ini file...it is a hidden file but we can still open it with any text editor. Now open Notepad by selecting Start menu - All Programs - Accessories - Notepad. In Notepad go to file menu - open file "C:\boot.ini" and add this line to the bottom: c:\grub.mbr="Gentoo Linux"
It should now look similar to this example:
| File: c:\boot.ini |
[boot loader] timeout=30 default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS [operating systems] multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /fastdetect C:\grub.mbr="Gentoo Linux" |
This additional line references the grub.mbr file we created earlier which is simply the instructions to boot Linux. Save the file and close Notepad. Finally reboot your machine; with luck you will see two listings, the second one being “Gentoo Linux”. When you select this GRUB should greet you and you are done.
[bewerken] Separate disk installation
Scenario: XP and Gentoo installed on separate hard disks; XP in your first partition of your first disk and Gentoo in partitions on your second disk. This arrangement is common and desirable in long-term dual boot systems because each drive can contain a different self-contained, bootable operating system, which are easy to bring alive solo if the other one dies. Plus, if you include a 30GB FAT32 partition on each drive, each operating system can write to the other OS's drive as a local file backup (chances of both drives dying at the same time is about nil).
One down-side is that some problems booting Gentoo/XP from a separate disk are common, insidious, and go un-resolved. One example I've come across is putting Windows on the Secondary drive. LILO can boot this up, making Windows think it's on the IDE Primary by intercepting BIOS disk I/O calls. But eventually, some application doesn't play nice, and directly does I/O to one or both disks. As a general rule, Windows does not like to boot from a Secondary drive.
Fortunately, the Wiki HOWTO you're reading provides a definitive method of booting Gentoo on a Secondary disk, allowing XP to reside happily on the Primary disk. I will use LILO here as it has the best support for Windows partitions. You could also use GRUB although I have not had any success with it.
[bewerken] LILO Configuration
Firstly set your boot partition as active by running these commands:
# fdisk /dev/hdb # Command (m for help): <enter ‘a’> # Partition number (1-4): <enter /boot partition number> # Command (m for help): <enter ‘p’ and check your /boot partition has an asterisk next to it. # Command (m for help): w (Save the new schema)
If you are not sure which partition boot lives in then use “fdisk –l” to remind yourself of your disk partitioning scheme and, if you are still unsure, “df –h” which will display your partitions and where they are mounted. Make a note of root’s location while you are there as you will need this later.
Next, emerge lilo and then create your configuration file using your favourite editor, in this case I use nano:
# emerge lilo # nano -w /etc/lilo.conf
Using the Gentoo Handbook, or the sample below, your conf file will look something like this:
| File: /etc/lilo.conf |
# Global LILO settings boot=/dev/hdb1 # Install LILO in the /boot partition prompt # Give the user the chance to select another section timeout=50 # Wait 5 (five) seconds before booting the default section default=Gentoo Linux # When the timeout has passed, boot the "Gentoo Linux" section # Kernel specific LILO settings image=/boot/kernel-2.6.14-gentoo-r5 # Location of your kernel image label= Gentoo Linux # Name of this section read-only # Start with a read-only root. Do not alter! root=/dev/hdb3 # Location of the root filesystem |
Remember to alter the root, boot and image locations according to your own setup. SATA disks will be referenced using sda (first SATA disk).
One important note: the above configuration file sets where LILO will write to. LILO needs to be installed into the boot sector of the boot partition (/dev/hdb1) and not your disk’s MBR (/dev/hdb). The boot sector of a partition is similar to the MBR in that it is the first 512 bytes although boot sectors of partitions can only be loaded by a bootloader from the MBR. So you should set “boot=/dev/hdb1”, assuming this is where your boot partition is located.
If the boot partition is part of an already-used Linux system, chock full of files, don't worry. The boot sector of any partition is not used for normal file storage. It is resident and reserved space of any partition whether or not the partition has been used or is populated with files.
[bewerken] LILO Installation
LILO will probably make a backup of an existing boot sector before it writes over it. From Section 3 of the LILO (v 21) manual, "Whenever the map installer updates a boot sector, the original boot sector is copied to /boot/boot.number, where number is the hexadecimal device number. If such a file already exists, no backup copy is made." The easy answer is to inspect the /boot directory and rename any existing files so LILO will create a new one. With a backup copy of the boot sector, should you make a mistake at any point, just use “lilo -u device-name” and it will restore the saved boot sector. To quote from the To install LILO:
# /sbin/lilo
As a side note, notice LILO writes to the boot device in the configuration file (or -b command line option, if it were to be used). LILO gets other critical information from the current root mount. For instance, if you ever salvage a hard drive installation after booting from an emergency LILO floppy, you'll probably chroot to the hard drive first. Note that the to and from could be the same on a simple installation.
[bewerken] Fooling Windows
Firstly, make sure you have a medium to transfer a small file from Gentoo to Windows e.g. a FAT formatted floppy disk or a partition readable from Windows and writeable from Gentoo. I will assume Gentoo is located on hdb, so just change this reference in the examples, if required.
Although LILO will probably do this for us (see caveat above for pre-existing files, quoted from the LILO manual), just to be sure initially we back up the MBR of the disk Gentoo is installed onto:
# dd if=/dev/hdb of=mbr.save bs=512 count=1
before installing LILO into the MBR of the Gentoo disk (hdb) using a special LILO command:
# lilo -M /dev/hdb
The -M option, available for the first time in LILO ver 22.3, is not the same as the -m option. Instead, the -M option creates a Master boot sector that we only need to copy to Windows once, and never need to update, no matter what other changes lilo makes. Specifically, "lilo -M" installs a default MBR onto the target that is obtained from a static copy compiled into /sbin/lilo, which will search for an active partition on the target disk and load that partitions's boot sector. (-M details obtained from hyc and LILO man pages).
Cull a copy of this new MBR using:
# dd if=/dev/hdb of=lilo.mbr bs=512 count=1
and finally restore the old mbr:
# dd if=mbr.save of=/dev/hdb bs=512
The next step is to transfer lilo.mbr to your Windows disk, in this case using a floppy, so:
# mount /dev/fd0 /mnt/floppy (mount your floppy disk, if required) # cp lilo.mbr /mnt/floppy (copy lilo.mbr to your floppy) # umount /dev/fd0 (un-mount the floppy, if required)
Now reboot your machine into Windows and copy the lilo.mbr file to c:\, assuming this is where Windows lives. Cast your mind back to the boot.ini file...we shall now add an entry to boot Gentoo but first we need to make the file viewable, writeable and unhidden. From command prompt (start > run, type “cmd”) enter:
attrib -s -h -r c:\boot.ini
You can now browse to this file, open it and add this line to the bottom: c:\lilo.mbr="Gentoo Linux"
It should now look similar to this example:
| File: c:\boot.ini |
[boot loader] timeout=30 default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS [operating systems] multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /fastdetect C:\lilo.mbr="Gentoo Linux" |
This additional line references the lilo.mbr file we created earlier which is simply the instructions to boot Linux. Save the file and reapply the attributes you removed by running:
attrib +s +h +r c:\boot.ini
at command prompt. Finally reboot your machine; with luck you will see two listings, the second one being “Gentoo Linux”. When you select this LILO should greet you and you are done.
[bewerken] Installing Grub
Installing Grub works much in the same way as LILO. But Stage 1 of Grub has to be told where to find Stage 2.
- Install Grub on your /boot partition (not the MBR of the first bootable disk!)
- Normally one would use grub-install, but this asumes the /boot partition is on the same drive as the MBR / Stage 1 of Grub. (The grub-install script should be fixed...)
- You have to fire up the grub shell and install grub using the command install of grub with the option "d" (see grub manual: http://www.gnu.org/software/grub/manual/html_node/install.html#install)
- Copy the Grub Stage 1 from the first sector of the /boot partition
# dd if=/dev/[boot partition here] of=grub.boot bs=512 count=1
- Copy the file to the Windows partition (c:\linux_boot\grub.boot)
- Add Grub (Gentoo/Linux) to the Windows bootloader NTLDR. Add a line to the file c:\boot.ini (remember the attributes!)
c:\linux_boot\grub.boot="Linux (Grub)"
- You should see Linux in the boot menu, next time you boot
[bewerken] Grub Hack
Do not ues this hack! Use the install command of the grub shell insead! See section above!
Many if not all have had trouble applying the same procedure for LILO to GRUB. I will share a little hack that has worked on my machine however I cannot confirm if it will work for all.
After following the LILO process but using GRUB instead open the C:\*.mbr file with a hex-editor and change the value at offset 0x40 to 0x8? , where ? is the drive number grub is installed on. Following on from the example the new value will be 0x81 as drive numbers start from from 0x80 and GRUB is installed on the 2nd drive.
More information and the inspiration for the hack can be found at http://mirror.href.com/thestarman/asm/mbr/GRUB.htm (An interesting read)
[bewerken] Using Grub as bootloader (replacing Windows NTLDR)
Here is a way to have Windows on the first hard disk and Gentoo on the other and be able to boot them both.
Install Windows to the first disk.
Install Gentoo to the other.
Edit grub's config file menu.lst.
| File: /boot/grub/menu.lst |
title=Windows root (hd1,0) chainloader +1 map (hd1) (hd0) map (hd0) (hd1) title=Gentoo Linux root (hd0,0) kernel /kernel-2.6.16-gentoo-r9 |
Install grub (0.96 works, others not confirmed) to 2nd disk (Gentoo disk).
Make the 2nd disk the disk to boot from in BIOS.
The trick is to make Windows think that it's the first disk although it's actually the 2nd disk because we boot from the physical 2nd disk first. The map commands do this.
Good thing in this setup is that you have 2 separate disks that you can boot from. If there is something wrong with your Gentoo system you can change the drive to boot from in your BIOS and boot to Windows.
[bewerken] Reverting back to Windows
So you have given Gentoo a go and decided it is not for you and want to undo the changes we have made or you decided you love Gentoo and just want to boot your windows drive differently. Luckily, it is a simple matter of correcting your boot.ini and deleting the Linux partitions. You can delete all your Linux partitions using Linux's fdisk, or use the Disk Management snapin from "Control Panel -> Administration -> Computer Management -> Disk Management". If you choose to go with the linux fdisk, you might like to use the Gentoo LiveCD you installed Gentoo from, another LiveCD or any other source that has Linux fdisk on it.
# fdisk <device e.g. /dev/hdb> # Command (m for help): <enter ‘d’> # Partition number (1-4): <enter partition number> # Command (m for help): w (Save the new schema)
Repeat steps 2 and 3 until you have deleted all your Linux partitions. This will of course erase all data in those partitions.
Now remove the one line from your boot.ini file, located in your c:\ drive, that we modified earlier. Modify the permissions as before and remove:
c:\grub.mbr="Gentoo Linux" or c:\lilo.mbr="Gentoo Linux"
depending on which route you chose, and reapply the permissions. You may also like to remove the *.mbr file left behind for tidiness.
[bewerken] Boot sector & MBR problems
These can, and will, happen so always make backups of important data before you start anything like altering your boot sectors. Should you find your Windows partition has become unbootable, you can repair the MBR and/or the boot sector of a partition using your XP installation disk. Simply boot from the installation disk, select 'R' to repair the current installation, enter the Recovery Console and then type:
fixmbr <device> and/or fixboot <drive> (this wipes the boot sector)
Depending on the damage you may lose your data on this disk.
If you find you have hosed your partitions and apparently lost your data, help is at hand. Generally, your data will be safe and can be recovered simply by restoring the partition. One such tool that always works for me is Active Partition Recovery[1], although there are of course others.
[bewerken] Glossary
- NTLDR – NT Loader
- GRUB – GNU GRUB
- LILO – LInux LOader
- MBR – Master Boot Record
- Boot sector
- fixmbr
- fixboot
[bewerken] See also
[bewerken] External links
- GNU GRUB homepage [2]
- LILO homepage [3]
- Detailed explanation of the boot.ini file and various configuration [4]
- A detailed tutorial of using GRUB to dual-boot with Linux and Windows [5]
- A tutorial of how to dual-boot with Linux and Windows on the same drive [6]
- An explanation of using GRUB to boot Linux from a separate drive [7]
- An explanation of using LILO to boot Linux from a separate drive [8]
- Restoring your MBR [9]
