Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Linux \ To_explore Linux system boot process     - OpenGL ES 3.0 vertex buffer (Programming)

- Add your own kernel and ramfs based on an existing Linux LiveCD (Linux)

- impdp error ORA-31631, ORA-39122 (Database)

- Zabbix monitors Nginx status (Server)

- Use Visual Studio 2015 to develop Android program (Programming)

- To install Git on Ubuntu systems (Server)

- df show disk space usage (Linux)

- Ubuntu 14.04 can be used to create a WIFI hotspot for Android (Linux)

- AngularJS notes --- Data Binding (Programming)

- Android first line of code study notes (Programming)

- Additional SQL Server 5123 database reported error (Database)

- Oracle Linux 7.1 install Oracle 12C RAC (Database)

- Bash added to the Vi mode indicator (Linux)

- Red Hat Linux mount U disk (Linux)

- CentOS 6.4 RPM install MySQL-5.6.22-1 (Database)

- Linux C source code (Ascii HexToBinary: Converts hexadecimal string format ASCII codes) (Programming)

- Development environment to build MEAN In Ubuntu 15.10 (Server)

- Linux in order to make NMAP hide and seek with the firewall (Linux)

- ASM required disk format process in Solaris platforms (Linux)

- CentOS 6.4 dial-up Raiders (Linux)

  To_explore Linux system boot process
  Add Date : 2018-11-21      
  Read catalog

Linux boot process overview
Grub loading the Linux kernel and initramfs
Explore ways initramfs file
Based on the systemd init system
Into the graphical interface
This article is a bit long, it took me about two weeks to complete, although not exhaustive written, but I think it is very valuable, seeking recommendations. Whether you are Linux enthusiasts, but also whether you have the patience to read, please mark the decisive, you deserve to have.


This may be a series of essays in addition to my summary than the last one, it may not. Why do you say? Because I think to write down in a Linux application environment may not have anything new, at least to my level of write anything new. I have this one series, not substantially related to the program, but really to the Linux desktop as a tool for everyday use, there is to explore C language or Bash language even in my part of this series, I also show related development tools, such as binutils Kit and autotools tool chain. I have said that Linux is the toss toss software under Linux system, Linux software world as much as there should be written a lot, but I think that is no way to write good. For example, there is some work I have not found the proper tools, such as JavaScript and CSS development, for the majority of the front end of the garden blog siege lion, this is definitely their own supernatural powers, but I do not know what tools can do that is easily and high efficiency, I would simply use Firefox developer tools provided. There are 3D development, game programming, mobile development and so on, although you can write relatively broad field, but after all, I'm not doing this, no experience, you can not say certain optical writing software trial experience it. Besides, after all, a programmer or a programmer, later wrote blog should still introduce programming experience better.

The reason why think of to write these things, it is because I really want you to like me, the Linux desktop tool to fight really use every day, rather than try a few and then deleted after installation. I was really in their daily life and work are using Linux, such as programming in Linux, write a blog, write papers and do slide. Of course, for LibreOffice to use such software will not have any trouble, so basically my blog did not mention, like under Windows programmer to write MS Office does not use the same guidelines. If someone can not insist on using Linux, it must be Linux some difficulties to defeat him. Indeed encounter many difficulties just use Linux, such as the interface is not beautiful, ah, ah font pleasing to the eye is not enough, too hard to use input method ah, there is a want to work can not find a tool that would change a property not found entry , system crashes, and so can not be restored, even just to install a package or download a file, but do not know where to put the file system. So, my family is in this one to show my methodology, what software is not important, not important how good use, but encountered a problem with the idea of ​​what to look for answers, where to find the answer. After twenty few impressions, my methodology is basically finished. So I decided to finish this one to explore the Linux system boot process, I will begin another series of work.

