A computer pulls itself up by it's bootstraps...
First CMOS (complementary metal oxide semiconductor) has instructions for hardware initialization and instructions for a quick POST (power on self test) ... aka...
The BIOS (basic input output system but sometimes referred to as aka firmware) on the motherboard (or sometimes a SCSI controller, RAID controller, graphics card, etc.) is the code about how to do the most basic things. (ie Stored on the CMOS)
The BIOS determines which devices are bootable and "initiates the bootstrap"... (that's why you set the sequential order of checking Boot Devices in the BIOS configuration)
The first sector on a device (traditionally the hard drive) is the MASTER BOOT RECORD. The MBR looks for a partition marked as Active and passes on control...
GRUB (grand unified boot loader) replaces the default MBR ntldr is that other operating system's executable that gets control from the MBR...
GRUB "stage 2" gets control from GRUB stage one (which has replaced the MBR) from there it loads the Kernel and the Initial RamDisk.
The Linux Kernel is a file that contains most of the drivers (code written so that your Operating System can communicate with the hardware)
INITRD (initial ramdisk) ... the initial "root" filesystem that is actually located in RAM (hence "ramdisk")
TO INSTALL GRUB IN THE MBR
grub
grub> root (hd0,0) grub> setup (hd0) grub> quit
reboot
note that (hd0,0) is the same as /dev/hda , /dev/hd0
grub-install '(hd0)' //to update grub by passing a parameter
NOTE: even if grub can't find stage 2 it will drop to the GRUB command line for manual configuration
(see my menu.lst example file or ...) your /boot/grub/menu.lst should contain helpful things like:
default 0 timeout 30
title Boot Arch Linux Live CD [Legacy IDE, no SATA] kernel /boot/vmlinuz26 lang=en locale=en_US.UTF-8 archisolabel=ARCHISO_AHCOHH6O ramdisk_size=75% initrd /boot/archiso_ide.img
title Grub Settings in another LST menu file configfile /boot/grub/settings.lst
title Windows Xp rootnoverify (hd0,1) makeactive chainloader +1
title debian root (hd0,3) chainloader +1
title Install Linux kernel (hd0,4) /boot/LINUX_KERNEL_FILENAME initrd (hd0,4) /boot/RAM_DISK_FILENAME
title Reboot the Computer reboot
title Shutdown the Computer halt
default 0 = first menu choice is the default timeout 30 = 30 seconds to pick something from the menu before default is booted title = text displayed in the Grub Menu
/boot/Linux_kernel where to find that operating system's kernel file /boot/Ram_disk where to find that operating system's ram disk image file
root = where the operating system (linux) are... rootnoverify = do not check for a root directory (which windows doesn't have)
(hd0,1) means the first hard disk, the second partition (0 is the first partition) makeactive ? chainloader +1 means GRUB is now passing control onto another loader (ntldr)
LINUX_KERNEL_FILENAME and RAM_DISK_FILENAME (initrd) for many distributions:
Debian: vmlinuz and initrd.gz Ubuntu: vmlinuz and initrd.gz Knoppix: vmlinuz and initrd.img Fedora: vmlinuz and initrd.img Suse: linux and initrd Mandriva: vmlinuz and all.rdz Gentoo: gentoo and gentoo.igz Slackware: bzImage and initrd.img
Arch ISO: vmlinuz26 and ARCHISO_IDE.img tinycore: bzImage and tinycore.gz PUPPY: vmlinuz and initrd.gz
GRUB 2 is the next version of GRUB... partition entries start from 1, NOT 0 (hd0,1)
/boot/grub/grub.cfg //replaces menu.lst and not intended for direct editing /etc/grub.d/ //directory with GRUB scripts, these allow
nano /etc/default/grub //this is how we configure GRUB so that the scripts //run and update grub.cfg
00_header 10_linux
00_: Reserved for 00_header. 10_: Native boot entries. 20_*: Third party apps (e.g. memtest86+).
30_otheros
!/bin/sh
exec tail -n +3 $0
This entry automatically added by the Debian installer for a non-linux OS
on /dev/hda1
menuentry "WinXP" { set root=(hd0,1) chainloader +1 }
this file has a few more grub settings, most importantly, the timeout
update-grub //MUST be run after updating /etc/default/grub
cp --preserve -R /{bin,dev,home,pentest,root,usr,boot,etc,lib,opt,sbin,var} /mnt/bt/
once systemrescuecd is booted at the command line prompt
mkdir /ubuntu
mount /dev/sda1 /ubuntu //sda1 = wherever your base installation is
chroot /ubuntu /bin/bash
ls //shows you your lovely old files grub //interactive
root (hd0,0) //set the GRUB's root device(4) to the partition containing the boot directory
grub-install /boot?
BOOT.INI controls NTLDR in that other operating system
[boot loader] timeout=30 default=multi(0)disk(0)rdisk(0)partition(2)\WINDOWS [operating systems] multi(0)disk(0)rdisk(0)partition(2)\WINDOWS="Win XP" /noexecute=optin /fastdetect
Apparently to add linux you can add the following line at the end of boot.ini c:\bootsect.lnx="Linux"
BUT this also requires that you copy the first 512 bytes of your linux installation (it's boot partition info) into a file that Windows can read:
From linux (if your linux installation is on the first partition of the second ide drive, "b1") dd if=/dev/hdb1 of=bootsect.lnx size=512 count=1
DO NOT MIX UP if FIRST and of SECOND!
dd if=bin/stage1 of=/dev/fd0 bs=512 count=1 dd if=bin/stage2 of=/dev/fd0 bs=512 seek=1
dd if=/dev/fd0 of=/home/sam/MBRboot.image bs=512 count=2
This copies the first 2 sectors of the floppy
dd if=/dev/sda count=1 | hexdump -C //displays to screen first sector (hex)
mount -o loop -t iso9660
cd /mnt/iso cp file.txt /tmp
INTERESTING FACTS TO KNOW ABOUT THE BIOS AND BOOTING
The BIOS can have a password, controls the "system time" of the motherboard (which some operating systems then use)...
The BIOS is stored on Flash Memory or ROM (read only memory) ... which is why manufacturers (and hackers) have "firmware upgrades" where you can "flash the BIOS" (change the code!)
The lithium "button" battery is to keep the BIOS real-time clock ticking...
The BIOS checks memory address 0000:0472, a value of 1234h indicates a reboot (skips the rest of POST = verify RAM, check for keyboard/mouse/input devices, PCI)... which is why reboots are faster than cold boots...
The first sector of a hard disk (often called the Master Boot Record) is loaded at 0000:7C00 and next the BIOS jumps to it.
A VERY THOROUGH LOOK AT LINUX BOOT LOADERS http://www.xs4all.nl/~lennartb/bootloaders/