|
Avoid the Gates of Hell. Use Linux --
Login
|
What happens when I bootIt is actually pretty amazing. First code in your BIOS runs. It resides an a ROM or EPROM, and does a bunch of initialization stuff. Eventually it tell your disk drive to go to sector 0 of track 0 and read in a sector worth's of data into RAM. It then jumps (sets the program counter) to the beginning of that data and executes what it finds there. What it found there is called the master boot record, and it looks like this:
Getting the Master Boot RecordBecome root and try the following on your computer:
dd if=/dev/sda of=mbr.bin bs=512 count=1
fdisk -l /dev/sda | tee fdisk.txt od -Ad -x mbr.bin | tail -c 250 It wouldn't be a bad idea to copy the files mbr.bin and fdisk.txt to a usb key, or some other computer, for safe keeping. At this point grub loads the rest of the system from disk. Eventually control is passed to a program called init, and if the phase of the moon is right and you were nice rather than naughty, your system will come up in X!! Yippie. You will probably do almost all of your interacting with grub in the file menu.lst. Most likely this file will be found at /boot/grub/menu.lst, but it is possbile that yours is located at /boot/boot/grub/menu.lst Please open it (read only) in your favorite editor. Things you really need to knowIn order to do anything with grub, you need to know the following:
Armed with that info, you can configure your menu.lst file to boot linux. Now look near the end of your menu.lst file and find some lines that look like:
What does this mean? Let's take it one at a time.
title Debian GNU/Linux, kernel 2.6.24-etchnhalf.1-amd64
is what appears in the grub menu that is displayed on your screen as the computer is booting up. It can be anything you want it to be, though something meaningful is probably wise.
root (hd0,0)
This tells grub which partition contains the kernel. Grub numbers disks from 0 and numbers partitions on each disk from 0. Thus you may have seen in the past that your filesystem mounts are /dev/hda1. In *grub speak* that is the zeroth partition (1) of the zeroth disk (hda). In times past, I used to have a seperate partition just for the kernel, and I put the rest of my filesystem on a different partition. The rationale was that this was *safer.* These days I don't bother. On the other hand, I am thinking of encrypting my root partition. If I (or you) ever want to do this, you will need a seperate (unencrypted) partition for your kernel.
kernel /boot/vmlinuz-2.6.24-etchnhalf.1-amd64 root=/dev/sda1 ro
This tells grub where the actual kernel image is, relative to the boot parameter you used above. It also tells linux where the root file system is, which contains the file /sbin/init. It my case it is on the same partion as the kernel, namely /dev/sda1. This is also the same parameter you would use with *mount* to mount this filesystem.
initrd /boot/initrd.img-2.6.24-etchnhalf.1-amd64
Some systems need an inital ram disk (initrd) in order to boot themselves. Why? well let's just say that's how it works. It allows the kernel to be small, and to grab whatever drivers it needs to get your system running from a virtual disk (the ram disk). For example, it is probably loading the actual hard disk drivers (either ide or sata or scsi) from the ram disk in order to be able to talk to your disk drive.
savedefault
Finally we have the savedefault command. At the very top of your menu.lst file you will find a command like:
default 0 # boot the first entry
default saved # boot the kernel I booted before savedefault means that if you select that kernel to boot, it should be saved as the default kernel for next time (if you used the default saved option). This seems a little convoluted, but there is a **very good reason** for this. Nothing can make you sweat more than installing a new kernel (or distribution) on a machine a few hundred kilometers away. You check, double check, then triple check. You type reboot, and starting pinging the remote machine. You watch as the *destination host unreachable* message appears, and they you fuss until hopefully the remote machine starts responding. Well, with a little grub magic, you can increase your chances of getting that treasured response. The fallback commandSuppose you have two kernels, an brand new shiny one, called linux-shiny and an old one called linux-reliable. You want to boot your machine into linux-shiny, but just in case something bad happens, have it reboot into good old linux-reliable. You can do this with grub's fallback mechanism. You'll need a menu.lst file like this:
default saved # This is important!!!
timeout 10 fallback 1 # This is important!!! title linux-shiney root (hd0,0) kernel /boot/linux-shiney savedefault fallback # This is important!!! title linux-reliable root (hd0,0) kernel /boot/linux-reliable savedefault Then from the command line you run:
grub-set-default 0
What happens is that grub will boot linux-shiney. While booting linux-shiney, the *savedefault fallback* command is run, which sets the default kernel to 1 (you can have more than one fallback). Now if the kernel panics, or fails to boot, the next time the machine boots it will run linux-reliable. It is up to you to *grub-set-default 0* (pehaps in an init script) if the machine boots successfully into you new shiny kernel. Booting that other operating systemIf you are unfortunate enough to find yourself in a non MFZ (Microsoft Free Zone) you may have to configure grub to boot into that other operating system. Assuming you only have one disk, and that linux is on partiton 1 and windoze is on partition 1, you would add the following to your menu.lst file:
title Windoze
rootnoverify (hd0,0) chainloader +1 title Linux root (hd0,1) kernel /boot/your-kernel-file-here Last, and probably least, just for fun we can install a custom splash screen to display when grub is booting. The image file needs to be a gzipped xpm file, with dimensions 640x480 and no more than 14 colors. It also helps if it was created on a Tuesday under a full moon. Anyway, to see your sexy new boot image, just add:
splashimage=(hd0,0)/boot/your-wonderful-image.xpm.gz
to menu.lst and away you go. May all your grubs be juicy and not taste like warm puss. This article was written by Henry Laxen of the Mazatlan Linux Users Group
|


