Linux init system

Source: Internet
Author: User

I have the version of ArchLinux, FEDORA20, Debian7, centos6 I mainly described these versions as an example, the BSD init version of the default is not, so can not be verified, the description is likely to be vulnerable. where ArchLinux, fedora20 use systemd,debian7 using the system V INIT,CENTOS6 using upstart.

Before we talk about Init, let's talk about the startup process of Linux kernel, which will be different on the PC and on the arm embedded Development Board.

System boot
  • PC
    The device will run a segment of code at the specified location after power-up, this position 0XFFFF0 is the BIOS that is cured on the motherboard (now UEFI), the Bois will load the program from a location on the disk after the self-test, and if the MBR partition runs a 512-byte MBR program located on the disk 0 0-Bar 1 sector, the MBR program passes the 446+ A 1-byte position reads a 64-byte partition table and loads the bootload on the boot flag partition, typically making grub, Lilo. UEFI boot, UEFI will go directly to the GPT partition of the FAT file system to find the EFI boot file and load, this file will load grub or other boot (Lilo support pending verification). Grub itself is a reduced version of the kernel, and grub itself contains stage1,stage1.5,stage2 three steps. It loads the kernel (GRUB2 is the linux instruction) Vmlinuz file through the kernel instruction and passes it to the kernel boot parameters, loads the RAM disk file through the INITRD instruction, and then the kernel is loaded into memory and runs.
    The boot directory in EFI startup mode such as:

    Boot directory in BIOS startup mode such as:

    Vimlinuz-linux is a kernel file loaded by the kernel instruction, Initramfs-linux.publication/image is a Ramfs file loaded by the INITRD instruction. The
    EFI directory, such as:

    The EFI directory is a partition of a FAT file system that is mounted. Includes multiple EFI files that can be loaded by UEFI.
    Grub-loaded configurations such as:

  • Development Board
    When the board is power-up, it reads the bootload from a location on the Norflash or Nandflash, and then the kernel is loaded into memory by the bootload, and the kernel starts running directly. On ARM Linux after 3.0, kernel will read LDS from somewhere in Flash to load configuration information for the onboard resource.

After the kernel initialization is completed, it needs to be associated with the root file system, the PC version of the kernel will use INITRD to do the bridge load root file system, and Armlinux directly according to the configuration to load and file system.

Introduction to Early init systems

After all the kernel operations are completed, a program to execute is loaded from the root filesystem, which is the parent of all programs and the protagonist of our day, init. Well, the front of the nonsense too much, now only to get to the point ...

init has a long history, and early Linux used init with two versions: sysv and bsd . Now they are still not completely abandoned, and there are still many distributions that use both systems such as Dibian and the system V Init,archlinux to discard BSD init to systemd before and after 20jenk12 years. Don't say much nonsense, describe it separately.

  • BSD

    Pre style= "FONT-SIZE:0.85EM; Font-family:consolas, Inconsolata, Courier, monospace;font-size:1em; Line-height:1.2em;margin:1.2em 0px; " >-use rc.x as the file name in the/etc directory to describe the operation of Init-rc.sysinit-rc.single single user execution-rc.multi2~5 execution-rc.local is miscellaneous-the INIT system loads the run-RC in the order above. The conf contains the associated configuration
  • System V

     - 脚本文件目录在`/etc/init.d/` - `/etc/rc{runlevel}.d`目录标识相应运行级别的目录 - 目录下的文件以S开头的是启动的服务,以K开头的是不启动的服务 - 启动标识后紧跟的数字表示启动优先级,数值越小运行越早 - 通过service命令来起停服务 - 通过chkconf来管理服务 - 通过`/etc/inittab`文件来配置相应的运行级别

The files loaded by both Init systems themselves are script files that can be used to load the appropriate modules or to start the required program.
BSD init content for specific services:

#!/bin/sh. /etc/rc.subrname="Dummy"Start_cmd="${name}_start"Stop_cmd=":"Dummy_start(){Echo "nothing started."}load_rc_config$nameRun_rc_command"$"

SYSTEMV init specific service configuration content:

#!/bin/sh# # # BEGIN INIT INFO# Provides:sudo# Required-start: $local _fs $remote _fs# Required-stop:# X-start-before:rmnologin# Default-start:2 3 4 5# Default-stop:# short-description:provide Limited Super User privileges to specific users# description:provide Limited Super User privileges to specific users.# # # END INIT INFOn=/etc/init.d/sudoSet - e Case "$" inchStart# Make sure privileges don ' t persist across reboots        if[- D/var/lib/sudo] Thenfind/var/lib/sudo-exec touch-t198501010000 ' {} '\;fi;;  Stop|reload|restart|force-reload|status);; *)Echo "Usage: $N {start|stop|restart|force-reload|status}">&2        Exit 1;;EsacExit 0

There is no difference between the two from a grammatical point of view.

There are some problems in the early Init system, such as the inability of parallel tasks, the lack of effective communication mechanism between the tasks, the monitoring of the process can only be done by pid ...

Introduction to Modern INIT systems

Systemd and upstart in this case, they are all event-driven, and have to say that because the SYSTEMD start time is later than upstart so many features also draw on upstart, while Systemd also borrowed from the Mac OS X's launcher system.

  • Systemd

    SYSTEMD is a system and service Manager under Linux that is compatible with SysV and LSB startup scripts. SYSTEMD Features: Support for parallel tasks, the use of socket and D-bus bus activation services, on-demand Boot daemon (daemon), the use of Linux cgroups monitoring process, support snapshot and system Recovery, maintain mount point and automatic mount point The services are precisely controlled based on dependency relationships.

    --Wikipedia  

Systemctl to manage Systemd, and also compatible with service commands
All SYSTEMD are configured in the /usr/lib/systemd directory and will be linked or copied to the/ETC/SYSTEMD directory when the boot is used.

  • Upstart

    • Use Initctl to manage upstart
    • Configuration items in /etc/init/ directory
    • Ubuntu in/etc/rc.confThe last line throughexec /etc/init.d/rc $RUNLEVELTo start the appropriate level system, Debina in the/etc/inittabAdded inid:2:initdefault:

    I remember that the upstart configuration of Ubuntu is different from the CentOS configuration method, which cannot be further verified here.

Use of SYSTEMD and upstart

First, separate the code, SYTEMD:

[Unit]Description=OpenSSH DaemonWants=sshdgenkeys.serviceAfter=sshdgenkeys.serviceAfter=network.target[Service]ExecStart=/usr/bin/sshd -DExecReload=/bin/kill -HUP $MAINPIDKillMode=processRestart=always[Install]WantedBy=multi-user.target

Upstart:

Start on fedora.serial-console-available dev=* and stopped RC runlevel=[2345]stop on RunLevel [s016]instance$DEVRespawnpre-startexec/sbin/securetty$DEVexec/sbin/agetty/dev/$DEV $SPEEDVt100-navpost-stopexec/sbin/initctl emit--no-wait fedora.serial-console-available dev=$DEVSpeed=$SPEEDUsage' Dev=ttysx speed=y-where X is the console ID and Y is baud rate '

See what the difference is?

Upstart and SYSTEMD are new ways, upstart is the way of command, SYSTEMD is conf form.

Systemd
  • UnitInformation and dependencies used to describe the service
  • ServiceDescribe the service itself
  • InstallDescribe his operating environment.
  • The RunLevel is also managed through SYSTEMD.
Upstart
  • start on runlevel [012345] stop on runlevel [!RUNLEVEL] to develop specific operational levels through and
  • execto run the appropriate program
  • script ... end scriptscript can be embedded directly through the instruction

For more detailed configuration please refer to the relevant manual.

We can --init=xxx specify the init system used by the kernel parameters. Of course, the specified init can be any program, you can directly specify to be any program you want.

Most of the Linux distributions are already using SYSTEMD as the default init system, Ubuntu is now using the upstart system, and Debain is voting to choose Systemd, Ubuntu also announced that it would accept Debian's upstream selection decision.

It seems that Systemd has the trend of unified Linux World init system.

?

Linux init system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.