Understanding the system startup in Linux
By Ancillotti
By connecting the PC, the first software that is loaded is the BIOS of the motherboard. He is counting the RAM, performs a quick check of the devices installed and, finally, starts loading the operating system. It can be loaded from various sources, including HD, CD-ROM or DVD, a USB stick, or even via the network (as is done in LTSP and other systems terminal levels), in the order defined in the configuration Setup.
After doing its work, the BIOS loads the operating system, reading the first sector of the hard disk the Master Boot Record or MBR. In it is written to the boot manager, which is responsible for loading the system. It's his presence that allows you to install more than one operating system on a micro and can choose between them at boot time.
On Linux, the manager is the most used grub (with a small share of lilo), while Windows is using the NTLDR. The MBR has room for only one boot manager, so you should pay attention to the configuration when you install multiple systems, since by default each system supports the boot manager before being installed.
Despite its vital importance, the boot includes a single sector of the HD, a mere 512 bytes.Because of this, it is actually used to store only a bootstrap, a small software that instructs the BIOS to load the executable boot loader at a specific point of HD.
The boot loader uses the first 446 bytes of the MBR. The remaining 66 bytes are used to store the partition table, which stores information about where each partition begins and ends.Partitioning programs, such as cfdisk do nothing more than change the information in the partition table. When it is lost or damaged (for whatever reason), all partitions disappear and you need to go after a program of data recovery.
The bootloader has the function to load the kernel and from it, the rest of the system. Both grub when lilo can be configured to also load Windows or other systems installed in dual-boot or multi-boot. Most modern distributions automatically configure it during installation.
Initially, the kernel is a compressed file and read-only, the file "/ boot / vmlinuz." He is unpacked in a reserved area of RAM and runs from there, taking advantage of the fact that the RAM is much faster than the HD. The main executable kernel is never changed during the normal use of the system, it changes only when you recompile the kernel or manually install a new version.
Once loaded, the first thing the kernel does is to mount the root partition, where the system is installed, first as read-only. At this stage it loads the init, the software that starts the normal boot the system, reading the startup scripts and loading modules and software specified in them.
The configuration file for init is the "/ etc / inittab". It is usually the first configuration file read at boot. The main task it is to load the other scripts, used to load the other components of the system and do all the checking operations are necessary during the boot.
All these steps are performed by scripts, located in the "/ etc / init.d", running the appropriate commands to initialize the services and perform other necessary operations. Some of them are run only at boot (checking the configuration, for example), while others boot services that are active continuously.
A good example is the cups, which is the service necessary for support printing. It is used both to print to local printers as network printers and is also used when you need to share the printer with other network machines. It comes installed by default on nearly all distributions and is controlled via the script "/ etc / init.d / cups" (or "/ etc / init.d / cupsys", depending on the distribution).
If you want to disable it temporarily, for example, would use:
# / Etc / init.d / cups stop
To enable it again later, would:
# / Etc / init.d / cups start
The same applies to almost all other services, such as the "samba" (responsible for file sharing, "bluetooth" (responsible for supporting the Bluetooth transmitter) and so on. They are also called "daemons" a term used for services that are active continuously, performing some function.
What determines whether each service will be on or off at boot is not the fact of whether it is installed but the presence of a symbolic link created within one of the Startup folders in the system. By default, run the first links that are inside the "/ etc / rcS.d /" (which includes the essential services running early in the boot) and then the links inside the "/ etc / rc5.d / ", which includes the other services.
The number (5 for example) indicates the runlevel that will be used, which may be a number from 1 to 5. Each runlevel corresponds to a folder with a different set of startup scripts. It is a way to have multiple "profiles", to use the system in different situations.
The most common configuration is to use runlevel 1 as a recovery mode, in which only the essential services to complete the boot is loaded, no graphical environment or support network. Today, runlevel 1 is little used because it is easier to correct problems booting using a live CD and solving problems through it, but the possibility remains open.
Then we runlevel 3, where nearly all services are loaded, except the graphical environment.This mode is widely used in servers. Finally, we runlevel 5, which corresponds to "normal" mode, where the graphical environment is loaded, along with all other services. As in other cases, there are variations, Slackware, for example, uses runlevel 4 for loading the graphical environment, while Ubuntu uses a completely different system.
Using the runlevel 5, the scripts are loaded into the folder "/ etc/rc5.d /", while using runlevel 3, the scripts are loaded into the folder "/ etc/rc3.d /". Nothing prevents you to modify the organization of the files manually, so do also carry the X in runlevel 3, or anything else you want. They are just folders with scripts and symbolic links and not a black box.
Ubuntu inaugurated the use of a new system initialization, called Upstart(http://upstart.ubuntu.com/). In it, the boot process is simplified (but also lose some flexibility) and ceases to exist differences between runlevels 2 to 5, who can use the same settings by clicking the graphical environment by default, which essentially eliminates the distinction between modes. If you have the curiosity to run the command "runlevel" which shows which runlevel is being used, it will report:
$ Runlevel
N 2
In other distributions, runlevel 2 is configured as a recovery mode without networking support or a graphical environment, but in Ubuntu it is the default level, they are born all services. If you check the configuration of the modes 3, 4 and 5, will see that the configuration is the same in all of them.
Another symptom of the use of Upstart is that the file "/ etc / inittab" ceases to exist, giving rise to "/ etc / event.d / rc-default, which becomes the new responsible for firing the boot process system.
The standard utility for configuring services in Ubuntu is the services-admin, available on the System> Administration> Services "
The problem is that it shows only one set of services considered "optional", hiding various services that are considered essential components of the system, such as cups.
If you want to see a complete list of all services, can take a look at the contents of the folder"/ etc/rc2.d"
Of course, you should only stick to turn off services not listed in the services-admin if you know what you're doing, since most of them are even important components. Disabling dbus, for example, much of the functions of hardware detection, along with several programs that use it to exchange messages no longer work.
To disable the service manually, use the command "update-rc.d-f name remove", as in:
# Update-rc.d-f remove cups
It removes the links pointing to the service in all pasts boot, causing it to cease to be loaded during boot. If you want to disable the service time (not to wait) can disable it using the command "/ etc / init.d / stop", as in "/ etc / init.d / cups stop".
To reactivate service after startup, use the command "update-rc.d-f name defaults, as in:
# Update-rc.d-f cups defaults
He re-creates the symbolic links and restore the original configuration. These same commands can be used in other distributions derived from Debian. In the case of Mandriva and Fedora, it uses the command "chkconfig", as in "chkconfig name on" (active) and "chkconfig name off (disable).
Comments
No comments yet.