Useful ansible stuff


inventory_hostname‘ contains the name of the current node being worked on…. (as in, what it is defined in your hosts file as) so if you want to skip a task for a single node –

- name: Restart amavis
  service: name=amavis state=restarted
  when: inventory_hostname != "boris"

(Don’t restart Amavis for boris,  do for all others).

You could also use :

  when: inventory_hostname not in groups['group_name']

if your aim was to (perhaps skip) a task for some nodes in the specified group.


Need to check whether you need to reboot for a kernel update?

  1. If /vmlinuz doesn’t resolve to the same kernel as we’re running
  2. Reboot
  3. Wait 45 seconds before carrying on…
- name: Check for reboot hint.
  shell: if [ $(readlink -f /vmlinuz) != /boot/vmlinuz-$(uname -r) ]; then echo 'reboot'; else echo 'no'; fi
  ignore_errors: true
  register: reboot_hint

- name: Rebooting ...
  command: shutdown -r now "Ansible kernel update applied"
  async: 0
  poll: 0
  ignore_errors: true
  when: kernelup|changed or reboot_hint.stdout.find("reboot") != -1
  register: rebooting

- name: Wait for thing to reboot...
  pause: seconds=45
  when: rebooting|changed

Fixing ~/.ssh/known_hosts

Often an ansible script may create a remote node – and often it’ll have the same IP/name as a previous entity. This confuses SSH — so after creating :

- name: Fix .ssh/known_hosts. (1)
  local_action: command  ssh-keygen -f "~/.ssh/known_hosts" -R hostname

If you’re using ec2, for instance, you could do something like :

- name: Fix .ssh/known_hosts.
  local_action: command  ssh-keygen -f "~/.ssh/known_hosts" -R {{ item.public_ip }} 
  with_items: ec2_info.instances

Where ec2_info is your registered variable from calling the ‘ec2’ module.

Debug/Dump a variable?

- name: What's in reboot_hint?
  debug: var=reboot_hint

which might output something like :

