Grub boot manager for Linux and Windows dual system installation.

Reprinted from the product is slightly Library  http://www.pinlue.com/article/2020/04/0710/1410126301133.html

Most people used daily work system is Windows, or if you want to try to turn Linux, Windows and Linux coexist then carried out the dual system installation is a good idea. However, the installation of the system than the single dual system, both in disk partitions, and the boot manager adds complexity, the paper mounted at boot manager dual system to be introduced.

I assume that Win2k / XP system you already have a good working condition and has been well prepared hard disk partition for Linux: Windows is located in the first hard disk first partition, expressed as hda1 on Linux, expressed as in Grub (hd0,0), while Linux is located hdaX, as expressed by Grub (hd0, X-1). Hard disk partition is counted under --Linux hda1 from the beginning, the hard disk partition is counted from Grub (hd0,0) starts, so that hdaX (hd0, X- 1). Where X falls within 1-4 described Linux partition is a primary partition, if X is greater than 4, Linux partition is a logical partition described herein is not limited to be located in the main Linux partition, as it is guided in the logical partition.

First, the idea of ​​this article, the author recommended by Windows to Linux boot sequence, ie first boot Windows ntloader, and then load the Grub boot sector of the Linux partition by ntloader, and finally through the Grub boot Linux system. This article related to the boot manager include ntloader and Grub, ntloader is the Windows system comes in after the installation of Win2k / XP already installed, Windows 2000 and Windows Xp is a ntloader loaded. Grub is very powerful boot manager under Linux system, common in some Linux versions are generally installed automatically.

DETAILED DESCRIPTION The following installation sequence:

First, it has been prepared on the Linux partition to install Grub

This process is usually carried out by the installer Linux system automatically when the installation program to install Boot Manager, and gives some tips on installation of Grub, beware: we choose Grub, instead of lilo, and Grub to install the Linux partition, do not install to the hard disk master boot record MBR (master boot record) on. When the program asks for the installation position of the Grub should be hdaX mentioned above, or (hd0, X-1), or if you wrote hda (hd0), will be attached to the MBR.

The emphasis Grub installed Linux partitions instead of MBR, because this article is a dual system installation, to scruple to compatibility with Windows systems ( "compatible" here is not accurate, real symbiotic meaning). Our principle is that the modifications to the Windows system has been installed to limit to the minimum extent necessary, not to be is not the necessary changes in order to guarantee peaceful coexistence of the two systems Linux and Windows. "That simple beauty", "simple" will be more secure.

If you install to MBR, it is also possible, but may have the following questions:

1, if the installed Windows system to modify the default settings of the MBR, you then install Grub to MBR, then the contents of the MBR has been modified, may cause the Windows does not start. The usual Windows installation and will not change the content of the MBR, but if you install some boot manager, they are often set by the MBR. Very popular nowadays some of the "key recovery" program, some of them are set by the MBR;

2, when the future reinstall Windows system, MBR where Grub will be erased, this will lead to the Linux system will not boot. Although this problem can be resolved, but I appreciate the way once and for all installation, Grub installed to the Linux partition, to avoid future trouble;

3, in some individual cases, the Grub not properly boot the system. This phenomenon is not common, but it still can happen, you know Grub is still the pre-release software, and will install Grub to the MBR, the problem will be made more complicated.

When you installed Linux systems can not specify where the partition will install Grub to Linux, our choice is:

Grub will be temporarily installed to MBR, if Grub Linux system can be guided into the Linux system, we then manually load Grub Linux partition, and then restore the MBR; or temporarily not Grub is installed in the installation program, exit the installation program after manual installation Grub.

Need to recover the MBR DOS, win98 / me boot diskette boot to / mbr parameters fdisk.exe program executes the boot partition on the floppy disk, i.e., the DOS command line (plain dos) perform the A: \> fdisk / mbr. If the machine does not have a floppy drive, you will need a CD-ROM or U disk to boot the machine into DOS; under Windows 2k / XP, the software called Vfloppy can use a floppy disk image files to virtual boot floppy, if your machine does not have USB an interface (or no U-DOS boot disk), and there is no floppy drive, a try.

