Getting started with the Linux Kernel (non-advertising)
I have been in touch with the Linux kernel for 4 ~ 5 years. Although I can’t say I know the Linux kernel very well, I have some idea at least. Therefore, this article mainly wants to share my Linux kernel entry road, if it is helpful to you, I hope to be able to forward it, to help more students who want to learn the kernel.
My path to code farming
My major in university is not computer science, but applied chemistry. I was introduced to PHP by chance (it was pretty popular at the time) and became obsessed with it, borrowing almost every PHP book in the library.
Since I am not a computer major, I can only read PHP books secretly in class (not really, because no one pays attention, haha). I started to write my own message boards, small forums, blogs and so on (back in 2008-09, forums seem to have disappeared now) and started to access MySQL database.
Of course, writing small forums was not enough for me, so I began to see how PHP was implemented. But when I looked at it, I found that all the files were.c files. I used to contact with.php, so I couldn’t understand it at all. A quick Google search revealed that the.c files were written in C.
OK, do not understand school cough up, good at that time is a big four, more idle. Went to the library to borrow a classic Tan Haoqiang version of the “C language programming”, now think of it, although this book many small mistakes, but also relatively popular, unlike the CLASSIC C language K&R version of the “C programming language” so difficult.
PS: I think the criterion of a good book is whether you can learn something from it. So for me, Tan haoqiang’s version of “C language programming” is a good book.
C is easy to language, but f * * king hard to use. PHP is the best language in the world!! But I learned C only so I could read PHP source code. With a little foundation in C language, I began to look at PHP source code, starting with PHP 3.0. In fact, at that time still do not understand, and little information.
I don’t remember how I started, but one day it was like an Epiphany. “, and then started to look at the source code for PHP 4.0.
This was the beginning of my career as a programmer…
After graduation, I have been engaged in THE development of PHP. Because I am not a computer major, IT is very difficult to find a job at the beginning, so I can only start from a small company (as the saying goes, everything is difficult before it is easy).
In 2011, just two years after graduation, I started to want to share my experience without knowing how to do it (young people are not sensible), but I think I didn’t have much experience to share at that time… I invited my handsome brother To write a PHP book called PHP Core Technologies and Best Practices.
Why learn the Linux kernel?
Having said that, let’s talk about why I want to learn the Linux kernel. Since my first company was a small company, I had to do a lot of things by myself, such as compiling and installing PHP environment, installing MySQL database, etc. (because there was no cloud platform at that time, we built our own machines).
So I began to learn about The Linux system. Although I had messed with Linux in college, I didn’t know much about it. When I first started using Linux, being used to Windows, I found it too damn hard to use. But because of the need to work can not be forced to scalp.
There are a lot of strange problems with file systems, such as insufficient inodes. .
Out of curiosity and ignorance, I downloaded the latest version of Linux source code (3.0 at the time). Decompression after a look, dumbstruck, it is the same as heaven (because at that time also looked at the PHP source code for a long time, also have a deeper understanding of THE C language), this is the C language I know? So, had to give up.
However, I started learning the Linux kernel again with the conviction that I wanted to find my roots. Here is my way of learning.
The path to the Linux kernel
Having learned from last time, I’ll start with a lower version of Linux, Linux 0.12. I started with 0.12 because there is a great book introduction to the 0.12 version, Called The Complete Anatomy of the Linux Kernel. Here is its cover:
In fact, it was difficult to read this book at the beginning, mainly because I am not a computer major, so the hardware related knowledge is relatively poor. In addition, the kernel is full of assembly code, so it is necessary to understand assembly language first.
It wasn’t until I discovered x86 Assembly Language — From Solid Mode to Protected Mode that I began to understand the principles of operating systems. The cover reads:
This book opens up a lot of mists to me, such as real mode and protected mode, virtual memory and physical memory mapping, etc. One problem with this excellent book is that Linux uses AT&T-style assembly, while this book introduces Intel-style assembly. So, before looking at the kernel, it’s a good idea to check out AT&T-style assembly, and there are plenty of sources online.
Therefore, I suggest that the first read “x86 assembly language – from real mode to protected mode” this book, and then read “Linux kernel complete anatomy”, that basic can understand Linux 0.12 source code, understand Linux 0.12 is the entry of the Linux kernel.
The Linux kernel advanced path
Now that you understand Linux 0.12, you’re ready to look at higher versions of the kernel. But before looking at advanced versions of the kernel, it’s best to understand modern Linux design, so I recommend the following book, Linux Kernel Design and Implementation:
This book introduces Linux version 2.6, which is relatively simple and does not show much code. The downside is that it’s a general introduction to Linux design without a detailed analysis, but it’s a good way to get started.
Then it’s time to look at the most classic book on the Linux kernel: Inside the Linux Kernel.
This book is to learn the kernel must see the book, it is very detailed analysis of the Linux kernel principle and implementation, and the translator is in the Linux kernel is very accomplished “Chen Lijun” teacher, translation quality is good. This book also analyzes Linux 2.6, so after reading this book, you can go straight to Linux code.
Anything else?
After reading the above 4 books, the kernel also has a good understanding, of course, the most important or to see the kernel source. If reading these books above, or feel not too understand, so it is necessary to sacrifice a artifact. Here it is:
Why is this book an artifact? Because this book is the most detailed analysis of the kernel I’ve ever read, detailed enough to make you feel wordy. On the downside, the Linux version is too low (2.4.0), and there are a few illustrations.
In addition to the above, I would also recommend the inside Linux Kernel Architecture book:
This book analysis is more detailed, and the version is relatively high, this book I think as an option to read it, do not see it does not matter, you can directly look at Linux source code.
Finally,
Linux kernel reference books are probably above these, of course there are many other books, but I think after reading these, and then directly look at the source code is good, after all, look at the source code to really understand Linux.
Let’s summarize the order in which to read the above books:
In his book Outliers, Gladwell pointed out that the genius in people’s eyes is not superior in talent, but continuous efforts. 10,000 hours of training is the necessary condition for anyone to become a world-class master from an ordinary one.
So if you’re not a genius, follow the 10,000-hour rule.
In addition, if you are just getting started, I suggest you bookmark this article and follow this learning path. I think you will be able to learn the Linux kernel.
So what’s the use of learning the Linux kernel? The most obvious is the ability to fake a pussy bar during an interview and solve some weird core problems on the job.