Boot process on Linux systems also several changes. First, the operating system is loaded from disk process has changed very old operating system needs to write boot sector, operating system, now this long process to start a special tool. The most commonly used operating system loader is Grub, the name I am sure you would have a thunderous, and Grub has evolved from version 1 to version 2, we call Grub2. Grub2 and Grub1 very different, there is a lot of talk about Linux on the web articles that thing Grub1 drop of a hat, for example, so that we modify the menu.lst file like this, are very outdated content. Detailed information on Grub2 can read the document info grub or info grub2. Grub advantage is to support multiple operating system boot, Windows, Linux, BSD are alone, but they start protocol is not the same, start Windows relies chainloader, boot Linux directly linux command, and BSD systems like multiboot use, especially the Grub multiboot specification for those who want to write their own operating system programmers useful because no longer have to start from the boot sector code to write, direct access to the protected-mode operating system written in C language. Linux system also initrd or initramfs mechanism at startup, the Linux users also need special attention. initrd or initramfs also experienced a technological innovation, the beginning is used RamDisk technology, currently used tmpfs technology. Finally, the kernel loaded into memory, the control system will be initialized to the init process, and init program is not static, most started using SysVinit, later changed to Upstart, the most popular now become systemd . There are still a lot of books and web text speaking or practice SysVinit era, of course, these articles can only RedHat EL 5 and before the release of example, and for the latest releases, these articles will talk about methods and new Getting users difficult.

Explore Linux system boot process is one thing that every Linux user advances to a certain extent bound to do. Some people may just be curious, and some people may really need to start the process to solve a particular problem. I have been many times this exploration, has long wanted to write a written, but always write well. This time by systemd popular in the east, let this be the finale of the exploration process I of this series. Why is the popularity of the east by systemd it? Because I heard that Ubuntu 15.04 version of the upcoming month will replace from upstart to systemd, is currently being tested in nervously. Of course, all of a sudden came up to developers in terms of migration is still a little difficult, but just make sure goals, even Ubuntu 15.04 without using systemd, to 15.10 certainly is it. Therefore, I like to toss this multiple Linux distributions for people who do not have multi-line operations, and only need to learn systemd.

Linux boot process overview

Here briefly listed the Linux operating system to start the whole process:

After pressing the computer's power button, power on the computer, BIOS boot;
BIOS hard to read the MBR, the boot sector to run the code, the old system often need to write boot sector, and the new system is basically started by a dedicated software took over in the Linux world, we are currently used Grub2. Since the boot sector of space too small to fit too complex code logic, Grub2 also uses a multi-stage start strategy;
Grub2 responsible for the operating system kernel is loaded into memory, if necessary, they will be loaded initramfs file into memory, then transfer control to the kernel;
After the kernel is initialized, the kernel initialization process, it will give control to / init program, from entering the user space;
Because the kernel First, the initramfs file hanging in the root file system, so just start running / init program is actually initramfs file, so it is important initialization script of the necessary documents, the kernel modules and configuration files are located initramfs file this is why many times we changed some configuration files, you need to update the initramfs file and then restart the operating system to take effect;
initramfs file / init program is responsible mount a file system on the hard disk, and then switch to the root of the root file system partition on the hard disk, and then run the / sbin / init program, when all programs and configuration files, scripts are using and, of course, is the same reason the network file system on a hard disk. It can be seen running init program is a phased process;
/ Sbin / init program is responsible for system initialization, operation services, user login, and so on;
If you need to run a graphical interface, the / sbin / init program runs the Display Manager, in Fedora is gdm, in Ubuntu is lightdm. Then Display Manager is responsible for starting the entire graphical interface.
Grub loading the Linux kernel and initramfs

Research on the first leg of the Linux boot process is to study Grub. Most of the time we do not consider the Grub installation, the installation of Linux as a desktop system has helped us to automatically install Well, we need to do most is to change to change Grub configuration file. Only in one case need to manually install Grub, it is after a crash emergency, of course, you need to run a CD or U disk version of the Linux system, and then run the grub-install command, which you need to specify the Grub install to the hard disk MBR, the specific operation to look at the document.

Grub2 and Grub, compared with many improvements, improvements to Grub2 are the equivalent of a small operating system, such as a hard disk partition Grub2 can identify a variety of formats and file systems, can identify a variety of image formats, and even dynamic load module. The most important change is the configuration file from the file Grub1 /boot/menu.lst era into the era of the Grub2 /boot/grub/grub.cfg file (note that some systems are /boot/grub2/grub.cfg such as Fedora), configuration file syntax has changed a lot of complexity. Although after Syntax Grub2 profile is more complex, but we generally do not need to directly modify the file, but modify / etc / default / grub file, then use the update-grub command to automatically generate configuration files. Of course, to complete some simple tasks to /boot/grub/grub.cfg file can also be modified directly, but once the system is updated, the modified files may have been overwritten.