When I have used LiveCD Xubuntu in a set "key recovery" of TCL Computer installation, the installer did not give any option to automatically install Grub to the MBR, the results can not enter any system. A finally with under DOS: the \> fdisk / mbr restore the MBR, the normal boot Windows, manually install Grub to the root partition under Linux, then load Grub by ntloader, was able to achieve a guide to Linux.

Easy way to manually install Grub is using a Linux LiveCD with the Grub (such as common Knoppix, Morphix, Ubuntu, are possible), booting the system, within the Linux installer if they can enter the shell is also possible, in short Linux is to execute the instruction, the following instruction at the terminal:

# grub

grub > root (hd0,X-1)

grub > setup (hd0,X-1)

grub > quit

First, locate the needed more instructions Grub / boot directory partition (hd0, X-1), then the boot code is written Grub (hd0, X-1) The first sector of the partition, so make sure that you should first ( hd0, the X-1) partition / boot / grub directory has stage1, stage2, * _ stage * other documents, these documents can be obtained by releasing Grub package file, or directly from LiveCD disc / boot / grub directory replication.

If LiveCD with grub-install script, can be executed directly

# Mount / dev / eleven / mnt

# grub-install --root-directory=/mnt /dev/hdaX

Grub more instructions with First directory / boot / grub is / hdaX mount / mnt, then to install Grub / hdaX.

Second, fit into the Grub ntloader

Grub is installed to a Linux partition, but it can not boot the system, we need to link up to it and ntloader, to be guided by the ntloader Grub. This is done by converting Grub hdaX partition boot sector of the file, and fitted into the Windows ntloader to be implemented.

Linux system still starts with a LiveCD (since you installed Linux system is still not boot), or when the installer can enter in the shell, execute the following command:

# mount -t vfat /dev/hda1 /mnt

# dd if=/dev/hdaX of=/mnt/linux.lnx bs=512 count=1

The two instructions above Windows boot partition (herein as hda1) mounted to the lower / mnt, then Linux partition (hdaX) in the first sector (512 bytes in size) copy the root directory of the boot partition for Windows linux.lnx named file.

Note: If your Windows boot partition (ie C drive under Windows) is not a fat32 file system, but ntfs file system, you need to put DOS formatted floppy disk in the floppy drive, and the first instruction is replaced with:

# mount -t msdos /dev/fd0 /mnt

Because ntfs file system without special treatment, can not be written in Linux, even if you replace the instructions for the vfat ntfs, mount realized, too, so we are here to put a DOS-formatted floppy disk write linux.lnx and then through the floppy disk under Windows linux.lnx into the C drive.

Followed by editing the Windows boot.ini file in the root directory of C, boot.ini usually hidden, read-only file system, so it needs to be "hidden", "Read Only" attribute removed before they can be edited. In the "My Computer" Tools menu "Folder Options" under the "View" column "Hide protected operating system files" and "Hide extensions for known file types" and select "Show hidden files and folders folder ", you can see the boot.ini file in the root directory of the C. Boot.ini in the [operating systems] field to add a line:

c:\linux.lnx=”Grub Menu”

And [boot loader] column of "timeout = 0", to "timeout = 5", so that when the boot Windows operating system with the word "Grub Menu" selection menu is displayed for 5 seconds, if select Grub menu, you will enter the Grub menu.

Third, set the menu.lst file

Grub menu.lst is set in a text file can be edited using a text editor, located in / boot / grub directory. Although we have put in front Grub installed to root Linux partition, but if it does not generate menu.lst file and be set up, Grub does not have any effect. Menu.lst file to set up a complex task, particularly in relation to the various special kernel parameters and initrd, menu.lst file system installed within fortunately usually have detailed comments. If you and your Grub is automatically set by the installer, it is usually menu.lst has been set up, we just make some changes and adjustments according to their needs, without having to rewrite menu.lst. Even if your menu.lst not generated by the installer, do not worry, you can also refer to analyze the installation CD or menu.lst files on the LiveCD to be set menu.lst Linux partition.

If Grub has been installed by the installer to the MBR, and can guide the installation of Linux, then automatically generated /boot/grub/menu.lst under Linux root partition system has been configured, we only need to reinstall Grub Linux partition to the root system, to restore the original MBR, Windows, Linux method according to the above system root partition ntloader Grub boot code is loaded into it. Because Grub mounting position is not specified in the menu.lst file, but performed in the Linux shell grub, Grub enter command line instructions inner root and setup Grub application to specify, in a shell script file or executable grub- install, specify the device file (e.g., / dev / hda or / dev / hdaX) as a parameter.

If the installed Linux system does not use Grub, but use as a boot manager lilo, lilo can be achieved as long as the guide, we can learn from /etc/lilo.conf file in the linux system to be set up to menu.lst. Lilo.conf is lilo configuration file, although menu.lst different format, but the key part is the same, such as the kernel and initrd specified position, the boot parameters passed to the kernel, the system specifies the default boot and long delay, in lilo.conf kernel parameters in the APPEND, we can be transplanted into the lilo.conf the parameters in menu.lst.

Fourth, an instance of Menu.lst:

As the following examples menu.lst I installed windows 2000 system grub4nt configuration files, so you can see (hd0,0) both Windows boot partition, but also where the partition Grub documents and some of the linux kernel file. Although Grub4nt savedefault command can not be applied in the menu.lst outside (probably because grub4nt not support write operations on fat32 file system), and other settings standard Gnu Grub is no different, we can use this example to understand the specific configuration file menu .lst.

default 0

timeout 5

foreground = 333333

background = eeeeee

color light-gray/blue black/light-gray

gfxmenu (hd0,0)/boot/morphix/message

title ubuntu linux

kernel (hd0,2)/vmlinuz ro root=/dev/hda3

title ubuntu linux (rescue mode)

kernel (hd0,2)/vmlinuz ro single root=/dev/hda3

title Other operating systems:

root

title PUD LiveHD

kernel (hd0,0)/boot/pud/linux lang=us ramdisk_size=100000 init=/etc/init apm=power-off vga=791 nomce initrd=miniroot.gz quiet BOOT_IMAGE=knoppix

initrd (hd0,0)/boot/pud/miniroot.gz

title Windows

root (hd0,0) or rootnoverify (hd0,0)

makeactive

chainloader +1

title submenu -> Morphix LiveHD

configfile (hd0,1)/boot/grub/menu.lst

Menu.lst do not fully explain here, just with examples, introduce a few key links, please read the full description of Grub online manual.

Default 0

to configure the default boot the system default, sequence numbers starting from 0, the entry to automatically find regular session begins in the menu.lst title, a title entry and the first guide, you can change according to their needs other digital as a (second title terms);

timeout 5

When a timeout is used to set the long delay Grub boot, according to the present embodiment is 5 seconds, the system after waiting five seconds without the user manually select the system to boot, Grub will automatically boot the system specified by default;

title ubuntu linux

title to indicate the start of the system provided Grub guided behind the title text will be displayed as the name of the system in the Grub menu, in the present embodiment Grub boot menu is displayed ubuntu linux, ubuntu linux (rescue mode), other operating systems, PUD LiveHD, Windows, submenu -> Morphix six entries, wherein the third entries is not a real system, only play the role of instruction, so the root section is empty;

kernel (hd0,2)/vmlinuz ro root=/dev/hda3

It is used to indicate linux kernel kernel file system location, and boot parameters, (hd0,2) / vmlinuz kernel hda3 means (a hard disk of the third primary partition) vmlinuz file in the root directory, the root file system ( /) located hda3, Note: instructs the kernel file path partition must Grub notation, can not be used linux notation, while the location of the root file system must use the device file name in the linux represented (in this case / dev / hda3). Sometimes, vmlinuz kernel file is not real, but a kernel file link file (link file), but this does not affect the Grub boot, you can find the real kernel file and be guided according to link this file in the kernel It will be very useful with the long version number, simplifying the spelling of the file name of the kernel, reducing the chance of error misspelled;

This kernel is provided in the most simple manner, is relatively common arrangement, the kernel used to guide installed directly installed root file system (i.e. linux system), without the need for initrd setting; clear core when setting the parameters specific, this arrangement can be used to try to boot the system. If a single add In the above arrangement, i.e. to kernel (hd0,2) / vmlinuz ro root = / dev / hda3 single, after the system boot into single-user (root user) text mode, i.e., rescue mode (Rescue mode), would be more useful when the system upgrades, maintenance or find, troubleshooting;

initrd (hd0,0)/boot/pud/miniroot.gz

initrd initrd file is used to indicate (i.e., the initial memory disk file, linux guidance systems commonly used technique) location, on the hard disk partition and requirements representation of the same kernel, this method must represent the Grub (hd0, 0);

root (hd0,0)

for positioning the root partition, in this case the partition hda1, Windows system. If it is before the initrd and kernel, file locations can be used to simplify notation, such as

kernel (hd0,2)/vmlinuz ro root=/dev/hda3

Can be written as

root (hd0,2)

kernel /vmlinuz ro root=/dev/hda3

The initrd can also be the case of imitation;

makeactive

makeactive used to activate targeted root partition, it is only to the main partition, logical partition can not be used to extend the partition, although this technique can be used to guide the Grub linux system installed in the main area, but a relatively large limitations, it is often used to boot Windows system;

chainloader +1

chainloader +1 to be guided to the primary partition makeactive activated, supra: it can only boot primary partition, it is usually used to boot the Windows system, and the system can be installed linux logical partitions on the extended partition, usually use the kernel this initrd and more powerful, flexible boot mode;

configfile (hd0,1)/boot/grub/menu.lst

When configfile for the introduction of other menus Grub menu.lst menu, a plurality of linux system installed on the same machine, a plurality menu.lst file, this statement is useful because it can simplify the set menu.lst file, do not Chong Chao those complex boot parameters, only to be referenced on it other menu.lst file system, select this sub-menu in the Grub boot, will enter the boot menu menu.lst of references.

PUD LiveHD the present embodiment is to copy the contents of the PUD (one kind of Chinese Traditional Debian LiveCD version) to hda1 disc (in the present embodiment for Windows C: drive), and then use them to guide grub4nt, so to achieve the migration to the hard disk LiveCD I call LiveHD; and the contents of the Morphix LiveHD sucked Morphix (a modular LiveCD the Debian) CD-ROM to a separate ext2 / 3 partitions, in this case (hd0, 1), i.e. hda2, to achieve the LiveHD guide. Interestingly, PUD can only put fat32 partition, Morphix can only put ext2 partition, not vice versa guide, this should be different due to the different versions of the LiveCD kernel supported file system.

Note: Grub4nt Grub is extended under windows 2k / XP, built on Grub for DOS, / boot / grub directory placed in the fat / fat32 file system, can be achieved by a small Grub boot file grldr in ntloader, without write MBR, it is China who works as a novel way of guidance, linux enthusiasts to show the world the Chinese people's wisdom, we will cover in a later special. Fifth, adjust boot.ini file

boot.ini is a text file that can be opened with a text editor, it is a win 2k / XP under ntloader settings file, the following is an example boot.ini on my machine:

[boot loader]

timeout=0

default=multi(0)disk(0)rdisk(0)partition(1)\WINNT

[operating systems]

c:\ubuntu.lnx=Xubuntu Linux

c:\morphix.lnx=Morphix LiveHD

c:\grldr=Grub Menu

