Sunday, November 22, 2009

How to make you PC Dual Boot Linux and windows




For past few years I have been using Linux (Fedora). When I decided to use Linux the first thing came in my mind is how to make my PC dual boot for both windows and Linux. Though one method was simple I allowed the grub loader to install in my MBR (master boot record) and there I chose  lable "other" as default.

Though that was the most simple thing to do but later I faced a problem. When I tried to boot my pc with windows xp bootable CD it did't booted with that. That was because there was grub loader in MBR.

So later I searched for Installing Fedora or other Linux without installing GRUB in MBR. So by default the windows loader NTLDR should detect the linux partion and it should boot your linux with it. The the problem is that you NTLDR can't detect linux partion. So basically you have to copy a file in your windows partion.

There are few methods to do it :-
  • 1# Use dd to copy GRUB stage1 to a binary file:- Install Fedora and choose the boot loader option to install GRUB in the first sector of the Fedora boot partition (see attachment). Fedora will not boot at first. In linux rescue (see attachment), use the dd command to copy GRUB stage1 located in the first sector of the Fedora boot partition to a binary file in the Windows root directory. Then manually edit boot.ini (see attachment) to add a new entry for Fedora to the Windows boot menu to launch the binary file. 
    • After Fedora is installed...
    • Boot with the Fedora DVD into linux rescue.
    • At the command prompt, enter:

      dd if=/dev/sdxy of=fedora.bin bs=512 count=1


    • NOTE: You change x & y to the drive & partition of the Fedora boot partition with stage1. You may also change the name of the output file to whatever you choose.

    • Copy the binary file to a floppy or a partition that Windows can access (see attachment).
    • Exit linux rescue and reboot into Windows.
    • Copy the binary file to C:\ where boot.ini is also located.
    • Edit boot.ini to add a line similar to this:

      Code:
      c:\fedora.bin="Fedora"


    • Reboot.
    • How it looks on paper

      Code:
                                                boot.ini               /--> kernel
                                                          |                 / 
      BIOS --> Partition Loader --> Boot Sector Code --> ntldr --> XP Menu -----> kernel          grub.conf                  /--> kernel
                 (Master Boot        (Volume Boot          |                \                         |                     / 
                    Record)             Record)       ntdetect.com           \--> fedora.bin --> GRUB stage2 --> GRUB Menu -----> kernel
                                                                                 (GRUB stage1)   (/boot/grub)               \ 
                                                                  
       

    • NOTE: This "dd method" sometimes doesn't work if the Fedora boot partition is not on the same drive as Windows. That can result in an incorrect boot drive number being specified in the code of the binary file at offset 40h. The hex values for the boot drive number are first=80h, second=81h, third=82h, and so on. If the value at offset 40h is FFh, that means that the stage1 program gets the boot drive number from BIOS, and that also could be wrong for the physical layout. The binary file can be edited with any hex editor to change the boot drive number when this happens. In the example below, the value for the boot drive number at offset 40h is FFh. The Fedora boot partition was on the second drive, and the binary file did not work to boot the Fedora system. The binary file was edited with ghex to change the boot drive number to 81h, and then it worked to boot the Fedora system.

  •  2# BOOTPART:-
    • Summary

      Install Fedora and choose the boot loader option to install GRUB in the first sector of the Fedora boot partition (see attachment). Fedora will not boot at first. Use BOOTPART in Windows to create a binary file containing code that loads and executes the boot sector code of the Fedora boot partition (stage1). BOOTPART also edits boot.ini to add a new entry for Fedora to the Windows boot menu to launch the binary file. BOOTPART is often useful when the dd-created binary file fails to work.

      The Steps

      After Fedora is installed...
    • Reboot into Windows.
    • Download BOOTPART from the Internet and unzip the files to your Windows Desktop.
    • Open a Windows Command Prompt window. From here on, everything occurs in this window.
    • Change directories to the Windows Desktop...

      Code:
      cd desktop


    • Enter the command bootpart without any options and your partitions will be listed. Example...

      Code:
      C:\Documents and Settings\User\Desktop>bootpart
      
      Physical number of disk 0 : 9590e5ce
       0 : C:* type=b  (Win95 Fat32), size= 2008093 KB, Lba Pos=63
       1 : C:  type=5  (Extended), size= 18000832 KB, Lba Pos=4016250
       2 : C:  type=7  (HPFS/NTFS), size= 18000801 KB, Lba Pos=4016313
      Physical number of disk 1 : b4f03683
       3 : D:* type=7  (HPFS/NTFS), size= 80035798 KB, Lba Pos=63
      Physical number of disk 2 : 9a109a0
       4 : E:* type=83 (Linux native), size= 104391 KB, Lba Pos=63
       5 : E:  type=8e (Linux LVM), size= 38989755 KB, Lba Pos=208845


    • Now enter the command again in this format...

      Code:
      bootpart [partition number] [filename] [title]
      [partition number] Get this from the output of your bootpart command without options in the previous step. In the above example, partition #4 is the Fedora boot partition and is easy to spot since it is listed as type=83 (Linux native) and the other Linux partition is an LVM physical volume. If there had been several type 83 partitions instead of the LVM PV, here are some clues to find the boot partition: a) it is usually the first type 83 Linux partition in the list, b) it is usually about 100000 KB in size, c) it may have an asterisk (*) by it indicating it is the active partition.

      [filename] This is the name to give the binary file to be created in the Windows root directory. It can be anything you want.

      [title] This the title of the Fedora OS in the Windows boot loader menu. It can be anything you want.



    • Continuing with the example from above, the command could be like this...

      Code:
      bootpart 4 C:\fedora.bin "Fedora"


    • Reboot.