"reboot_hint": {
        "changed": true, 
        "cmd": "if [ $(readlink -f /vmlinuz) != /boot/vmlinuz-$(uname -r) ]; then echo 'reboot'; else echo 'no'; fi", 
        "delta": "0:00:00.024759", 
        "end": "2014-07-29 09:05:06.564505", 
        "invocation": {
            "module_args": "if [ $(readlink -f /vmlinuz) != /boot/vmlinuz-$(uname -r) ]; then echo 'reboot'; else echo 'no'; fi", 
            "module_name": "shell"
        "rc": 0, 
        "start": "2014-07-29 09:05:06.539746", 
        "stderr": "", 
        "stdout": "reboot", 
        "stdout_lines": [

Which leads on to —

Want to run a shell command do something with the output?

Registered variables have useful attributes like :

  • changed – set to boolean true if something happened (useful to tell when a task has done something on a remote machine).
  • stderr – contains stringy output from stderr
  • stdout – contains stringy output from stdout
  • stdout_lines – contains a list of lines (i.e. stdout split on n).

(see above)

- name: Do something
  shell: /usr/bin/something | grep -c foo || true
  register: shell_output

So – we could :

- name: Catch some fish (there are at least 5)
  shell: /usr/bin/somethingelse 
  when: shell_output.stdout > "5"

Default values for a Variable, and host specific values.

Perhaps you’ll override a variable, or perhaps not … so you can do something like the following in a template :

max_allowed_packet = {{ mysql_max_allowed_packet|default('128M') }}

And for the annoying hosts that need a larger mysql_max_allowed_packet, just define it within the inventory hosts file like :

busy-web-server mysql_max_allowed_packet=256M

Install Virtualbox on Centos 7

1. Change to root User


su -
## OR ##
sudo -i

2. Install Fedora or RHEL Repo Files


cd /etc/yum.repos.d/

## Fedora 26/25/24/23/22/21/20/19/18/17/16 users

## CentOS 7.4/6.9 and Red Hat (RHEL) 7.4/6.9 users

3. Update latest packages and check your kernel version

Update packages


## Fedora 26/25/24/23/22 ##
dnf update

## Fedora 21/20/19/18/17/16 and CentOS/RHEL 7/6/5 ##
yum update

While executing yum update if you get any dependency errorfor glibc use the following to resolve it:

rpm -qa | grep glibc
You may see duplicates for either glibc or glibc common. There might be a common version in between any two packages of glibc and glibc-common. Remove the package which has uncommon version.

You can also check for duplicates with the following command:
yum list –showduplicates glibc

rpm -e glibc-common-2.17-196.el7

rpm -qa kernel |sort -V |tail -n 1

uname -r

Note: If you got kernel update or run older kernel than newest installed then reboot:



4. Install following dependency packages

CentOS 7/6/5 and Red Hat (RHEL) 7/6/5 needs EPEL repository, install it with following command:


## CentOS 7 and RHEL 7 ##
rpm -Uvh

## CentOS 6 and RHEL 6 ##
rpm -Uvh

## CentOS 5 and RHEL 5 ##
rpm -Uvh

## Fedora 26/25/24/23/22 ##
dnf install binutils gcc make patch libgomp glibc-headers glibc-devel kernel-headers kernel-devel dkms

## Fedora 21/20/19/18/17/16 and CentOS/RHEL 7/6/5 ##
yum install binutils gcc make patch libgomp glibc-headers glibc-devel kernel-headers kernel-devel dkms

## PAE kernel users install ##
## Fedora 24/23/22 ##
dnf install binutils gcc make patch libgomp glibc-headers glibc-devel kernel-headers kernel-PAE-devel dkms

## Fedora 21/20/19/18/17/16 and CentOS/RHEL 7/6/5 ##
yum install binutils gcc make patch libgomp glibc-headers glibc-devel kernel-headers kernel-PAE-devel dkms

5. Install VirtualBox Latest Version 5.1 (currently 5.1.28)


## Fedora 26/25/24/23/22 ##
dnf install VirtualBox-5.1

## Fedora 21/20/19/18/17/16/15/14 and CentOS/RHEL 7/6/5 ##
yum install VirtualBox-5.1

This command create automatically vboxusers group and VirtualBox user must be member of that group.
This command also build needed kernel modules.
Package is VirtualBox-5.1 not VirtualBox.

Rebuild kernel modules with following command:


## Fedora 26/25/24/23/22/21/20/19 and CentOS/RHEL 7 ##
/usr/lib/virtualbox/ setup

## Fedora 18/17/16 and CentOS/RHEL 6/5 ##
/etc/init.d/vboxdrv setup
## OR ##
service vboxdrv setup

You might get the following error: Stopping VirtualBox services. Building VirtualBox kernel modules.
This system is not currently set up to build kernel modules (system extensions).
Running the following commands should set the system up correctly:

yum install kernel-devel-3.10.0-327.28.2.el7.x86_64
(The last command may fail if your system is not fully updated.)
yum install kernel-devel failed: Look at /var/log/vbox-install.log to find out what went wrong.

Execute the following: yum install kernel-devel

If the error still persists look in the log: /var/log/vbox-install.log
If you find the following error: Error: unable to find the sources of your current Linux kernel. Specify KERN_DIR=<directory> and run Make again. Stop.

## Current running kernel on Fedora ##
KERN_DIR=/usr/src/kernels/`uname -r`
## Current running kernel on CentOS and Red Hat (RHEL) ##
KERN_DIR=/usr/src/kernels/`uname -r`-`uname -m`
## Fedora example ##
## CentOS and Red Hat (RHEL) example ##
## Export KERN_DIR ##
export KERN_DIR

Make sure your system is rebooted.

6. Add VirtualBox User(s) to vboxusers Group

Replace user_name with your own user name or some another real user name.


usermod -a -G vboxusers user_name

7. Start VirtualBox

Use launcher from menu or simply run:



fswatch – Monitors Files and Directory Changes or Modifications in Linux

fswatch is a cross-platform, file change monitor that gets notification alerts when the contents of the specified files or directories are altered or modified.

It executes four types of monitors on different operating systems such as:

  1. A monitor build on the File System Events API of Apple OS X.
  2. A monitor based on kqueue, a notification interface present in FreeBSD 4.1 also supported on many *BSD systems, OS X inclusive.
  3. A monitor based on File Events Notification API of the Solaris kernel plus its spin-offs.
  4. A monitor based on inotify, a kernel subsystem that shows file system modifications to apps.
  5. A monitor based on ReadDirectoryChangesW, a Windows API that records alters to a directory.
  6. A monitor that regularly check that status of file system, keeps file modification times in memory, and manually determine file system changes (which works anywhere, where stat can be used).

Features of fswatch

  1. Supports several OS-specific APIs
  2. Allows recursive directory monitoring
  3. Performs path filtering using including and excluding regular expressions
  4. Supports customizable record format
  5. Additionally, it supports periodic idle events

How To Install fswatch in Linux Systems

Unfortunately, fswatch package is not available to install from the default system repositories in any Linux distributions. The only way to install the latest version of fswatch is to build from source tarball as show in the following installation instructions.

First grab the latest fswatch tarball using following wget command and install it as shown:

$ wget
$ tar -xvzf fswatch-1.9.3.tar.gz
$ cd fswatch-1.9.3
$ ./configure
$ make
$ sudo make install 

Important: Make sure you’ve GNU GCC (C and C++ Compiler) and Development Tools (build-essential on Debian/Ubuntu) installed on the system, before you compile fswatch from source. If not, install it using following command on your respective Linux distributions..

# yum group install 'Development Tools'		[On CentOS/RHEL]
# dnf group install 'Development Tools'		[On Fedora 22+ Versions]
$ sudo apt-get install build-essential          [On Debian/Ubuntu Versions]

On Debian/Ubuntu distributions, you might get following error while executing fswatch command..

fswatch: error while loading shared libraries: cannot open shared object file: No such file or directory

To fix it, you need to execute the command below, this will help refresh the links and cache to the dynamic libraries before you can start using fswatch.

$ sudo ldconfig

How do I use fswatch on Linux?

The general syntax for running fswatch is:

$ fswatch [option] [path]

On Linux, it is recommended that you use the default inotify monitor, you can list available monitors by employing the -M or - list-monitors option:

$ fswatch -M
$ fswatch --list-monitors

fswatch - List Monitors

The command below enables you to watch the changes in the current directory (/home/tecmint), with events being delivered to standard output every 4 seconds.

The -l or –-latency option allows you to set the latency in seconds, the default being 1 second.

$ fswatch -l 4 .

fswatch - Monitor Home Directory Changes

The next command monitors changes to the /var/log/auth.log file every 5 seconds:

$ fswatch -l 5 /var/log/auth.log

Using -t or --timestamp option prints the time stamp for every event, to print the time in UTC format, employ -u or --utf-time option. You can as well format time using -f or --format-time format option:

$ fswatch --timestamp /var/log/auth.log

Next, -x or --event-flags tells fswatch to print the event flags along side the event path. You can use –event-field-seperator option to print events using the particular separator.

$ fswatch --events-flags ~ /var/log/auth.log

To print the numeric value of an event indicating changes in your home directory and /var/log/auth.log file, use -n or --numeric option as below:

$ fswatch --numeric ~ /var/log/auth.log 

Perhaps you can look through the fswatch man page for detailed usage options and information:

$ man fswatch

Pyinotify – Monitor Filesystem Changes in Real-Time in Linux

Pyinotify is a simple yet useful Python module for monitoring filesystems changes in real-time in Linux.

As a System administrator, you can use it to monitor changes happening to a directory of interest such as web directory or application data storage directory and beyond.

It depends on inotify (a Linux kernel feature incorporated in kernel 2.6.13), which is an event-driven notifier, its notifications are exported from kernel space to user space via three system calls.

The purpose of pyinotify is to bind the three system calls, and support an implementation on top of them providing a common and abstract means to manipulate those functionalities.

In this article, we will show you how to install and use pyinotify in Linux to monitor filesystem changes or modifications in real-time.


In order to use pyinotify, your system must be running:

  1. Linux kernel 2.6.13 or higher
  2. Python 2.4 or higher

How to Install Pyinotify in Linux

First start by checking the kernel and Python versions installed on your system as follows:

# uname -r 
# python -V

Once dependencies are met, we will use pip to install pynotify. In most Linux distributions, Pip is already installed if you’re using Python 2 >=2.7.9 or Python 3 >=3.4 binaries downloaded from, otherwise, install it as follows:

# yum install python-pip      [On CentOS based Distros]
# apt-get install python-pip  [On Debian based Distros]
# dnf install python-pip      [On Fedora 22+]

Now, install pyinotify like so:

# pip install pyinotify

It will install available version from the default repository, if you are looking to have a latest stable version of pyinotify, consider cloning it’s git repository as shown.

# git clone
# cd pyinotify/
# ls
# python install

How to Use pyinotify in Linux

In the example below, I am monitoring any changes to the user tecmint’s home (/home/tecmint) directory as root user (logged in via ssh) as shown in the screenshot:

# python -m pyinotify -v /home/tecmint

Monitor Directory Changes

Next, we will keep a watch for any changes to the web directory (/var/www/html/

# python -m pyinotify -v /var/www/html/

To exit the program, simply hit [Ctrl+C].

Note: When you run pyinotify without specifying any directory to monitor, the /tmp directory is considered by default.

Docker Security

2017-03-19 10_39_45-GOTO2016• - VLC media player2017-03-19 10_40_30-GOTO2016• - VLC media player2017-03-19 10_40_45-GOTO2016• - VLC media player2017-03-19 10_41_21-GOTO2016• - VLC media player2017-03-19 10_41_31-GOTO2016• - VLC media player2017-03-19 10_41_44-GOTO2016• - VLC media player

Docker contaniners share the kernel wth the machine they are running on.

2017-03-19 10_44_12-GOTO2016• - VLC media player.png

If any of the containers starts using up more resources like CPU, RAM the other containers might run ino /do/s issue.

2017-03-19 10_45_35-GOTO2016• - VLC media player.png

The attack can break out from a container into the host  machine or other containers.

2017-03-19 10_46_35-GOTO2016• - VLC media player.png

Make sure that the images coming from dockerhub are from trusted sources.

2017-03-19 10_47_30-GOTO2016• - VLC media player

You should be careful with what secrets you store in your containers.2017-03-19 10_47_51-GOTO2016• - VLC media player2017-03-19 10_48_01-GOTO2016• - VLC media player2017-03-19 10_48_32-GOTO2016• - VLC media player

2017-03-19 10_52_52-GOTO2016• - VLC media player.png

You can use the commands:

docker network disconnect nh

nh is the name of the container. This will disconnect your containers from the network and they will be inaccessible.

docker diff

Docker diff will show you which files have been modified.

If you do not want external invalid/destructive files to modify your containersthen you can make your containers read-only

2017-03-19 10_56_31-GOTO2016• - VLC media player.png

Specify –read-only option while running your container.

2017-03-19 11_00_00-GOTO2016• - VLC media player2017-03-19 11_00_14-GOTO2016• - VLC media player2017-03-19 11_00_35-GOTO2016• - VLC media player

2017-03-19 11_03_31-GOTO2016• - VLC media player2017-03-19 11_03_41-GOTO2016• - VLC media player2017-03-19 11_04_27-GOTO2016• - VLC media player2017-03-19 11_04_51-GOTO2016• - VLC media player2017-03-19 11_05_01-GOTO2016• - VLC media player2017-03-19 11_05_39-GOTO2016• - VLC media player2017-03-19 11_06_11-GOTO2016• - VLC media player2017-03-19 11_06_35-GOTO2016• - VLC media player2017-03-19 11_06_46-GOTO2016• - VLC media player

2017-03-19 11_07_41-GOTO2016• - VLC media player

2017-03-19 11_10_19-GOTO2016• - VLC media player2017-03-19 11_10_37-GOTO2016• - VLC media player2017-03-19 11_10_53-GOTO2016• - VLC media player2017-03-19 11_11_21-GOTO2016• - VLC media player2017-03-19 11_11_45-GOTO2016• - VLC media player2017-03-19 11_12_03-GOTO2016• - VLC media player2017-03-19 11_12_44-GOTO2016• - VLC media player2017-03-19 11_12_55-GOTO2016• - VLC media player2017-03-19 11_13_11-GOTO2016• - VLC media player2017-03-19 11_13_55-GOTO2016• - VLC media player2017-03-19 11_14_06-GOTO2016• - VLC media player2017-03-19 11_14_21-GOTO2016• - VLC media player2017-03-19 11_14_35-GOTO2016• - VLC media player2017-03-19 11_15_00-GOTO2016• - VLC media player2017-03-19 11_15_43-GOTO2016• - VLC media player2017-03-19 11_16_29-GOTO2016• - VLC media player2017-03-19 11_17_06-GOTO2016• - VLC media player2017-03-19 11_17_17-GOTO2016• - VLC media player2017-03-19 11_17_34-GOTO2016• - VLC media player2017-03-19 11_18_37-GOTO2016• - VLC media player2017-03-19 11_18_48-GOTO2016• - VLC media player


2017-03-19 11_19_44-GOTO2016• - VLC media player

How does linux work?

Basics of Linux:

Linux is a multitask and multiuser operating system. Now, a little explanation of this terminology.

An operating system is a collection of programs that run in a computer so that a person can easily access the hardware and all resources of the computers. The operating system is the big program that makes your computer life easy.

multitask operating system is capable of doing several tasks at the same time.

multiuser operating sytem has a concept of “userquot;, a way to identify the person that is using the system, and can allow different users to perform different taks in the computer, and protect one user’s tasks from interfering with another user’s programs.

Some terminology:

There are a few other terms that will help you to understand the rest of the this manual:

  • shell: this is a program in the system that allows you to give the commands you want to execute. It is the basic programs that connects you to the operating sytem.
  • process: any task that you run in the system is called a process (again, a process is something a little more complex than just a task, but that definition is good enough to start).
  • file: a part of the hard disk that contains data owned by a user of the system.
  • X-windows (or simply windows): this is a mode of Linux where you screen (monitor) can be split in small “parts” called windows, that allow you to do several things at the same time (or rather change from one task to another easily) and view graphics in a nice way.
  • text terminal: by this I mean a monitor that has only the capability to display text stuff, no graphics (or perhaps a very basic graphics display).
  • session: the time you spend between logging on in the system and logging out of the system.

Linux boot process:

In many ways Linux is no different from any other operating system. It runs on the same computer, and the inner workings are the same as those that drive Windows, Linux, BSD, MacOS, etc. But there are fundamental and compounding differences from that point forward. Here we will cover how Linux works? Starting at power on, and finally reaching the desktop.

When you press the “On” button on your PC to start it, the computer wakes up the same way we do every morning. We open our eyes and check if there is anything wrong from the time we went to sleep. On a computer this is performed by the BIOS (Basic Input Output System) on the motherboard. The BIOS is the small chip that has the responsibility of identifying, checking and initializing system devices such as graphics cards, hard disks, etc.

To do this the BIOS makes a POST (Power On Self Test) and then checks which drive to use as the primary boot device. Normally this is set through the BIOS configuration screen and the first boot device can be identified as the CD-ROM, USB drive, hard disk or floppy disk. Let’s say that our system is configured to boot from CD-ROM and then Hard Disk. The BIOS checks the CD-ROM device to see if a CD/DVD resides there and is bootable. If so it boots from the CD-ROM, if not it turns to the hard disk, and hands over the control of the computer.

The boot of the operating system starts here, with the boot partition always located at the same place for all operating systems: track 0, head 0 and cylinder 0. Then the small program here, which is GRUB (GRand Unified Boot loader) or LILO (LInux LOader) performs the initialization and boot of the operating system, and since many distributions implement GRUB as their default bootloader, I will go with this one.

The configuration file (/boot/grub/grub.conf), which is used to create the list of operating systems to boot in GRUB’s menu interface, essentially allows the user to select a pre-set group of commands to execute.

It looks like below:

 # grub.conf generated by anaconda
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/mapper/vg_centos-lv_root
# initrd /initrd-[generic-]version.img
title CentOS (2.6.32-642.13.1.el6.x86_64)
 root (hd0,0)
 kernel /vmlinuz-2.6.32-642.13.1.el6.x86_64 ro root=/dev/mapper/vg_centos -lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_LVM_LV=vg_centos/lv_swap rd_NO_MD SYSFON T=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=vg_centos/lv_root KEYBOARDTYPE=p c KEYTABLE=us rd_NO_DM rhgb quiet
 initrd /initramfs-2.6.32-642.13.1.el6.x86_64.img
title CentOS (2.6.32-504.8.1.el6.x86_64)
 root (hd0,0)
 kernel /vmlinuz-2.6.32-504.8.1.el6.x86_64 ro root=/dev/mapper/vg_centos- lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_LVM_LV=vg_centos/lv_swap rd_NO_MD SYSFONT =latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=vg_centos/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
 initrd /initramfs-2.6.32-504.8.1.el6.x86_64.img
title CentOS 6 (2.6.32-504.el6.x86_64)
 root (hd0,0)
 kernel /vmlinuz-2.6.32-504.el6.x86_64 ro root=/dev/mapper/vg_centos-lv_r oot rd_NO_LUKS LANG=en_US.UTF-8 rd_LVM_LV=vg_centos/lv_swap rd_NO_MD SYSFONT=lat arcyrheb-sun16 crashkernel=auto rd_LVM_LV=vg_centos/lv_root KEYBOARDTYPE=pc KEY TABLE=us rd_NO_DM rhgb quiet
 initrd /initramfs-2.6.32-504.el6.x86_64.img

The GRUB is either in /boot/grub/menu.lst or /boot/boot/menu.lst. The menu.lst file is symlink to grub.conf. So both files are same.

Now, the GRUB knows that the kernel version 2.6.32 is to be loaded and it is in root (/) directory (the kernel is a compressed file and can decompress itself in case of a system call.) GRUB makes a call to the kernel (which is the vmlinuz-2.6.32-504.8.1.el6.x86_64 file in the configuration above) to decompress itself and start.

The kernel checks if your graphics card is there and running and if it supports complex text modes. After that it checks the hardware present on the computer (hard disks, network cards, TV cards etc.) and loads the relevant drivers. The kernel displays all the progress with informative messages during this time, as you can see in the screenshot.

After this boot stage the kernel tries to mount the file system. It tries to auto detect the file system and if it succeeds, carries on. If not, a kernel panic occurs and the system stops. If not, the kernel finally hands over the remaining job to the process named init and waits.

Init is the first process in the Linux system, with Process ID (PID) 1 and it initializes the rest of the system.

One of the most important concepts in how Linux works are the runlevels. These modes of operation allow Linux to run in V-style initialization state. After we see what is the system state in each runlevel, we continue with the initialization process in all Linux systems. Discussing the step by step process of what Linux initialization does. This will help to explain how does Linux work. Then we discuss the graphical login window, which means the system is up and running for the graphical user mode.

Linux Runlevels

Users migrating from Windows have difficulty understanding the runlevel concept in Linux. We have to understand what is a runlevel? And what does the computer do at the specified runlevel? to understand the remaining init process.

Linux is a multiuser system and it loads/halts the necessary programs to act as single user, multiuser, graphical desktop, and to halt or restart the system. The runlevels are numbered from 1 to 6 and the corresponding system states are as follows:

Runlevel 0: shutdown/halt the system

Runlevel 1: single user mode

Runlevel 2: multi user mode without network

Runlevel 3: multi user mode with network

Runlevel 4: reserved for local use (GUI mode for Slackware only)

Runlevel 5: graphical user interface (GUI) mode

Runlevel 6: reboot

There are programs that have to be started in each runlevel. These programs are listed in rcX.d files present in /etc, where X indicates the runlevel number (for example rc3.d is the file that holds information about which programs to start/stop for runlevel 3.) /etc/init.d directory holds the information to point at these files for the init to look for.

The rc3.d contains symbolic links to /etc/init.d files as:

S90crond -> ../init.d/crond

K88sssd -> ../init.d/sssd


We said the programs are started or stopped. If the computer is booting, the programs are started and preceded with S in the rcX.d files. If the computer is shutting down, they are preceded with K. ‘S’ is for ‘start’ and ‘K’ is for ‘kill’.Having all these in mind, let’s go on with the init process.

  • Init

    When the init process starts, it checks configuration files to carry on its job. First of all, it looks at the /etc/inittab which tells the init which processes to start. In the /etc/inittab file is the information about the runlevels. The default runlevel for the system is indicated by the line id:X:initdefault where X is the runlevel number.

    As you may have guessed, the runlevels have direction settings 1 -> 2 -> 3 -> 5. Meaning, if you want your computer to boot to runlevel 3, runlevel 1 programs are started, then runlevel 2 programs then runlevel 3, and the system is booted. In this scenario, runlevel 5 programs are not started.

    Then the init performs system initialization, named sysinit.

    Depending on the runlevel, init tries to figure out if it is a part of a network. Then it mounts /proc, where Linux keeps track of various processes and hardware (try cat /proc/cpuinfo at the command line), and checks the BIOS to align the system with the BIOS settings such as date and time, and sets the time zone. After that init mounts the swap partition (which Windows users know as pagefile) as defined in the /etc/fstab. When finished, it goes on to setting the hostname, which is the system’s “name” in the network. After that, it mounts the root file system (/ in Linux notation) and checks the /etc/fstab again to verify the other file systems if specified.

    Then it goes on to identify the Plug’n’Play devices in the system and makes the operating system aware of them by executing some routines. Init finally checks if there are any RAID devices in the system and verifies them. Reaching the last stages, it mounts all the file systems defined in /etc/fstab. Of course, if there are any other tasks specified in the /etc/fstab, init executes them also.

Logging in

When all of the above are completed successfully, init executes the /sbin/mingetty processes, which shows the graphical login screen of the distribution. Reaching this state means that the system is up and running in graphical user interface mode and waiting to know which user will log in.


Structure Of Linux Operating System

An operating system is a collection of software, each designed for a specific function.

Linux OS has following components:

1) Kernel

kernel is the core of the operating system. It establishes communication between devices and software. Moreover, it manages the system resources. Basically it has four responsibilities:

  • device management: A system has many devices connected to it like CPU, memory device, sound cards, graphic cards, etc. A kernel stores all the data related to all the devices in device driver (without this kernel won’t be able to control the devices). Thus kernel knows what a device can do and how to manipulate it to bring out the best performance. It also manages communication between all the devices. Kernel has certain rules that has to be followed by all the devices.
  • Memory management: Another function that kernel has to manage is the memory management. Kernel keeps a track of used and unused memory and make sure that processes shouldn’t manipulate data of each other using virtual memory address.
  • Process management: In process management kernel assign enough time and gives priorities to processes before handling CPU to other process. It also deals with security and ownership information.
  • Handling system calls: Handling system calls means a programmer can write a query or ask the kernel to perform a task.

2) System Libraries

System libraries are special programs that helps in accessing the kernel’s features. A kernel has to be triggered to perform a task and this triggering is done by the applications. But applications must know how to place a system call because each kernel has a different set of system calls. Programmers have developed standard library of procedures to communicate with kernel. Each operating system supports these standards and then these are transferred to system calls for that operating system.

Most well known system library for Linux is glibc (GNU C library).

3) System Tools

Linux OS has a set of utility tools which are usually simple commands. It is a software which GNU project has written and publish under their open source license so that software is freely available to everyone.

With the help of commands you can access your files, edit and manipulate data in your directories or files, change location of files or anything.

4) Development Tools

With the above three components your OS is running and working. But to update your system you have additional tools and libraries. These additional tools and libraries are written by the programmers and are called tool chain. A tool chain is a vital development tool used by the developers to produce a working application.

5) End User Tools

These end tools make a system unique for a user. End tools are not required for the operating system but are necessary for a user.

Some examples of end tools are graphic design tools, office suites, browsers, multimedia players, etc.