Grub most important task is to load the Linux kernel and initramfs files, these commands are very straightforward, in /boot/grub/grub.cfg file is also very easy to find

Mainly show Grub load the Linux kernel and the Linux kernel to pass parameters to the process, while demonstrating initramfs file loading process.

Explore ways initramfs file

Grub after the Linux kernel and the initramfs file into memory, passes control to the kernel, which will be in memory initramfs file mounted as the root filesystem, the kernel initialization is complete when the user needs to enter the space, the run / init in fact, this / init in the initramfs file, so if you want to know what the system is started after done, look initramfs contents of the document is necessary.

In the / boot directory, generally have a file or a /boot/initramfs.img /boot/initrd.img file, but depends on the contents inside have a little skill. Come learn about the history. The first question is why have initrd or initramfs, the answer is that, in order to reduce the size of the Linux kernel, there are some drivers not compiled into the kernel, but in the form of modules exist in the file system, but some file systems does it need nuclear load the corresponding driver module to read, thus forming a came first, the chicken or the egg paradox of such problems in order to solve this problem, is to drive these modules into initrd or initramfs file in, the starter will load it into memory, and then loads the kernel memory drive module, and then drive other file systems, and more work. At the same time, for many embedded operating system, it may be loaded into memory initrd or initramfs is the ultimate file system. The second issue is the initrd and initramfs file what format, how to create and open. This question is a bit complicated, let me see the following thin to me.

In fact, in Linux history, memory technology file system is not the same. In the very old system, is modeled as a piece of memory disk, called RamDisk, this technique is not efficient, why it is not high, it is because after the analog memory into disk, the disk still need to treat it the same treatment , you need to give it a specific format to create a file system to read or write a file or when to use kernel caching system, so that the same data on the presence of the two in memory, so it is a waste. initrd file used in the old system is in fact equivalent to a mirrored disk, so to read or write its contents, you need to hang it in the system, then read and write.

Now we are the new system, initrd initramfs has been replaced, although many systems still use initrd.img as the file name, in fact, using initramfs technology. initramfs technology does not use RamDisk, but the use of tempfs, which is multiplexed kernel caching system, so tempfs contents in memory, there is only one, and that is in the kernel's cache memory not only saves cost, but also improving efficiency. So what initramfs file format is it? It is compressed CPIO format, so long as cpio, open it is not a problem.

In fact, is not entirely without problems, I examined the file when Fedora initramfs.img 21 encountered difficulties. If you use cat initramfs.img | cpio -imd unlock the CPIO files, you will find only a few a few files, number of files and file sizes are far below our expectations

What went wrong? This is because Fedora 21 uses the latest Early User Space Technology. This problem also temporarily not search online answer, I also see the extracted files in a early_cpio, then early as a keyword to see the kernel code, just know. However, specific information about the technology, I did not get to know. But this is not the point, focusing on how to properly unpack this file. First, I found a Fedora 21 system files used to build initramfs tools dracut, using the methodology see my first article in the series

What went wrong? This is because Fedora 21 uses the latest Early User Space Technology. This problem also temporarily not search online answer, I also see the extracted files in a early_cpio, then early as a keyword to see the kernel code, just know. However, specific information about the technology, I did not get to know. But this is not the point, focusing on how to properly unpack this file. First, I found a Fedora 21 system files used to build initramfs tools dracut, using the methodology see my first article in the series

In this script, I found it skipcpio need to use a program, skip head initramfs file after, and then the rest of the CPIO as compressed files unpacked. Opinion, will read the script sometimes very important, so my "Bash scripting language, aesthetics and philosophy." This one does not put in writing. Finally, unpack command initramfs file like this:

sudo / usr / lib / dracut / skipcpio initramfs - $ (uname -r) .img | zcat | cpio -imd

Next, we can happily study / init program are doing a.

Based on the systemd init system

In fact, the open source community systemd is controversial, there are many people opposed systemd, reasons for the objection systemd is too complicated, it is too much to do, and it is in addition to a foreign init program is also responsible for managing the hardware, logging, time tasks, and even user logs taken over. Many people still Unix philosophy of the world is only one thing and do a good job, what should this pipe for systemd huge package, a lot of people do not like it. Another violation of the Unix philosophy where systemd is its logging system uses a binary format, instead of plain text format Unix widely used.