How it looks on paper
Code:
boot.ini               /--> kernel
                                                    |                 / 
BIOS --> Partition Loader --> Boot Sector Code --> ntldr --> XP Menu -----> kernel                          grub.conf                  /--> kernel
           (Master Boot        (Volume Boot          |                \                                         |                     / 
              Record)             Record)       ntdetect.com           \--> fedora.bin --> GRUB stage1 --> GRUB stage2 --> GRUB Menu -----> kernel
                                                                            (BOOTPART)    (boot sector)    (/boot/grub)               \                                                     
  •  #3: GRUB for DOS(my favorate)
    Summary

    Install Fedora and choose the boot loader option to install GRUB in the first sector of the Fedora boot partition (see attachment). Fedora will not boot at first. This method uses GRUB for DOS (aka GRUB4DOS) which is capable of launching the Fedora kernel directly without using any GNU GRUB stages. Even though Fedora's GRUB stages are not required for this method to work, there is still a benefit from choosing to install GRUB in the first sector of the Fedora boot partition. It causes a grub.conf file to be created for Fedora while still sparing the master boot record from changes. Having a grub.conf file is useful for copying menu commands to the GRUB for DOS menu.lst or for using the configfile menu command to launch Fedora. The stage1 code that is installed in the boot sector causes no harm sitting there unused.

    The Steps

    After Fedora is installed...
  • Reboot into Windows.
  • Download the GRUB4DOS zip file.
  • Unzip the file and copy these files to C:\ (or the Windows root directory):



    1. grldr
    2. menu.lst



  • Edit boot.ini (see attachment) to add a line similar to this:

    Code:
    c:\grldr="Start GRUB"


  • Edit menu.lst to add sections for the Linux systems (and to tidy up for the many examples).
  • Reboot.
How it looks on paper
Code:
boot.ini               /--> kernel
                                                    |                 /
BIOS --> Partition Loader --> Boot Sector Code --> ntldr --> XP Menu -----> kernel                /--> kernel
           (Master Boot        (Volume Boot          |                \                          /
              Record)             Record)       ntdetect.com           \--> grldr --> GRUB Menu -----> kernel
                                                                              |                  \
                                                                           menu.lst               \--> kernel
                                                                      (using configfile)
The usual menu commands all work in the GRUB for DOS menu.lst file. The title, root, kernel, and initrd lines can be copied from another configuration file to directly boot a Linux kernel. Or, the configfile command can be used to reload the menu with the information from another system's GRUB configuration file. And, the chainloader command can be used to launch boot sector code.

12 comments:

  1. ^^ 謝謝你的分享,祝你生活永遠多彩多姿!........................................

    ReplyDelete
  2. 你要教你的孩子走路;但是,應由孩子自己去學走路. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

    ReplyDelete
  3. blog is great~~祝你人氣高高~.........................

    ReplyDelete
  4. This comment has been removed by a blog administrator.

    ReplyDelete
  5. 生命是一頓豐富的宴席,有人卻寧可挨餓........................................

    ReplyDelete
  6. 如果成為一支火柴,也要點亮一個短暫的宇宙;如果是一隻烏鴉,也要叫疼閉塞的耳膜。.............................................

    ReplyDelete
  7. 新手上路哦~請大家多支持^_^..............................

    ReplyDelete