multi(0)disk(0)rdisk(0)partition(1)\WINNT="Win2k" /fastdetect

We come to it line by line explanation.

[Boot loader] specifies a default boot system and waiting time, in this case the default boot the first IDE disk first partition (denoted as multi (0) disk (0) rdisk (0) partition (1), and if your windows Xp system in the second partition of the hard disk, it is represented as multi (0) disk (0) rdisk (0) partition (2) \ WINDOWS, this notation differs linux, it does not distinguish between primary and logical partitions, and the order of the partitions based on the disk 1 starts counting from the digital system windows 2000) therein, no delay, the guide immediately.

If the Timeout value from 0 to 5, then 5 seconds delay for the user to select boot menu; to -1, the system does not automatically boot, the user is always waiting for keyboard input to be selected.

[Operating systems] is used to describe a different system to boot from the boot menu, "=" character are the display contents of the boot menu, and "=" in front of the actual guide part ntloader content, multi (0) disk (0) rdisk (0) partition (1) \ WINNT guide means ntloader windows system to be located on a hard disk first partition \ winnt directory, c: \ ubuntu.lnx and c: \ morphix.lnx the dd is the application command in the linux grub in the boot sector of the partition root transformation generates files, c: \ grldr grub4nt the boot file is used to implement the ntloader guided in grub.

Different order of entries in the [operating systems] can be adjusted, for example, we may be c: \ grldr = Grub Menu from the first row to the third row in this section, so that the boot menu Grub Menu will first line display.

And the default boot system may also be changed, for example, we may be multi (0) disk (0) in the [boot loader] rdisk (0) partition (1) \ WINNT to c: \ grldr, so the default boot is grub4nt the Grub menu instead of the windows 2000. Here we must note: c: \ grldr into the [boot loader] one time, the correct wording should be

default=c:\grldr

Must not be "= Grub Menu" to bring, or boot menu will display not what we want, remember!

Six, grub4nt use

The grub loaded into ntloader in the method, in addition to the above-described second portion of the root Linux boot sector can convert ntloader file, there is another method of Grub boot partition, is used grub4nt. grub4nt by grldr this small file, so ntloader direct load Windows systems C: \ boot \ grub \ menu.lst (new version grub4nt will look for the root directory \ menu.lst) under the plate.

In the boot.ini file under windows [operating systems] section add a line as follows:

c:\grldr=grub4nt

menu.lst set grub4nt, either the /boot/grub/menu.lst Linux system root partition directly transplant (savedefault under the GNU Grub can not be used in grub4nt, results in an error of grub4nt), also in within grub4nt menu.lst file menu /boot/grub/menu.lst Linux system is introduced directly into the root partition by configfile, which is an easy and secure way, eliminating the need for a complex set of kernel boot parameters.

That is so arranged in the grub4nt menu.lst file:

title GNU Grub menu

configfile (hda0,X)/boot/grub/menu.lst

Seven summary

In this paper, install the boot manager when Windows and Linux coexist in the same machine gives a description, it can be seen, ntloader I recommend is under Windows 2k / XP-based guide to load the Grub by ntloader, and finally by Grub realization boot Linux. Characteristics of such a leader sequence is for Windows guide to be varied little only inserted therein for loading the Grub. Of course, the reverse sequence is also possible, i.e. first guide Grub (Grub can be loaded MBR or primary partition in an active state), the load to Grub ntloader (by chainloader +1 order), and then implement the guidance Windows. But the latter may lead to other problems.

In any case, the Linux boot herein are performed by Grub, Grub whether the loaded root Linux partition boot sector is loaded by Grub ntloader root Linux partition, or through grldr grub4nt by the loading grldr be achieved ntloader Grub boot. In fact, Grub boot sector and file grldr just Grub loading different implementations Bale.

 

 

Published 60 original articles · won praise 58 · Views 140,000 +

Guess you like

Origin blog.csdn.net/yihuliunian/article/details/105361864