Linux Core Concepts -1

Saurav chaudhary
10 min readAug 30, 2021
Welcome to the world of Linux 😄

What are we going to learn in this Blog?

  1. Introduction to the Linux Kernel
  2. Kernel Space and User Space
  3. Working with Hardware
  4. Linux Boot Sequence
  5. SYSTEMD TARGETS (RUNLEVELS)
  6. Filesystems and Hierarchy

Linux Kernel

If you have worked with any operating system, you have likely to come to a word kernel. So what exactly is a kernel. what exactly a kernel do ?

Kernel acts as a interface between the computer hardware like CPU , memory , devices and the applications /processes. It works efficiently to manage some of the kernel properties.

Let’s understand this kernel via a example.

lets suppose a scenario where our college have a library. I guess everyone college has a library 😕. Library has got books , study guides ,workstations for students . but there is no librarian to manage the records . the library has no record of who borrowed what and for what time . in this case there will be a time when there will be a lack of resources in the library . so that's why a librarian is need to manage all the resources out there . now lets replace the example of the librarian with the Linux kernel ,replace the example of books ,study guides with the computer hardware like CPU , memory , devices and replace students with the application/processes.

In this way Linux kernel Manages the application or the processes along with the computer hardware things by creating a interface to work efficiently and run those processes in a smooth way.

Now I hope u know what is kernel.

Now Let’s learn what functions does kernel provides?

  1. Memory Management — Kernel takes care of which process has taken how much of memory and where and in this way it helps in managing the memory .
  2. Process Management — It determines which process can use the CPU and for how long it can use it?
  3. Device Drivers — It acts as a interpreter or a mediator between the hardware and the processes.
  4. System Calls and Security — It receives request from the processes known as a system call and completes the security processes to clarify there is no such vulnerates in-between.

Some of the main features of the kernel are

  1. Monolithic — Monolithic simply means, kernel manages memory management , CPU scheduling , process management of their own.
  2. Modular — Modular simply means it can extend its capacities by dynamically loaded of their kernel and use that to work as per requirement in a more efficient manner.

How can be check which kernel we are using and the details of the kernel ?

Ans — Run uname

By running this uname command in your Linux u will get just a simple output of which OS kernel you are using.

To know more info about which kernel you are using run uname -r command.

4 = Kernel Version

15 = Major version

0 = Minor Version

72 = patch release

Generic = Distro Specific Info

Let’s Dive more Deeper

Kernel And User Space

Now our kernel is further divided into two of it spaces for performing any functions.

  1. Kernel Space — The kernel space is the space where all the kernel code executes along with all the kernel extensions with the help of the device drivers that acts as a mediator between them. This kernel space is unrestricted with the hardware management uses like the CPU as such it is restricted with the following —

a) Kernel Code

b)Kernel Extensions

c) Device Drivers

You can think this this kernel space as the private space where the librarian manages all the records to handle all the tasks.

2. User Space — The user space is the space where all the processes or the applications perform their actions. All the Linux kernel comes pre-build with a user space in any of the programming language Like C, java ,python, Ruby, docker containers and this comes with a GUI. you can think this user space as the space where students in the library make use of the resources like books, study guides to study.

In order to perform certain operations user space is meant to send a request to the kernel space in the form of a system calls. These system calls started from the user space passes through the kernel spaces executers all the actions that needed to perform then it goes to the hardware and finally the action has been performed. system calls is done in order to open a file , write to a file , list processes, defining a variable and much more.

Example — Lets suppose we have to perform a process of open a file in the system . Then in the user space we will type the command in the cli i.e. cat /etc/os-release . This will make a system call as the open process then it will go the kernel space execute its actions and will open the file successfully. we can perform actions like open(),close(),readdir(), strlen(), closedir() and many more.

Working With Hardware

Now as we have worked with a internal hardware like the CPU and now its time to get the information of the external hardware. Any external hardware like USB drive which usually contains study material for Indian students. Like this blog if u know what I mean 😝

Let’s say this USB drive has been connected with the system then the device driver which is in the kernel space detects a state change and when ever a state is changed there occurs a UEVENTS in the system. After the occurrence of the uevents it goes to the user space which has UDEV utility which is responsible for creating a user space. Here in this example udev will create a user space where we can physically see the usb drive study material in the system in the directory of /dev/sdb1 .

