| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • Stop wasting time looking for files and revisions. Connect your Gmail, DriveDropbox, and Slack accounts and in less than 2 minutes, Dokkio will automatically organize all your file attachments. Learn more and claim your free account.

View
 

How-to-keep-your-system-clean-while-working-with-GRUBby-hands

Page history last edited by Paul G. Taylor 10 years, 1 month ago

Parent page to http://pgtips91.pbworks.com/Step-by-step-instructions-for-the-target-system

 

This project has arisen out of the saga that developed at Linux Internationals, here: --    

Pardus 2009.1 Install disc

[Note, this morphed into a long discussion on booting problems between Xandros, Pardus and Win98]

 

  1. Introduction :
  2. Things that need to be considered : --
  3. Steps to regaining control of your computer.
    1. Decide which OS will be the default OS.
    2. Decide which boot-loader will load the default OS.
    3. Install the default boot-loader into the MBR to boot the default OS.
    4. Run the installation of the default boot-loader in the default OS to pick up as many of the other installed OSes as it is able to find.
    5. Manually add the boot information of any installed OSes that were missed in the step above.
    6. It may be necessary to chain-load another boot-loader if the target OS cannot be loaded by the default boot-loader.
    7. It may help to create a boot-floppy or a boot-CD containing all the above data as a backup against any changes introduced by installing some other OS later on.
    8. Avoid messing up this system ever-afterwards.
  4. Lay-out of Partitions :
    1. General Considerations.
    2. Suggested Partitioning Structure.
  5. Current starting Conditions in Target System under review.
  6. Boot-loaders
    1. LILO
    2. GRUB Legacy [up to version 0.97 ]
    3. GRUB-PC       [ version 0.98 upwards ]
  7. The Master Boot Record.
    1. What is the Master Boot Record [MBR]?
    2. Backing up the MBR
    3. See also
  8. Chainloading
    1. Chain-loading LILO from GRUB Legacy
    2. Chain-loading another boot-loader in GRUB
      1. Load another boot loader to boot unsupported operating systems
  9. Working with GRUB
    1. Examine Current menu.lst from running installed Linux.
  10. Working with LILO
    1. Chain-loading another boot-loader in LILO
  11. How to make a Grub floppy/CD that boots all systems in a PC
  12. Making a partition bootable.
  13. Step by step instructions for the target system.
  14. Back-up and Restore the MBR
    1. MBR backup
    2. MBR restore
    3. 2.4 How Can I Uninstall Lilo?


Introduction :



When multi-booting from several installed operating systems, each of which uses a different boot-loader, different file systems and all competing with one another to control the MBR, there are a number of problems that may ensue if not guarded against and provision made for the complexity of the situation.

The order in which the Operating Systems are installed has a dominant influence over which boot-loader is installed to the MBR and is therefore the controlling boot-loader at time of booting up.

However, once the system is fully installed there are ways and means by which the system can be conformed to the wishes of the user, regardless of how the defaults have laid out the system up until this point.

 

Things that need to be considered : --


MBR  [Master Boot Record]
Operative Boot-loader
Layout of Partitions
Boot-loaders :
      LILO
      GRUB Legacy

      GRUB-PC 

Distributions

 

 

Steps to regaining control of your computer.

 

What you need to do, to regain full control over your system, is explicitly make these choices and implement them : --

 

Decide which OS will be the default OS.

 

 

 

Decide which boot-loader will load the default OS.

 

 

 

Install the default boot-loader into the MBR to boot the default OS.

 

 

 

Run the installation of the default boot-loader in the default OS to pick up as many of the other installed OSes as it is able to find.

 

 

 

Manually add the boot information of any installed OSes that were missed in the step above.

 

 

 

It may be necessary to chain-load another boot-loader if the target OS cannot be loaded by the default boot-loader.


Thus MS Windows boot-loader needs to be called by GRUB to boot MS Windows, and GRUB-PC needs to be called by GRUB Legacy if the target OS has been installed with a file system that is not recognised by GRUB Legacy, such as ext4 for example.

 

 

