Best Industrial Training in C,C++,PHP,Dot Net,Java in Jalandhar

Sunday, 1 December 2013

Grub Intro and TroubleShooting in Grub



 a boot loader is the first software program that runs when a computer starts. It is responsible for loading and transferring control to an operating system kernel software (such as Linux or GNU Mach). The kernel, in turn, initializes the rest of the operating system (e.g. a GNU system).

GNU GRUB is a very powerful boot loader, which can load a wide variety of free operating systems, as well as proprietary operating systems with chain-loading. GRUB is designed to address the complexity of booting a personal computer; both the program and this manual are tightly bound to that computer platform, although porting to other platforms may be addressed in the future.
One of the important features in GRUB is flexibility; GRUB understands filesystems and kernel executable formats, so you can load an arbitrary operating system the way you like, without recording the physical position of your kernel on the disk. Thus you can load the kernel just by specifying its file name and the drive and partition where the kernel resides.

When booting with GRUB, you can use either a command-line interface , or a menu interface. Using the command-line interface, you type the drive specification and file name of the kernel manually. In the menu interface, you just select an OS using the arrow keys. The menu is based on a configuration file which you prepare beforehand . While in the menu, you can switch to the command-line mode, and vice-versa. You can even edit menu entries before using them.
 

GRUB features

The primary requirement for GRUB is that it be compliant with the Multiboot Specification, which is described in Multiboot Specification.
The other goals, listed in approximate order of importance, are:
  • Basic functions must be straightforward for end-users.
  • Rich functionality to support kernel experts and designers.
  • Backward compatibility for booting FreeBSD, NetBSD, OpenBSD, and Linux. Proprietary kernels (such as DOS, Windows NT, and OS/2) are supported via a chain-loading function.
Except for specific compatibility modes (chain-loading and the Linux piggyback format), all kernels will be started in much the same state as in the Multiboot Specification. Only kernels loaded at 1 megabyte or above are presently supported. Any attempt to load below that boundary will simply result in immediate failure and an error message reporting the problem.
In addition to the requirements above, GRUB has the following features:

Recognize multiple executable formats
Support non-Multiboot kernels
Load multiples modules
Load a configuration file
Provide a menu interface
Have a flexible command-line interface
Support multiple filesystem types
Support automatic decompression
Access data on any installed device
Be independent of drive geometry translations
Detect all installed ram
Support Logical Block Address mode
Support network booting
Support remote terminals
 

Installing GRUB using grub-install

For information on where GRUB should be installed on PC BIOS platforms, see BIOS installation.
In order to install GRUB under a UNIX-like OS (such as gnu), invoke the program grub-install (see Invoking grub-install) as the superuser (root).
The usage is basically very simple. You only need to specify one argument to the program, namely, where to install the boot loader. The argument has to be either a device file (like ‘/dev/hda’). For example, under Linux the following will install GRUB into the MBR of the first IDE disk:
     # grub-install /dev/hda
Likewise, under GNU/Hurd, this has the same effect:
     # grub-install /dev/hd0
But all the above examples assume that GRUB should put images under the /boot directory. If you want GRUB to put images under a directory other than /boot, you need to specify the option --boot-directory. The typical usage is that you create a GRUB boot floppy with a filesystem. Here is an example:
     # mke2fs /dev/fd0
     # mount -t ext2 /dev/fd0 /mnt
     # mkdir /mnt/boot
     # grub-install --boot-directory=/mnt/boot /dev/fd0
     # umount /mnt
Some BIOSes have a bug of exposing the first partition of a USB drive as a floppy instead of exposing the USB drive as a hard disk (they call it “USB-FDD” boot). In such cases, you need to install like this:
     # losetup /dev/loop0 /dev/sdb1
     # mount /dev/loop0 /mnt/usb
     # grub-install --boot-directory=/mnt/usb/bugbios --force --allow-floppy /dev/loop0
This install doesn't conflict with standard install as long as they are in separate directories.
Note that grub-install is actually just a shell script and the real task is done by grub-mkimage and grub-setup. Therefore, you may run those commands directly to install GRUB, without using grub-install. Don't do that, however, unless you are very familiar with the internals of GRUB. Installing a boot loader on a running OS may be extremely dangerous.
 

Troubleshooting:


Error messages produced by GRUB

 GRUB only offers a rescue shell
GRUB's normal start-up procedure involves setting the ‘prefix’ environment variable to a value set in the core image by grub-install, setting the ‘root’ variable to match, loading the ‘normal’ module from the prefix, and running the ‘normal’ command. This command is responsible for reading /boot/grub/grub.cfg, running the menu, and doing all the useful things GRUB is supposed to do.
If, instead, you only get a rescue shell, this usually means that GRUB failed to load the ‘normal’ module for some reason. It may be possible to work around this temporarily: for instance, if the reason for the failure is that ‘prefix’ is wrong (perhaps it refers to the wrong device, or perhaps the path to /boot/grub was not correctly made relative to the device), then you can correct this and enter normal mode manually:
     # Inspect the current prefix (and other preset variables):
     set
     # Find out which devices are available:
     ls
     # Set to the correct value, which might be something like this:
     set prefix=(hd0,1)/grub
     set root=(hd0,1)
     insmod normal
     normal
However, any problem that leaves you in the rescue shell probably means that GRUB was not correctly installed. It may be more useful to try to reinstall it properly using grub-install device. When doing this, there are a few things to remember:
  • Drive ordering in your operating system may not be the same as the boot drive ordering used by your firmware. Do not assume that your first hard drive (e.g. ‘/dev/sda’) is the one that your firmware will boot from. device.map can be used to override this, but it is usually better to use UUIDs or file system labels and avoid depending on drive ordering entirely.
  • At least on BIOS systems, if you tell grub-install to install GRUB to a partition but GRUB has already been installed in the master boot record, then the GRUB installation in the partition will be ignored.
  • If possible, it is generally best to avoid installing GRUB to a partition (unless it is a special partition for the use of GRUB alone, such as the BIOS Boot Partition used on GPT). Doing this means that GRUB may stop being able to read its core image due to a file system moving blocks around, such as while defragmenting, running checks, or even during normal operation. Installing to the whole disk device is normally more robust.
  • Check that GRUB actually knows how to read from the device and file system containing /boot/grub. It will not be able to read from encrypted devices, nor from file systems for which support has not yet been added to GRUB.


No comments:

Post a Comment