But let us not be misled by these objections. systemd is really a very good system initialization, at least I was in love with after using it. systemd Traditional each made a change is justified, even if the binary log format, but also to better manage and log analysis, but also provides a very comprehensive tool to view the log. The father of Linux also said he did not think of systemd, he thinks the so-called "Do one thing and do a good job," the outdated philosophy, the philosophy is only suitable for those scenes can be combined through the pipeline each program, but in reality there are many complex scenarios can not be resolved through the pipeline. Anyway, systemd use is becoming more common, Fedora, RedHat EL 7 are using systemd, the next version of Ubuntu will also use systemd. Therefore, learning systemd is a must.

Systemd best way to learn is to look at its documentation man systemd, then view other corresponding document according to the document prompts, such as man systemd.service, man systemd.target like. To fully estimate about systemd can write a book, I just talk about some of the following basic concepts.

System initialization to do a lot of work, such as hanging in the file system, start the sshd service, swap space, etc., systemd to each work as a unit, each unit corresponds to a configuration file. systemd unit in turn divided into different types, each type of unit in its configuration file with a different extension, the common unit types are:

service corresponding to a background server process, such as httpd, mysqld, etc;
soket corresponds to a socket, then corresponds to a service, similar to xinetd features;
device corresponds to a device labeled with udev rule;
mount the corresponding system of a mount point, systemd accordingly automatically mount for compatibility with SysVinit, currently systemd automatically process / etc / fstab and converted to mount;
automount automatically mount point;
swap swap space;
target configuration logic grouping unit, comprising a plurality of correlation hive, as can be SysVinit the operating level;
timer timer is used to periodically trigger user-defined actions, which can be used to replace the traditional atd, crond, etc;
systemd configuration files are stored in / usr / lib / systemd / system directory, initramfs configuration file is located relative to the natural extract the directory usr / lib / systemd / system directory of. on initramfs / init program and / sbin / init program on the hard disk are only / usr / link lib / systemd / systemd program only. After systemd starts, according to the rules in the configuration file default.target initialize the system. In fact default.target is also a link, if it is linked to multi-user.target, the start character interface, if it is linked to graphical.target, then start the graphical interface. This traditional SysVinit the run level has a certain similarity. systemd target in many of its traditional SysVinit in the run-level correspondence is as follows:

SysVinit run in the target significance level systemd
0 runlevel0.target, poweroff.target shut down the system.
1, s, single runlevel1.target, rescue.target single-user mode.
2, 4 runlevel2.target, runlevel4.target, multi-user.target user-defined / domain specific operating level. The default is equivalent to 3.
3 runlevel3.target, multi-user.target multi-user, non-graphical. Users can log on multiple consoles or network.
5 runlevel5.target, graphical.target multi-user, graphical. All services typically run level 3, plus a graphical login.
6 runlevel6.target, reboot.target restart.
emergency emergency.target emergency Shell.
A target will depend on the other unit, the unit will be relied upon more dependent on the unit, the unit will be run at the same time when the system starts, and pull out the carrot out of the mud with the principle is the same, but systemd is started in parallel each unit this can speed up system boot speed. Each unit of the configuration files are plain text, syntax is extremely simple and can be opened directly read. These configuration details I do not speak, documents which are very clearly written. For the user, as long as the use systemd management tools systemctl command can solve most of the problems.

We often deal with local and system start-up is to set some services run automatically at system startup. Recall RedHat EL 5 previous system, to make a service when the system is up and running, we need to put some script files into /etc/rc.d/init.d directory, and then in the corresponding / etc / rc. d / rcX.d directory, create a symbolic link, and also pay attention to the names of these scripts. Meanwhile, RedHat EL 5 previous system also provides several tools to simplify our work, and they are the service command chkconfig command. Now in the new system, these commands can only be recalled, systemctl command took over the work. In the following table:

