<<

KNOW-HOW Ask Klaus! ASK KLAUS!

of partitions, etc. I would also like to the BIOS) for a bootloader. If a boot- know which files are involved, and in loader is found, the bootloader is what order they are read and used. started. Some bootloaders (frequently PCE) may return with a “no luck, con- Klaus Knopper is the creator of The full story would probably tinue” result, and then the next device Knoppix and co-founder of the fill a book, but here are some is tried. things that I think are most im- • The bootloader (LILO, GRUB or the LinuxTag expo. He currently portant to know about the boot process. Windows boot.ini bootloader) reads The following answer may be specific to the operating system kernel from disk/ works as a teacher, program- what is know as the “PC Architecture,” CD-ROM/ USB-flash or another mer, and consultant. If you have usually meaning Intel/ AMD-based pro- bootable device. Optionally ( cessors and corresponding boards. In feature), a compressed a configuration problem, or if other hardware architectures, the boot image is also loaded into memory as a process is similar, yet the process varies “virtual disk.” Kernel and initial ram- you just want to learn more depending on hardware design. disk get decompressed into memory. about how Linux works, send Usually, when you switch on your • Now comes a critical part. At this computer, the hardware runs a short point, the , after option- your questions to: “self-test” sequence that can partly be ally changing the VGA resolution, influenced by the settings stored in the switches to “protected mode,” which klaus@linux-magazine. com BIOS. Parts of this self test are: has a different address scheme. The • A quick RAM check just to see computer “forgets” everything it once whether all addresses of installed found when running the initial self RAM seem to be accessible. (For a tests and drivers. This also means that more thorough test, you can use a tool (apart from a few exceptions), Linux Boot Sequence such as memtest86+). now has to provide its own drivers in Thanks for answering our “aver- • A quick auto-configuration of the PCI order to access any storage media. age user” questions so diligently and (old) ISA bus. Inter- and simply. I am not new to rupts and IO addresses, Linux. In fact, I have been using it since again influenced by BIOS the mid-90s when I installed a mail relay settings, are assigned for and Internet gateway using Red Hat 6. I the initial boot phase. also jumped with joy when my - • A search for “bootable based firewall setup actually worked. At roms” as part of the hard- the time, I could find no support or train- ware initialization. At this ing in my country, and I had to figure ev- point, the graphics card erything out myself. or SCSI adapters can run I have a problem that has been annoy- small configuration sub- ing me for some time. Would you detail routines that don’t re- the steps involved in booting a Linux quire a running operating distribution such as Red Hat? Describe system. every step taken in the boot sequence – • A check of bootable de- loading of bootsector, kernel, mounting vices (in the order set in

60 ISSUE 77 APRIL 2007 WWW.LINUX - MAGAZINE.COM Ask Klaus! KNOW-HOW

This can lead to the funny effect that loading Linux from a hard disk works well (because the BIOS routines knew how to read from a drive), but after the kernel is running, you get an error message saying that the media from which the kernel has just been loaded is “not accessible.” This is, of course, just happening because of a missing module (not included in the kernel or initrd) for handling the device. I tend to build the kernel in a way that it can handle all common “bootable devices” on its own without needing additional modules or configuration. Therefore, the Knoppix kernel contains drivers for IDE/ PATA and SATA, so devices at- tached to these controllers get recog- nized at an early stage. • The kernel tries to initialize the hard- ware, so as to make it usable for appli- cations. For part of this, Linux uses its own settings for interrupt/ IO and Figure 1: init reads its configuration from the inittab file. chipset configuration, but the options set in the BIOS are used, too. You can scripts under /etc/rcS.d/ are run first. question, be extremely helpful if you ac- influence the Linux kernel’s behavior The scripts do further system configu- cidentally misconfigured iptables or low- at the initial boot command line or via ration: remount of the root filesystem level settings so that the system does not the append= boot options set forth in (a different one); filesystem check and reach a stage that would allow you to log lilo.conf (LILO) or menu.lst (GRUB). mounting of hard disk partitions given into it. • If an initial ramdisk was loaded, this in /etc/fstab; network setup; and the To get such an “emergency shell” at is now used as the root , permanent login processes on the text the lilo or grub boot prompt, type: and a script or program called /linuxrc consoles, as well as (in most distribu- is executed. If the newer method of tions) the display manager kdm, gdm, linux init=/bin/sh initramfs was used, the ramdisk can or xdm, depending on your prefer- even be included in the compressed ences. The runlevel selected at the You will then be prompted to enter com- kernel binary. The initial ramdisk usu- boot command line or given as default mands immediately after the kernel’s ally contains add-on modules (or mod- in /etc/inittab, determines which hardware detection, a least if your root ule loaders with some kind of initial scripts are run afterwards. Look for filesystem is still in a somewhat usable hardware detection); or, if you need a ls -l /etc/runlevelnumber.d/*. You can condition. very quick startup without using “init” get your current runlevel number by In most setups, the mounted root file (the next step) as the control program, just typing runlevel. system is still read-only, so if you plan, the GUI or program that is supposed to After this, the system is up and running for example, to reset the root password run as the main application is imme- and you can log in (if you have not auto- without knowing the old one, you diately started. In most distributions, matically been logged in already). Most should remount your root file system hardware support and network boot errors happen (if not due to kernel mis- read-write first, using: is also handled in the initial ramdisk. configuration) in the init scripts, which • After access to initrd has finished and are not always written with easy recov- mount -o remount,rw / the last process ends, the kernel will ery in mind. try to start the master control program For example, if a corruption in the root Then you can manually try to repair init, which is located in /sbin or /etc. filesystem is detected during the file sys- everything from the shell. If it is no longer needed, the memory tem check, you may be unable to log in Be very careful not to hit the ctrl-alt- used for the initial ramdisk is freed. and “repair errors manually” in the way del key combination during your system init reads its configuration from a file that is suggested by the error messages repair attempts, since, without using called /etc/inittab (man 5 inittab). at this step. init, that key combination is not rerouted • init then starts all programs, mostly In this case, you can often use a trick to a clean shutdown and would reset shell scripts that start other programs that allows you to skip most of the boot your computer without any further no- or daemons, which are given in the process and just start a single program tice or question, probably without giving /etc/inittab configuration lines. For right away after kernel and initrd are the kernel a chance to save any buffered many GNU/ Linux distributions, the loaded. This can, referring back to your changes.

WWW.LINUX - MAGAZINE.COM ISSUE 77 APRIL 2007 61 KNOW-HOW Ask Klaus!

After you are done with your emer- gency rescue shell session, just remount filesystems as read-only:

mount -o remount,ro /

This will then allow you to just hit the reset button or use the previously men- tioned immediate reset by keyboard. Ruined Everything! I’m not sure what’s wrong. My computer recently gave the mes- sage “operating system error” when I tried to start it. Now a message says “searching for a boot record,” and it never stops searching. And now my DVD/ CD drive is missing.

It may be a hardware error, which cannot be repaired by software. If a ruined BIOS setup is likely, try setting all BIOS options to Figure 2: The fstab file contains information on drives and mount points. the “slow but safe” variant. (Sometimes this is not the safe variant, but the “nor- isolation, and – in the worst case – ruin Root Password mal” setting is.) your board. Also, ram may need to be I have a live CD of Knoppix 3.7. Also, major failure to work can also replaced because it’s failing after a few I would like to use it to do re- arise from a changed hardware configu- billion read/ write cycles. covery and disk partitioning, ration, even if the BIOS only thinks that So much for the hardware rescue at- but when I boot, it comes up in user you may have changed something, so it tempt. For the software side, sometimes mode, and I need root to run administra- automatically changes the chipset set- a BIOS upgrade can help eliminate prob- tive programs. How do I set the root tings, interrupt numbers or IO addresses lems that only showed up after installing password for a Live CD? on its own. I’ve seen it happen. Hard- a new operating system version. ware is evil. Sometimes hardware features won’t Most setup scripts in Knoppix I’ve seen computers that would do work well, and instead of patching hard- (located in the Knoppix menu, hard lockups without even attempting to ware with a soldering iron, it can be beneath the KDE menu) will use boot into a usable system, working again wise not to use some features that are “sudo” to run setup tasks under root by just changing the sequence of net- not urgently needed, such as IRQ bal- privileges. When you start a program work cards or by removing a soundcard ancing or ACPI. that is designed to ask for a root pass- that was installed in addition to the on- Knoppix has a good – yet long – boot word, instead of being run by sudo, you board card. command line to see whether problems probably do need a root password. Pass- Also, connectors do age. Despite what caused by an incomplete onboard imple- words in Knoppix are locked/ invalid. hardware vendors want you to believe, mentation of features that have found There are no backdoors or “default pass- there is such a thing as oxidation of con- their way into the Linux kernel vanish: words.” Set a new root password with: tacts and changes in the physical geome- try that makes signal cables lose their knoppix acpi=off noapic U sudo passwd contacts. So, if you make sure that all nolapic pnpbios=off pci=bios hard disk and CD-ROM connectors are or visit the root console by control-alt-F1 carefully fixed in their sockets, and no nolapic is not a spelling error. I recently and type: plastic attachments are loose or appar- discovered some notebooks that would ently broken, there is a good chance that not boot without the “nolapic” option. passwd your computer will magically work again Using nolapic, everything – including even though it refused to recognize any ACPI, CPU frequency scaling, and all on- Then just switch back to X with control- drive attached to the IDE or SATA sock- board controllers – worked flawlessly, alt-F5. ■ ets earlier. while without nolapic, the kernel You can also try new cables. I don’t stopped dead at recognition of the hard- believe in contact/ cleaning sprays, disk controllers (where the fault was Send your Linux questions to though, because these can easily short- apparently neither the disks, nor the klaus@linux-magazine. com. circuit modern connectors, disintegrate controllers).

62 ISSUE 77 APRIL 2007 WWW.LINUX - MAGAZINE.COM