Now Let’s get some detailed information of the hardware Using the command line .

Run dmesg

This dmesg command will collect all the information which lies in the buffer section of the kernel space . it contains all the information when the system boots up . a lot of information is there so we need to filter some specific information , lets say information about our USB drive . so we will run this command.

Here you can see a detailed information about the USB drive that is attached to our system.

Now we have got a special utility called UDEVADM . Run udevadm info command to get a description of the hardware. This command runs as an query within the database and give that list outs the info as the output.

Run udevadm monitor command and you can see the transparency work on how the state changes occur when ever a device has been inserted. you can see the info when a hardware attached and when it detached. this is the most loved beginner command as I love it too.

run lspci — PCI means
Peripheral Component Interconnect

This command is used to list out the hardware like audio devices , video devices , ethernet controller. These devices are directly attached to the motherboard of the system. It will list out those hardware short description as the output.

Run lsblk

This command is used to list out the block devices information that has been connected wit the system .

These SDA are the physical disk that been more divided into subspaces like sda1, sda2, sda3 ,sda4, sda5. This further classification is more like a temporary space sub-division and we can reuse this space to store data again and again.

The MAJ:MIN that has been marked is that denotation of the physical disk and the further divisions. In the fig, we have MAJ as 8 which represents a SCSI DISK and the MIN represents the further divisions of that spaces where data will store.

Run lscpu command to get a detailed information about the CPU configuration in your system. you can see the architecture , CPU family ,model name , vendor id , sockets ,core , threads and much more.

AHHHH, here we go again. Let’s deep dive and see how actually CPU works for the system .

As in early 90's only 32 bit OS was there in the market. And 32 bit OS means we store the data in the register up to the value of 2 to the power of 32 . Register stores the data from the memory and performs the tasks associated with the data. The memory was also limited to 4 GB at the time. That means at that time we run a software version of only 32 bit in the 32 bit OS. while compare this situation as of now , we have got 64 bits OS in the market which can stores data up to 2 to the power of 64 in the register and has the memory of 18 EB. As of now we can run 64 bits software versions as well as 32 bit software version on 64 bit OS but 32 bits is only recommended to run until you have no other options left otherwise in some cases it will cause some complications.

some more deeper we need to go as I am not feeling the vibe now 😅

So our 64 bit OS that we use in the this example have 1 physical socket which acts as a CPU in them as currently mentioned in the fig to. This socket further divides in the cores. we have got 4 cores in my laptop .Comment down and tell me how much u have got. Now these cores are further consists of threads . each core has 2 threads in my system which is actually responsible for performing hardware tasks. So we have got a number of virtual CPU's in our system .

Do you want know the formula of calculating the virtual CPU's in your system

here is the formula — Sockets x Cores x Threads = CPUs

Run lsmem — summary command to list out the memory summary of how much memory has been availed offline or online and total memory pf block size .

Run free -m command to see how much memory has been used and how much has been left in your hardware. Here -m is used to output the data as in mb , you can use k for kb and much more.

Run lshw command , this command will list out the hardware configuration of your system such as the firmware , core , capabilities and a description of your hardware.

HAHA what you can’t run these command.

Sometimes you don't have the privilege's to run some specific command. you need to have sudo features to run some specific command . we will cover sudo in much more detail as this will cover one single blog on its own . so basically you just need to run this command as a sudo user by adding sudo before the command. As easy as that. it will prompt for your password while running this sudo command.

Hands-on experience exercises

There are some sets of questions based on the Linux core concepts those you have learned above, now its time to test yourself . so make sure to test yourself before moving to the next blog .Comment on the blog and let me know how much marks you have achieved. In case of any doubts/questions/suggestions feel free to Dm me on Twitter.

  1. What is the exact version of kernel running in this system?
  2. what is the kernel version in 4.15.0-88-generic?
  3. What is the major version number of the kernel in 4.15.0–88-generic?
  4. What is generic in this version?
  5. Which command would you run to print the messages generated by the kernel?
  6. How many block devices of type disk are present in the system?

Try this all questions to test yourself and let me know

Yep , Finally its over 😢. But this was just the part 1 ,take a break & come back tomorrow for part 2 Of Linux core concepts. Till then, oops my dog want to say something to YOU !

Happy learning 😃

Follow us on Twitter To join us in the initiative of learning Devops in 60 days.

see you in next blog, stay happy 😄

--

--