====== Booting ====== ===== Introduction ===== * The basic process of booting into Linux is seen in this little diagram: * Power-up --> BIOS --> Stage 1 bootloader in the Master Boot Record --> Stage 2 bootloader (LILO, GRUB) --> Kernel --> Init * Read the article "The Linux Boot Sequence" at [[http://wiki.freegeek.org/index.php/The_Linux_Boot_Sequence|Free Geek Wiki]] for a discussion of this process. It gives the SysVInit process for Init, but does mention Upstart which is being used beginning with Ubuntu 6.10 (Edgy). See "Upstart Plans to Ease Linux Management" by Carla Schroder on [[http://linuxplanet.com/linuxplanet/reports/6366/3/|LinuxPlanet]] for an in-depth discussion of that. ===== Methods for Booting: ===== - Boot Manager - Usually GRUB, but some distros use LILO - LiveCD or Rescue CD - when things get broken, you can usually boot with one of these. See Rescue about this. - Ancient history (See [[:historical:old_booting_page|archived booting page]] for a little more on these) * Floppy Disk - kernel put on a floppy. Rather old, because kernels are usually too big for a floppy currently * Loadlin - Old way of booting from Windows ===== How to set up booting ===== The process for booting is set up during installation. If you have Windows or other operating systems on your machine, the installer usually includes them as choices in the boot menu. If they are not included during the installation, you can edit the configuration file for either GRUB or LILO later. ==== Editing GRUB menu.lst ==== Example of stanzas in /boot/grub/menu.lst: title Ubuntu, kernel 2.6.20-16-386 root (hd0,3) kernel /boot/vmlinuz-2.6.20-16-386 root=UUID=3db245ba-320f-4fd1-8671-188f2d36928c ro initrd /boot/initrd.img-2.6.20-16-386 quiet savedefault title Windows root (hd0,0) chainloader +1 Short explanation of stanzas: * title is just the name you want to appear in the menu * root is the partition where the kernel and initrd.img are to be found. This is in GRUB nomenclature where hd0 means the first hard drive and the 3 means 4th partition. GRUB begins numbering with 0! * kernel is the name of the kernel and the location within the partition named in the second line. Also included is the name of the partition to be the root of your system. This is often the same as the root in the second line, but the naming of it will now be according to Linux and not according to GRUB. This used to be something like /dev/hda4, but newer distros are using the [[UUID naming]]. This is not the place to go into the reasons for that. 'ro' on the end means to initially boot the partition as read only. * initrd line is location of the initrd.img. * Note that the Windows stanza uses chainloader To add something that is missing, you need to make a similar stanza with the root, kernel, initrd.img etc. With GRUB all you need to do is edit /boot/grub/menu.lst to add the stanza. You do not need to update GRUB in the MBR. You can change the order of the items listed in the menu by moving them in menu.lst. Normally the default to boot is the first one. You can change that default by changing the number in the line "default 0" near the top of menu.lst. Remember that GRUB starts with number 0; so if you want to boot the 2nd item in the list by default, change the "0" to "1" on that default line. For more on GRUB see the [[http://www.gnu.org/software/grub/manual/grub.html|GNU GRUB Manual 0.97]] === Using chainloader with GRUB for multi-booting === In the example menu.lst above, you will see that the Windows stanza is using "chainloader". You can use this for Linux distros as well. Using chainloader, you will not have to find the exact kernel and initrd.img names. When you install your second (or more) distro, just install the boot loader in the root partition rather than the MBR. (See Note below if did not elect to install grub in the root partition when you installed the second distro.) Then reboot into the distro that you used to install GRUB with. Edit the /boot/grub/menu.lst there and add a stanza for your new distro. Lets suppose you installed Debian Etch in partition 9. You would add this stanza: title Debian Etch chainloader (hd0,8)+1 Then you can reboot and choose Debian Etch and you will see the boot loader for that appear. The nice thing is that now, whatever distro you put on partition 9 will boot when you select that title. Of course, if you change the distro on that partition, it would be good to change the title on your grub menu.lst. The downside: you slow down your boot up sequence because you load 2 bootloaders, and you have to select twice (or let 2 default choices happen). You can speed it up by editing the config file for the second boot loader to have a shorter default waiting time. **Note:** If you already have your second distro installed and did not install grub in the root partition, it is an easy thing to fix. Before you edit menu.lst to change to using the chainloader, boot to the second distro. Install grub (as root or using sudo) in the root partition with: update-grub grub-install /dev/hdxx where //hdxx// is the root partition, for example ///dev/sda6//. Then reboot into your main distro and edit menu.lst to use chainloader for the second distro. ==== Editing LILO lilo.conf ==== Example of stanzas in /etc/lilo.conf: boot=/dev/hda default="windows" image=/boot/vmlinuz-2.4.20 initrd=/boot/initrd.img-2.4.20 label=Linux root=/dev/hdb2 read-only other=/dev/hda1 label=windows table=/dev/hda Short explanation of stanzas: * The top line shows where LILO will be located. /dev/hda indicates the MBR of the first hard drive * default is the operating system to boot by default. The label is used here. * image is the kernel name and path relative to the root partition * initrd is the location of the initrd.img * label is what appears in the menu listing * root is the root partition for the system. * read-only means the partition should be booted as read only * The Windows stanza uses gives the location of the Windows partition with "other" and uses "table" in the last line. To add something that is missing, just add a stanza with the information about the kernel, initrd.img, root, and a label. With LILO you must run "/sbin/lilo" as root in order to have the changes take place. You can change the default operating system to boot by changing the default to the label of choice. For more on LILO see [[http://linuxbasics.org/LDP/HOWTO/LILO.html|LILO mini-HOWTO]] by Miroslav Skoric. ===== What about inittab? ===== You will often read about ///etc/inittab// and that you can edit it to change default runlevel or what happens when you press Ctrl-Alt-Delete. Upstart (mentioned above) does not include /etc/inittab. Things are a little different if your system is using Upstart. Here are a couple of the FAQs from /usr/share/doc/upstart/README.Debian.gz. - How do I change the default runlevel? * Edit the /etc/inittab file, if you installed edgy fresh you'll need to create it. Locate, or write, the following line: \\ **id:N:initdefault:** \\ Where N is the default runlevel, change this to match. - How do I change the behaviour of Control-Alt-Delete? * Edit the /etc/event.d/control-alt-delete file, the line beginning "exec" is what upstart will run when this key combination is pressed. * To not do anything, you can simply delete this file. After deleting the file, you need to "kill 1" to ensure that the job is removed from its memory. ===== What to do if you overwrite your MBR ===== The way this usually happens is when you reinstall Windows and it overwrites the MBR. You will need to boot from a [[http://linuxbasics.org/tutorials/using/rescue_disk|rescue disk]] or your installation cd. Some of them have a selection in the menu for system repair which usually has a section for reinstalling GRUB. If not, boot with the rescue disk/LiveCD and then using your actual partition rather than /dev/hda3 do: sudo su - mount /dev/hda3 /mnt chroot /mnt grub-install /dev/hda Note: Use only 'su -' if your rescue disk doesn't use sudo. chroot causes you to use the partition rather than the LiveCD to run the commands. Running grub-install from the Rescue Disk or LiveCD alone will not work, but if you run it from the partition, it will use what is in /boot/grub and put grub back in the MBR where it belongs. ===== Comparison of GRUB and LILO ===== [[http://www-128.ibm.com/developerworks/library/l-bootload.html?ca=dgr-lnxw01LILOandGRUB|Boot loader showdown: Getting to know LILO and GRUB]] by Laurence Bonney at IBM DevelopmentWorks about GRUB and LILO, contrasting and comparing the two. ===== Grub Command Line ===== You can use the [[:tutorials:advanced:GRUB Command Line]] to find information that will allow you to boot when the selections in your GRUB menu are not working.