It may help to create a boot-floppy or a boot-CD containing all the above data as a backup against any changes introduced by installing some other OS later on.

 

 

Avoid messing up this system ever-afterwards.

 

 

To avoid messing up this system, when installing or re-installing an OS later on, ensure that you install the boot-loader only to the root of the partition where the OS is being (re-)installed and avoid over-writing the MBR. This is usually possible by selecting the advanced options during the installation process. Watch carefully for this option at the stage where you select the partition(s) into which to (re-)install the OS because if you miss this option you will have quite a lot of work to do to recover your system. Often the option is difficult to find, being hidden from inexpert users.



Lay-out of Partitions :

 

General Considerations.


Typically, if you have a version of MS Windows installed, this will have been installed first and occupy the first partition on the system. I will assume that this is the case from here on.

The partitioning system has an archaic limitation of four primary partitions. In order to have more than four partitions on a hard drive, therefore, it is necessary to have one of these partitions dedicated as an extended partition. The extended partition can then be sub-divided into any number of Logical Partitions as needed [there is a limit but this will seldom be a problem].It is best to reserve the 4th partition for this so that any Logical Partitions added or deleted do not affect the partition table adversely.

It is possible, and desirable, to keep your personal data, such as emails, documents, photographs, downloads, etc, on their own data partition(s). This should be distinguished clearly from what the OS will store in your /home/username directory. The latter stores a lot of needed information that is very specific to the installed operating system but is strictly not personal data in the full sense. There is a way to keep these two significantly different forms of data separated, avoiding many problems including : --
* duplication or lack of access to data between the various operating systems,
* loss of data when re-installing an operating system

To see more on this topic in depth, refer to the on-line tutorial at http://sblinux.org/pages/symlink-home.html  or alternatively at http://www.gnulinuxuser.net/2-cu/data-01.html

 

Suggested Partitioning Structure.

 

For the sake of this tutorial, I will create an illustrative partition layout which will then form the basis of this tutorial hereafter.

The first partition of the first hard drive will be referred to variously, by GRUB Legacy as (hd0,0), by GRUB-PC as (hd0,1), by LILO as (), by MS Windows as '\:C', by Linux as hda1

Here then is the layout, in Linux terminology.

Primary 1    hda1, file system FAT32 [or vfat], MS Windows 98, XP, Vista, 7

Primary 2    hda2,   Main Other OS

Primary 3     Swap partition [at least double your installed RAM ]

Primary 4    Extended Partition

Logical 5     Data 1, emails, documents, PIM, etc

Logical 6    Data 2, Photographs, Video clips,

Logical 7    Data 3, Downloads

Logical 8    Backups of personal data

Logical 9    Experimental OS installation 1

Logical 10    Experimental OS installation 2

You get the idea!

I'll assume that MS Windows was installed first, occupies the entire hard drive and has control of the MBR initially. You may be able to re-size the MS Windows partition and create the partitioning I have shown, or it may be necessary to add a second hard drive for the additional partitions and leave MS Windows to its own. These days Linux has no difficulty in mounting a partition that has been set up by MS Windows, in either FAT32 or NTFS file format, meaning that you can access your personal data there from within a Linux installation later on. But if you are starting from bare metal, installing MS Windows yourself and then the other operating systems, then the layout in my example is straight forward to implement.

 

Current starting Conditions in Target System under review.

 

Starting conditions : --

 

