APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed
RSS Feeds RSS Feeds











(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version
->
-> Bootstrapping your Linux Machine


Bootstrapping your Linux Machine





by Prasad P M

Dec 31, 2005




1. Introduction

"Booting the computer", this is a common word associated with starting the computer. Though we use it casually in our daily life, have you ever thought of what exactly it is ? or how the system brings itself to a workable environment ? Well, my attempt in this article is to explain all the stages involved in booting your linux machine. In simple words, "bootstrapping" means starting up your computer. It involves all those stages, from the moment you power on your machine till the system is ready to log you in.

2. The Boot Process

The Boot process involves several different stages that the system undergoes while it is being booted. If any of these stages fail, then the system cannot start itself.

* The BIOS
* Kernel Initialization
* Hardware Configuration
* System Processes
* Startup Scripts
* Multiuser Mode

Lets look at each of the above stages in detail.

2.1 The BIOS

This is the initial stage of the boot process. The moment you power your system, the microprocesser is not aware of your computer environment or even your operating system. It is the BIOS, that provides the necessary instructions to microprocessor and helps to initialize the computer environment. That is why it is called Basic Input/Output System.

These are the main tasks of BIOS.

* POST (Power On Self Test): The BIOS performs a power on self test on all hardware components attached to the computer during booting. You might have noticed the LEDs on your keyboard flashing during booting. That is an example of POST. If anything fails, it will be reported to you on your screen.

* The BIOS provides a set of low level routines for the hardware components to interface with the Operating System. These routines act like drivers for your Screen, Keyboard, Ports etc.

* The BIOS helps to manage the settings of hard disks, your first boot device, system time and more.

The BIOS also initiates the bootstrapping sequence by loading the Initial Program Loader (The boot loader program) into the computer memory. The software is usually stored in the ROM. This stage is actually outside of the domain of the Operating System and it is more vendor specific.

2.2 Kernel Initialization

Linux actually implements a two stage boot process. In the first stage, the BIOS loads the boot program (Initial Program Loader) from the hard disk to the memory. In the second stage, the boot program loads the Operating System kernel vmlinuz into memory. Though we can name the kernel anything of your like, we'll call it vmlinuz. Well, it's just a tradition, where 'vm' stands for the Virtual Memory support and last 'z' denotes that it is a compressed image, ie vmlinux.z => vmlinuz.

When the kernel loads into memory, it performs a memory test. Most of the kernel data structures are initialized statically. So it sets aside a part of memory for kernel use. This part of the memory cannot be used by any other processes. It also reports the total amount of physical memory available and sets aside those for the user processes.

2.3 Hardware Configuration

If you have configured a linux kernel, you would have configured the hardware sections as well. This is how the kernel knows what hardware to find. Based on the configuration, when the kernel boots, it tries to locate or configure those devices. It also prints the information of the devices it found during the bootup. It will probe the the bus for devices or asks the driver for information of the devices. Devices that are not present in the system or not responding to the probing will be disabled. It is possible to add more devices using the util 'kudzu'.

2.4 System Processes

Once the hardware initialization is complete, the kernel will create several spontaneous processes in the user space. The following are those processes.

* init
* keventd
* kswapd
* kupdated
* bdflush

These are called spontaneous processes because they are not created by the usual fork mechanism. Of these, only 'init' is actually in the user space(only processes in the user space can be controlled by us) , we have no control over others. The rest of the boot up procedure is controlled by init.

2.5 Startup Scripts

Before explaining how startup scripts work, let's have a look at the tasks performed by them. The following are the important tasks performed by startup scripts.

* Set the name of the computer
* Set the time zone
* Check the hard disk with fsck
* Mount system disk
* Remove old files from /tmp partition
* Configure network interfaces with correct IP address
* Startup deamons and other network services

The startup scripts are found in /etc/rc.d/init.d folder in your linux machine.

2.5.1 Init and runlevels

You can boot your linux machine to different runlevels. A runlevel is a software defined configuration of your system where the system behaviour will vary in different runlevels. Though, linux can have 10 different runlevels, only 7 of them are used. I have mentioned them below.

runlevel description
0
shutdown
1 or S
single user mode
2 multiuser mode without nfs
3
full multiuser mode
4
not used
5
X windows
6
reboot


You can specify the runlevel in the init configuration file /etc/inittab.

2.5.2 Startup Scripts and runlevels

You may see folders (rc[0-7].d) corresponding to each runlevel in the /etc folder. These folders contain files symbolically linked (in linux everything is a file) to the startup scripts in folder /etc/rc.d/init.d. If you look at these folders, you may see that the name of the symbolic links starts with the letter "S" or "K" followed by a number and the name of the startup script /service to which it is linked to.

For example, the following are the files in runlevel 2 and 3.

/etc/rc2.d/K20nfs -> ../init.d/nfs
/etc/rc2.d/S55named -> ../init.d/named

The name of those files are important. Because when you switch between runlevels, the services are started/stopped based on these names. Consider these two cases here.

* switching to higher runlevels - init will run scripts that start with letter S, in ascending order of the number with argument 'start'
* switching to lower runlevels - init will run scripts that start with letter K, in decending order of the number with argument 'stop'

The runlevels init checks to switch between them, depends on the configuration of your system. The following commands will help. For more details of the commands, refer to the manual pages.

The commands that deal with runlevels are:

/sbin/runlevel - shows the previous and current runlevels
/sbin/init and /sbin/telinit - to switch between runlevels
/sbin/chkconfig - to enable/disable services in runlevels

2.5.3 Startup Scripts and /etc/sysconfig files

The files in the /etc/sysconfig folder are read by the startup scripts. So it's worth mentioning them here.


* network - contains information of your hostname, nisdomain name etc.
* clock - timezone information
* autofsck - automatic filesystem check during boot up
* network-scripts - folder contains interface configuration files ifcfg-lo, ifcfg-eth0 etc.
* hwconf - hardware information
* sendmail, spamassassin, syslog, yppasswdd - information about the corresponding daemons.

Edit the files in /etc/sysconfig folder to make changes to your system.

2.5.4 Init and single user mode

This runlevel is used by sysadmins to perform routine maintenance. Its most commonly used for checking errors in file system with command 'fsck'. Only the root file system will be mounted in this runlevel and the system administrator is provided with a shell. If necessary, other partitions needs to be mounted manually. Also none of the deamons will be running in this runlevel. Only the system administrator can use the system in this mode. You can simply exit from the shell to boot it to the multiuser mode.

2.6 Multiuser Operation

Though the system has been booted to a particular runlevel, none of the users can login to the system until init spawns getty processes on terminals. If the system is booted to runlevel 5, init needs to spawn the graphical login system 'gdm'.

If the system has gone through the above mentioned stages without any failures, you may say that your system is booted and is ready to perform the tasks :)

