GRUB – Booting
Welcome to the tutorial guide. The tutorial will provide a user with guidance and instructions on GRUB booting. Please note that GRUB has two distinct boot methods. One of the two is to load an operating system directly, and the other is to chain-load another boot loader which then will load an operating system actually.
As the boot method that is to load and operating system directly is best and a reason for it is that a user don’t need to install or maintain other boot loaders and GRUB is flexible enough to load an operating system from an arbitrary disk/partition. Let’s start to load an operating system directly by following the step as mentioned below:
How to boot an OS directly with GRUB
Multiboot is the native format supported by GRUB. For the sake of convenience, there is also support for Linux, FreeBSD, NetBSD and OpenBSD. If a user wants to boot other operating systems, then he/she will have to chain-load
A user can follw the steps so that GRUB can boot any Multiboot-compliant OS:
• A user should set GRUB’s root device to the drive where the OS images are stored with the command root
• Then a user can load the kernel image with the command kernel
• Now, if a user needs modules, then he/she can load them with the command module or modulenounzip
• Finally, a user can run the command boot
A user can boot Linux, FreeBSD, NetBSD and OpenBSD in a similar manner. A user can load a kernel image with the command kernel and then run the command boot. If the kernel requires some parameters, then a user has to append the parameters to kernel, after the file name of the kernel.
Load another boot loader to boot unsupported operating systems
If a user wants 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. A user can follow the steops as mentioned below@
• A user can set GRUB’s root device to the partition by the command rootnoverify
• grub> rootnoverify (hd0,0)
• now a user can set the active flag in the partition using the command makeactive:
• grub> makeactive
• now a user can load the boot loader with the command chainloader
• grub> chainloader +1
Please note that `+1′ indicates that GRUB should read one sector from the start of the partition.
• Now a user can run the command boot.
GNU/Hurd
As GNU/Hurd is Multiboot-compliant, it is easy to boot it. A user should not forget that he has to specify a root partition to the kernel. A user can follow these steps as meintoned:
• First of all, a user has to set GRUB’s root device to the same drive as GNU/Hurd’s.
• Following command can be helpful for the user. find /boot/gnumach
• Now a user can load the kernel and the module, like this:
o grub> kernel /boot/gnumach root=hd0s1
o grub> module /boot/serverboot
o finally, a user can run the command boot
GNU/Linux
It is easy to boot GNU/Linux from GRUB, because it resembles to boot a Multiboot-compliant OS.
o First of all a user can set GRUB’s root device to the same drive as GNU/Linux’s.
o Following command be prove helpful. The command find /vmlinuz
o Now a user can load the kernel by running following command:grub> kernel /vmlinuz root=/dev/hda1
If a user wants to specify some kernel parameters, then a user can append them to the command. For example, to set vga to `ext’, a user can run following command:
grub> kernel /vmlinuz root=/dev/hda1 vga=ext
o If a user is using an initrd, then he/she has to execute the command initrd after kernel by running following command: grub> initrd /initrd
o In end, a user can run the command boot
A user should know that if he/she is using an initrd and specify the `mem=’ option to the kernel to let it use less than actual memory size, then he/she will also have to specify the same memory size to GRUB. In order to let GRUB know the size, a user should run the command uppermem before loading the kernel.
FreeBSD
GRUB can load the kernel directly, either in ELF or a.out format. But this is not recommended, since FreeBSD’s bootstrap interface sometimes changes heavily, so GRUB can’t guarantee to pass kernel parameters correctly.
NetBSD
GRUB can load NetBSD a.out and ELF directly. This can be provided in the steps as below:
o A user can set GRUB’s root device with root
o Now a user can load the kernel with kernel. It is recommended that at user should append the ugly option –type=netbsd, if he/she wants to load an ELF kernel, like this: grub> kernel –type=netbsd /netbsd-elf
o Finally, a user can run boot.
DOS/Windows
As GRUB cannot boot DOS or Windows directly, so a user should chain-load them. However, their boot loaders have some critical deficiencies, so it may not work to just chain-load them. In order to overcome the problems, GRUB provides a user with two helper functions.
If a user has installed DOS (or Windows) on a non-first hard disk, then he/she has to use the disk swapping technique, because that OS cannot boot from any disks but the first one. The workaround used in GRUB is the command map like this:
grub> map (hd0) (hd1)
grub> map (hd1) (hd0)
This performs a virtual swap between the first and second hard drive.
A user should note that this is effective only if DOS (or Windows) uses BIOS to access the swapped disks. If that OS uses a special driver for the disks, this might not work.
A user might encounter another problem if he/she has installed more than one set of DOS/Windows onto one disk, because in this way a user could be confused if there are more than one primary partitions for DOS/Windows. There is a solution to this which is that a user should use the partition hiding/unhiding technique.
If GRUB hides a DOS (or Windows) partition, DOS (or Windows) will ignore the partition. If GRUB unhides a DOS (or Windows) partition, DOS (or Windows) will detect the partition. If a user has installed DOS (or Windows) on the first and the second partition of the first hard disk, and wants to boot the copy on the first partition, then he/she can run following command:
grub> unhide (hd0,0)
grub> hide (hd0,1)
grub> rootnoverify (hd0,0)
grub> chainloader +1
grub> makeactive
grub> boot
SCO UnixWare
It is known that the signature in the boot loader for SCO UnixWare is wrong, so a user will have to specify the option –force to chainloader. This is provided below:
grub> rootnoverify (hd1,0)
grub> chainloader –force +1
grub> makeactive
grub> boot
QNX
As QNX seems to use a bigger boot loader, so a user has to boot it up. This is provided below:
grub> rootnoverify (hd1,1)
grub> chainloader +4
grub> boot
If a user wants to make the system robust then he should know that when testing a new kernel or a new OS, it is important to make sure that users computer can boot even if the new system is unbootable. This is important if a user maintains servers or remote systems. In order to do this a user has to setup following:
• A user has to maintain a system which is always bootable. For instance, if a user tests a new kernel, then he/she will need to keep a working kernel in a different place.
• A user should direct GRUB to boot a working system when the new system fails. This is possible with the fallback system in GRUB.
The former requirement is very specific to each OS, so it is best to use GRUB.
There are two possibilities: one of them is quite simple but not very robust, and the other is a bit complex to set up but probably the best solution to make sure that a users system can start as long as GRUB itself is bootable.
Booting once-onlyA user can teach GRUB to boot an entry only at next boot time. Suppose that a user has an old kernel old_kernel and a new kernel new_kernel. A user should know that old_kernel can boot his/her system correctly, and he/she wants to test new_kernel.
In order to ensure that the system will go back to the old kernel even if the new kernel fails, a user can specify that GRUB should try the new kernel only once and boot the old kernel after that.
A user has to modify his/her configuration file. An example is provideed below:
default saved # This is important!!!
timeout 10
title the old kernel
root (hd0,0)
kernel /old_kernel
savedefault
title the new kernel
root (hd0,0)
kernel /new_kernel
savedefault 0
A user should note that this configuration file uses `default saved’ at the head and `savedefault 0′ in the entry for the new kernel. This means that GRUB boots a saved entry by default, and booting the entry for the new kernel saves `0′ as the saved entry.
With this configuration file, after all, GRUB always tries to boot the old kernel after it booted the new one, because `0′ is the entry of the old kernel.
The next step is to tell GRUB to boot the new kernel at next boot time. In order to do this a user has to execute grub-set-default by running following code:
# grub-set-default 1
This command sets the saved entry to `1′, that is, to the new kernel.
A user should note that if GRUB stops booting, if there is any error in the boot entry, such that the new kernel has an invalid executable format. Here a user has to use the fallback mechanism of GRUB.
Booting fallback systems
As GRUB supports a fallback mechanism of booting one or more other entries if a default boot entry fails, so it is a good idea sthat a user should specify multiple fallback entries.
Suppose that a user has three systems, `A’, `B’ and `C’. `A’ is a system which a user wants to boot by default. `B’ is a backup system which is supposed to boot safely. `C’ is another backup system which is used in case where `B’ is broken.
Then a user may want GRUB to boot the first system which is bootable among `A’, `B’ and `C’. A configuration file can be written in this way:
default saved # This is important!!!
timeout 10
fallback 1 2 # This is important!!!
title A
root (hd0,0)
kernel /kernel
savedefault fallback # This is important!!!
title B
root (hd1,0)
kernel /kernel
savedefault fallback # This is important!!!
title C
root (hd2,0)
kernel /kernel
savedefault
Please note that `default saved’, `fallback 1 2′ and `savedefault fallback’ are used. GRUB will boot a saved entry by default and save a fallback entry as next boot entry with this configuration.
When GRUB tries to boot `A’, GRUB saves `1′ as next boot entry, because the command fallback specifies that `1′ is the first fallback entry. The entry `1′ is `B’, so GRUB will try to boot `B’ at next boot time.
Similarly, when GRUB tries to boot `B’, GRUB saves `2′ as next boot entry, because fallback specifies `2′ as next fallback entry. This makes sure that GRUB will boot `C’ after booting `B’.
It is imporant to know that GRUB uses fallback entries both when GRUB itself fails in booting an entry and when `A’ or `B’ fails in starting up the system. This solution ensures that a users system is started even if GRUB cannot find his/her kernel or if a users kernel panics.
It is recommended that a user should run grub-set-default when `A’ starts correctly or a user fix `A’ after it crashes, since GRUB always sets next boot entry to a fallback entry. A user can run a command in a startup script such as rc.local to boot `A’ by default:
# grub-set-default 0
Please note that `0′ is the number of the boot entry for the system `A’.
If a user wants to see what is current default entry, then he/she can look at the file /boot/grub/default (or /grub/default in some systems). As this file is plain-text, a user can just cat this file. A user should not modify this file directly. The reason behind this is that GRUB may fail in saving a default entry in this file, if a user change this file in an unintended manner.
If a user followed this tutorial guide then he/she would have learnt about GRUB booting.













