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.
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.
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
Unit
Information and dependencies used to describe the service
Service
Describe the service itself
Install
Describe 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
exec
to run the appropriate program
script ... end script
script 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