3. Rebooting and Shutting down

We have discussed about the boot procedure so far. It is also important to shutdown the system properly. Otherwise you may end up with loss of data or serious damage to the file system.

You can safely use the commands /sbin/shutdown, /usr/bin/halt or /usr/bin/reboot to halt or reboot the computer. For more details of the commands, refer to the manual pages.




If this page was useful to you, please help others find it:  





4 comments




More Articles by



Click here to add your comments
- no registration needed!




Fri Feb 10 14:05:26 2006: 1618   TonyLawrence

gravatar
Halt, shutdown and reboot are not really the same thing. In Linux from 2.74 on, but NOT in most other Unixes (and not in older Linux), "halt" or "reboot" will invoke "shutdown" if you are in any multiuser mode. On other Unixes, that doesn't happen.

Actually, I think this convenience is a design flaw, but Linux does provide "poweroff" which does answer the odd need of shutting off NOW.



Sun Feb 12 13:52:38 2006: 1632   drag


Also runlevels are going to differ from Linux-based operating system (or more easily GNU/Linux-based systems).

For instance Debian and Debian-based distros are very common and they use different runlevels and have different locations of scripts. As does Slackware, which is less common, but still fairly popular.

For instance the init scripts are found in /etc/init.d/ directory in Debian. The default runlevel is 2. 0 is 'halt', 6 is 'reboot'. Runlevels 2-5 are all the same thing; it's up to the administrator to choose what they mean.

Also there is no /etc/sysconfig folder in Debian. There is a /etc/defaults folder for lots of things, however. Also there is update-alternatives for Debian's alternative system (like if you have 2 different versions of gcc installed you can choose a default and have symlinks taken care of automaticly). There is also a /etc/modules you can put the name of kernel modules you want loaded automaticly at bootup time (also to control order they start up).

For Slackware it's much more different then either the RPM-using distros (Redhat, Mandriva, Suse, etc) or the Debian-based distros (Debian Stable, Ubuntu, Xandros, etc) You can find a better description then what I am able to give at Slackware's website. http://www.slackware.com/config/init.php

There is no runlevel directories, each runlevel is a simple bash script setups the services for that runlevel and uses "if file exists run script" arguments to launch various other scripts. The way to configure these scripts is to edit them manually. There is a 'system v' style init runlevel directories for compatability reasons.

rc.0 script is for "halt". rc.4 is for "multiuser with X-based login". rc.6 is for "reboot". rc.K is for "single user". rc.M is for "multiuser with text login".

So depending on what version of "linux" your using (which is a misnomer since some Linux distros differ so significantly that it's easier to consider them different operating systems sometimes) you can run into different setups.

Of course what you stated is going to be the most common that your going to run across since that is what Redhat uses.



Mon Feb 13 22:51:13 2006: 1637   prasad



The startup scripts and related parts are slightly different in other distros. As I am more familiar with and using RedHat OS, those parts were explained based on my desktop machine.

Prasad

Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar

Kerio Samepage


Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

I am a Kerio reseller. Articles here related to Kerio products reflect my honest opinion, but I do have an obvious interest in selling those products also.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.

g_face.jpg

This post tagged:

       - Linux
       - Unix















My Troubleshooting E-Book will show you how to solve tough problems on Linux and Unix systems!


book graphic unix and linux troubleshooting guide



Buy Kerio from a dealer
who knows tech:
I sell and support

Kerio Connect Mail server, Control, Workspace and Operator licenses and subscription renewals



Click and enter your name and phone number to call me about Kerio® products right now (Flash required)