robert@robert-pardus ~ $ blkid
/dev/sda1: LABEL="WIN98" UUID="1724-16EF" TYPE="vfat" 
/dev/sda3: UUID="86d22688-98e1-419e-8aa4-252eb2802238" TYPE="swap" 
/dev/sda4: LABEL="XANDROS" UUID="de66e74a-a7c6-457c-a2ca-8567d5b7ce7b" TYPE="reiserfs" 
/dev/sda5: LABEL="UTILITIES" UUID="1569-19E6" TYPE="vfat" 
/dev/sda6: LABEL="PARDUS_ROOT" UUID="2f2e8162-b0bc-426e-bab4-de60b7aa364d" TYPE="ext4" [ _______________Note : The UUID is changed each time the partition is reformatted
/dev/sda7: LABEL="PARDUS_HOME" UUID="96847a79-b707-4351-b6fd-9ed74ea9505c" TYPE="ext4" [ _______________
Note : The UUID is changed each time the partition is reformatted
/dev/sda8: LABEL="APPLICATION" UUID="4560-A577" TYPE="vfat" 
/dev/sda9: LABEL="GAMES" UUID="2F2D-0F0B" TYPE="vfat" 
robert@robert-pardus ~ $

 

Boot-loaders

 

LILO

 

LILO stands for LInux LOader, and was the standard boot loader for Linux until GRUB came into vogue. It is more simple than GRUB and is still preferred by some users, but it is getting left behind with recent developments.

 

GRUB Legacy [up to version 0.97 ]

 

GRUB stands for 'GRand Unified Bootloader'  and has been almost universally adopted by Linux distros for some time. The older versions are now being overtaken by the latest major revision and re-design of the application, being called GRUB2 or more recently GRUB-PC

 

GRUB-PC       [ version 0.98 upwards ]

 

This is the latest development of the GNU GRUB utility and is being increasingly used with later releases of Linux.

 

 

The Master Boot Record.

 

What is the Master Boot Record [MBR]?

MBR stands for Master Boot Record. It is located in the first sector of the first hard disk or a floppy disk. It contains a small program that is read into memory and executed at boot (after the BIOS bootup). The program tries to find a bootable partition in the partition table (which is located in the end of the MBR sector). The boot sector of the partition is then loaded and executed. This normally is some boot loader but can also be an actual kernel of some specific OS. In Linux LILO or GRUB is usually installed in the MBR.

 

Backing up the MBR

In linux the MBR can be directly accessed with dd. For example to make a backup of the MBR:

# dd if=/dev/hda of=/path/mbr-backup bs=512 count=1

and restore it with

# dd if=/path/mbr-backup of=/dev/hda bs=512 count=1

Change hda to sda for SCSI or SATA drives.

Change to the a of hda to b or c etc for drives on other controllers.

 

See also


Read more: http://wiki.linuxquestions.org/wiki/MBR#ixzz0wfK2Njlo

 

Chainloading

 

Chain-loading LILO from GRUB Legacy

 

Here's a how-to for chain-loading LILO from GRUB Legacy : --

 

Kubuntu Boot LILO by GRUB

 

Chain-loading another boot-loader in GRUB

 

Load another boot loader to boot unsupported operating systems

If you want to boot an unsupported operating system (e.g. Windows 95), chain-load a boot loader for the operating system. Normally, the boot loader is embedded in the boot sector of the partition on which the operating system is installed.

  1. Set GRUB's root device to the partition by the command @command{rootnoverify} (see section rootnoverify):
    grub> rootnoverify (hd0,0)
    
  2. Set the active flag in the partition by the command @command{makeactive}(5) (see section makeactive):
    grub> makeactive
    
  3. Load the boot loader by the command @command{chainloader} (see section chainloader):
    grub> chainloader +1
    
    `+1' indicates that GRUB should read one sector from the start of the partition. The complete description about this syntax can be found in section How to specify block lists.
  4. Run the command @command{boot} (see section boot).

However, DOS and Windows have some deficiencies, so you might have to use more complicated instructions. See section DOS/Windows, for more information.

 

 

Working with GRUB

 

Here is a how-to for GRUB Legacy   Grub From the Ground Up

 

Examine Current menu.lst from running installed Linux.

While running an installed Linux you can examine the current state of the menu.lst file, by running the following command in a Konsole window : --

 

sudo grub --config-file \(hd0,0\)/boot/grub/menu.lst  [Note the '\' 'escape character' otherwise GRUB cannot parse the command.]

 

paul@paul-ArtistX07:~$ sudo grub --config-file \(hd0,0\)/boot/grub/menu.lst
[sudo] password for paul:
Probing devices to guess BIOS drives. This may take a long time.
paul@paul-ArtistX07:~$

This produced, in the Konsole window, the familiar black window with boot options, in fact a virtual GRUB! Everything works the same as at boot-up except that, as far as I can tell, it will not boot anything.

 

 

 

Working with LILO

 

Here is a mini-how-to for LILO    LILO mini-HOWTO

 

Chain-loading another boot-loader in LILO

 

 

 

How to make a Grub floppy/CD that boots all systems in a PC

 

This tutorial gives a very useful method of creating either a floppy disk or a CD which can be used to boot all the operating systems that have been installed on the computer. This is a useful exercise to learn about the process, it is also useful for booting external drives and as a rescue disk if anything should go wrong with the boot-up process in the future. 

 

Read more at the above link [the heading]

 

 

Making a partition bootable.

 

When an operating system has been installed with the boot-loader installed to both the MBR and the root file system, then that partition needs further attention to make it bootable from another boot-loader that now is installed to the MBR.

 

Here are the instructions, for LILO and GRUB, to copy the data from the MBR to the root partition and make it bootable with chainloading.

 

The "sole" necessary condition for Grub to chain-load a system is that the system must have its own boot code or boot loader inside the boot sector of its own partition. This is automatically arranged in the installation of any MS system, BSD and Solaris. In GNU/Linux a choice is often given by the installer to be either in the MBR or in the root partition. The two are the same if the Linux resides in hda1. If a Linux has placed its boot loader in the MBR then its boot code can be replicated in root partition, say it is the hdc39 partition, by

grub-install /dev/hdc39

or

lilo -b /dev/hdc39

depending on its boot loader being Grub or Lilo respectively.

 

Step by step instructions for the target system.

 

I will show this as a separate page for ease of printing and following.

 

Read more at the above link [the heading]

 

 

Back-up and Restore the MBR

 


MBR backup


In order to backup only the first few bytes containing the MBR and the partition table you can use dd as well.

dd if=/dev/hdx of=/path/to/image count=1 bs=512


MBR restore


dd if=/path/to/image of=/dev/hdx

Add "count=1 bs=446" to exclude the partition table from being written to disk. You can manually restore the table.

end

 


2.4 How Can I Uninstall Lilo?

When Lilo overwrites a boot sector, it saves a backup copy in /boot/boot.xxyy, where xxyy are the major and minor numbers of the device, in hex. You can see the major and minor numbers of your disk or partition by running ``ls -l /dev//device''. For example, the first sector of /dev/hda (major 3, minor 0) will be saved in /boot/boot.0300, installing Lilo on /dev/fd0 creates /boot/boot.0200 and installing on /dev/sdb3 (major 8, minor 19) creates /boot/boot.0813. Note that Lilo won't create the file if there is already one so you don't need to care about the backup copy whenever you reinstall Lilo (for example, after recompiling your kernel). The backup copies found in /boot/ are always the snapshot of the situation before installing any Lilo.

If you ever need to uninstall Lilo (for example, in the unfortunate case you need to uninstall Linux), you just need to restore the original boot sector. If Lilo is installed in /dev/hda, just do ``dd if=/boot/boot.0300 of=/dev/hda bs=446 count=1'' (I personally just do ``cat /boot/boot.0300 > /dev/hda'', but this is not safe, as this will restore the original partition table as well, which you might have modified in the meanwhile). This command is much easier to run than trying ``fdisk /mbr'' from a DOS shell: it allows you to cleanly remove Linux from a disk without ever booting anything but Linux. After removing Lilo remember to run Linux' fdisk to destroy any Linux partition (DOS' fdisk is unable to remove non-dos partitions).

If you installed Lilo on your root partition (e.g., /dev/hda2), nothing special needs to be done to uninstall Lilo. Just run Linux' fdisk to remove Linux partitions from the partition table. You must also mark the DOS partition as bootable.

 

Comments (0)

You don't have permission to comment on this page.