SysVinit command Systemd command meaning
service foo start systemctl start foo.service used to start a service (and not reboot the existing).
service foo stop systemctl stop foo.service to stop a service (and not reboot the existing).
service foo restart systemctl restart foo.service used to stop and start a service.
service foo reload systemctl reload foo.service when supported, reload configuration files without interrupting the wait operation.
service foo condrestart systemctl condrestart foo.service If the service is running then restart it.
Are service foo status systemctl status foo.service reporting service is running.
ls /etc/rc.d/init.d/ systemctl list-unit-files --type = service can be used to list a list of services to start or stop.
Set chkconfig foo on systemctl enable foo.service next time you start or meet other conditions of service to enable the trigger.
Setting service chkconfig foo off systemctl disable foo.service next time you start or meet other conditions trigger is disabled.
chkconfig foo systemctl is-enabled foo.service used to check a service in the current environment is configured to enable or disable.
chkconfig -list systemctl list-unit-files --type = enable and disable the output in the case of service at each runlevel services.
chkconfig foo -list ls /etc/systemd/system/*.wants/foo.service used to list the services which enable and disable at run level.
chkconfig foo -add systemctl daemon-reload is used when you create a new service file or change settings.
telinit 3 systemctl isolate multi-user.target change multiuser run level.
In fact systemctl command only the corresponding * .service files into the appropriate directory only, it also shows that you want to use systemd, not just SysVinit or upstart systemd can be replaced, and all other service-related and the package needs to be modified for systemd. So, Ubuntu way to go a little bit longer.

The system uses systemd, the power supply management is taken over by the systemd. The reference to power management, is a very wonderful question because I use Linux in a notebook met, that is on my laptop into the desktop, always prompt "wireless network card has been disabled by the hardware" only the first system to hang, and then wake up, to enable the wireless card. systemd power management command is as follows:

Command Operation
systemctl reboot reboot
systemctl poweroff shutdown
systemctl suspend Suspend
systemctl hibernate hibernation
systemctl hybrid-sleep hybrid sleep mode (suspend to hard disk simultaneously and suspend)
Finally add, systemd comes log service journald, and all log information stored in binary format, the user journalctl command to view the log information.

Into the graphical interface

If you are running as a server, start the Linux system will just include the above process. If you are using Linux desktop systems, and finally also you need to enter the graphical interface. Into the graphical interface of the work is done by the display manager to complete, in Fedora, the program is a display manager gdm, in Ubuntu, is lightdm. Display manager responsible for starting the X Server and displays the login screen, after the user logs in, the display manager to start gnome-session to enter the entire desktop environment. About content X Window aspects, you can see I wrote this one "X Window mystery." Finally look at the new graphical interface of progress, and that is to replace Xorg Wayland will become the new graphics technology. However, in Fedora 21, it has been able to try Wayland, I tried a little, seemingly not very stable.

Well, the thing about the Linux system boot process write so it. Can be seen from the above, Linux also has the technology continues to progress, we need to embrace change, but not rigid. Many times, books and Web tutorials and can not keep up with the latest developments, it is we need to think for themselves and exploration, therefore, particularly important to master the correct methodology.
- How to release the cache memory on Linux (Linux)
- Linux file permissions to modify the command: chmod (Linux)
- CentOS7 complete step to install Hadoop2.7 (Server)
- Vim useful plugin: YouCompleteMe (Linux)
- Tip: Use Cryptsetup U disk encryption (Linux)
- Getting Started with Linux system to learn: how to check in a package is installed on Ubuntu (Linux)
- TNS-03505 name could not be resolved (Database)
- Python implementation restart the router (Programming)
- How to Debian Linux the default Python version switch to alternative version (Linux)
- Redhat 7 modify the default run level method --RHEL7 use systemd to create a symbolic link to the default runlevel (Linux)
- Ubuntu 14.04 and derivative version of the user on how to install cURL 7.37.1 (Linux)
- CentOS x86 64bit upgrade to 2.7 Python2.6 (Linux)
- C ++ complex class of operator overloading (Programming)
- Linux kernel likely and unlikely to resolve macro definitions (Linux)
- Linux system performance analysis and top command ps.pstree Comments (Linux)
- Install JDK 1.7 + Eclipse in CentOS 6.4 in (Linux)
- Linux package management (Linux)
- Amazon EC2 server using Rsync + Inotify real-time synchronization (Server)
- IntelliJ IDEA run in Mac10.9 and JDK7 environment (Linux)
- To explore the Android ListView caching mechanism again (Programming)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.