The Debian Series: Boot, Init sequence and chkconfig

David E Lares S
Nov 6 · 4 min read

This story will go deep into the Debian boot sequence and what is happening once your device starts. It’s not an easy concept to digest, and there’s a lot of things going on simultaneously. I have to ignore some previous concepts because we are focusing on certain tasks and components. There’s a lot of material and better explanations out there but I’ll try to summarize the whole process in short lectures to better comprehension.

Lets’s start with our key component called the BIOS, we can conceptualize this element as the OS of our computer’s motherboard, long story short, this is a special chip that recognizes and localize the necessary hardware devices to start the OS into the RAM memory.

This BIOS chip will evaluate and check if the hardware environment is okay to proceed. If all is good, the BIOS will delegate the control of the system to the MBR or the Master Boot Record. The MBR refers to the boot sector of an HDD, which is the first 512 bytes of the storage sectors.

The MBR represents the key component of almost everything on the boot process. Basically identifies what to do in order to boot an OS, sometimes may be referencing to bootstrapping processes with GRUB (other programs exist for different OS), or to store a partition tables (will talk about it later) o even to identify an individual storage drive.

Following through, the GRUB is a program that lets us choose which OS we are going to boot from the installed on the HDD. GRUB is loaded on the MBR on its elemental way possible, it also lives on the storage disk because it also starts the OS processes once the user decides which OS will use.

Let’s pause a little bit here, let’s recap with details what we have to this point.

We stated that the BIOS checks for hardware devices. Then, GRUB loads their first phase of execution on the MBR and reads what’s on the BIOS, at this point, the GRUB is loaded on its most elemental way possible, after that, the second phase (on the HDD) loads the rest of the GRUB program, and shows the possible OS installed. After the user choose what OS to boot, the OS will load and the GRUB passes execution control to the OS itself.

Now we are in hands of the OS, most services must come up in order to use our hardware and do whatever we want. Right?

Let’s talk about the INIT processes and the runlevels hierarchy of Linux Services.

INIT (or initialization) is a series of processes that are executed after the kernel is loaded, this process is a daemon that continues running until the system shuts down. You can consider it as the father of all processes.

Strictly tied, we have a concept called runlevels, which basically represents what number of services stopped or started exists depending on the type of users that are present in certain moments of the machine.

Debian Runlevels

On the Debian 7 machine, the runlevels programs are located on the /etc directory, specifically between the rc0.d to the rc6.d folders. You may be thinking why 0 and why it goes to the 6, right? I will talk about it in a minute.

Inside each folder, you will find Sx files (mostly in order) which contain the logic of the process that runs on every single runlevel. Is the file starts with a K is a kill process.

Runlevels

Now, we have multiple runlevels, each one represents the type or ops mode that the OS (Unix based) when a certain level is reaching, there’s more information here, but in a summarized way, we have:

0 — Halt: basically stops the OS.

1 — Single (or single-user), starts without any service, is a simple run for prepare or stop the OS

2 to the 5: multi-user level, on this step you can use the OS without any GUI, can be used for custom purposes,

6 — Reboot: what it says, just reboots the server.

I need to clarify something, on the multi-user level, each internal step does something different, the 3rd step is where the system normally starts, by the 4th step we have the capability of the network interfaces. On the 2nd we barely have network capability and by the 5th one, we have GUI enabled.

So, there’s a lot of things going on in quick terms of time. This will give us a head up, on what’s going on since we power up or machine or laptop.

There is a tool called chkconfig that basically helps to enable or disable systems or services, basically, this utility tool helps us to start/stop services in order to optimize for sec or performance purposes, it depends mostly on what can be your goal

How to use it?

Simple, here’s an example.

chkconfig -l , the -l flag list the programs with the attached runlevel.

what about shutting a service? well, take a look at this.

chkconfig vsftpd off

Quite simple, right?

That’s it for today. There’s more information related to it everywhere, I tried to make it easy to digest for everyone. Please feel free to contribute to it.

In the next story, I will be talking about Disk partitions and provisioning.

Happy coding :)

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade