1. What are systemd and SysVinit?
systemd
andSysVinit
AllLinux initialization system (init system), used to manage system startup, services, processes and logs.
Comparison | SysVinit | systemd |
---|---|---|
Startup method | Step by step (serial) | Parallel startup (parallel) |
Service Management | Based on init scripts | Based on unit files |
Dependency management | Depend on manual definition | Automatically handle dependencies |
Startup speed | slow | Fast (parallel optimization) |
Log Management | /var/log/messages | journalctl |
Whether to support cgroups | no | yes |
Used by default | Old version of Linux (CentOS 6, Ubuntu 14) | Modern Linux (CentOS 7+, Ubuntu 16+) |
2. SysVinit Detailed explanation
SysVinit
(System V init) was from early Unix systemsinit
Process, responsible for system guidance and service management.
(1) How SysVinit works
- Read
/etc/inittab
SureRunlevel - exist
/etc//
Execute in the directoryStart the script - according toSequence (serial)Start the service in turn (start slowly)
(2) SysVinit run level
Running Level | effect |
---|---|
0 | Shut down |
1 | Single user mode |
3 | Pure command line mode |
5 | Graphic interface mode |
6 | Restart |
(3) How to start the service in SysVinit
-
SysVinit
use/etc//
scriptAs a service management method:
/etc//nginx start /etc//nginx stop /etc//nginx restart
- Can also be used
service
Order:
service nginx status service nginx restart
-
chkconfig
Used to manage power-on:
chkconfig nginx on # Start up automaticallychkconfig --list nginx # Check whether the power is turned on and on
(4) Problems with SysVinit
- Service startup is serial and slow
- Unable to track process status
- Log management dependency
/var/log/messages
, inconvenient query - Service dependencies need to be processed manually
3. Systemd Detailed Explanation
systemd
It's from modern Linuxinit
Process, replaceSysVinit
, providing faster startup speed and stronger service management capabilities.
(1) systemd
Features
- ✅ Parallel startup: Multiple services are started at the same time to speed up the system boot.
- ✅ Automatic dependencies processing: no manual configuration required
chkconfig
。 - ✅Usage
unit
File replacementinit
Scripts: More structured and easier to maintain. - ✅ Built-in
journalctl
Log management: It is more convenient to query logs. - ✅ Support
cgroups
Process control: manages process lifecycle.
(2) systemd
Start the service
-
systemctl
yessystemd
Service management tools provided:
systemctl start nginx # Start the servicesystemctl stop nginx # Stop servicesystemctl restart nginx # Restart the servicesystemctl status nginx # Check service status
- Set up power-on and start:
systemctl enable nginx # Start upsystemctl disable nginx # Cancel boot
- List all running services
systemctl list-units --type=service
(3) systemd unit file
-
systemd
use/etc/systemd/system/
In the directory.service
File management services, such as:
[Unit] Description=NGINX Web Server After= [Service] ExecStart=/usr/sbin/nginx -g "daemon off;" ExecReload=/bin/kill -s HUP $MAINPID KillMode=process Restart=always [Install] WantedBy=
-
systemd
Readunit
After the file, you can use itsystemctl
Direct management services:
systemctl daemon-reload # Reload the configurationsystemctl restart nginx # Restart the service
(4) systemd log management
-
systemd
usejournalctl
Record all system logs:
journalctl -u nginx # View Nginx related logsjournalctl -f # View logs in real time (similar to `tail -f`)journalctl --since "1 hour ago" # Check out the latest 1 Hourly logs
4. The difference between systemd and SysVinit
Function | SysVinit | systemd |
---|---|---|
Startup method | Serial startup | Parallel startup |
Management method | script | systemctl |
Dependency management | Manual configuration | Automatic processing |
Startup speed | slow | quick |
Log Management | /var/log/messages | journalctl |
Whether to support cgroups | no | yes |
Restart a single service | service nginx restart | systemctl restart nginx |
Check service status | service nginx status | systemctl status nginx |
5. How to tell whether the system uses SysVinit or systemd?
Method 1: Check /sbin/init
ls -l /sbin/init
If output:
lrwxrwxrwx 1 root root 22 Mar 12 2025 /sbin/init -> /lib/systemd/systemd
- illustrateuse
systemd
。 - if
/sbin/init
yes/etc/
Binary files in the directory, InstructionsSysVinit
。
Method 2: Check the process
ps -p 1
If output:
PID TTY STAT TIME COMMAND
1 ? Ss 0:00 /lib/systemd/systemd
illustrateusesystemd
。
If output:
PID TTY STAT TIME COMMAND
1 ? Ss 0:00 /sbin/init
illustrateuseSysVinit
。
Method 3: Run systemctl directly
systemctl --version
- If return
systemd
Version number (such assystemd 249
),illustrateusesystemd
。 - if
systemctl
The command does not exist,useSysVinit
。
6. Which Linux versions use systemd?
Release | The init system used |
---|---|
CentOS 6 and earlier | SysVinit |
CentOS 7 and newer versions | systemd |
Ubuntu 14.04 and earlier | SysVinit |
Ubuntu 16.04+ | systemd |
Debian 7 and earlier | SysVinit |
Debian 8+ | systemd |
Last:
-
SysVinit
yesTraditional Linux boot management system,useScripts, slow startup, rely on manual management.
-
systemd
yesModern Linux standardsinit
system,supportParallel startup、Automatically manage dependencies, greatly improvedStartup speed。 -
systemctl
Replacedservice
andchkconfig
, provide stronger management capabilities. -
journalctl
Replaces tradition/var/log/messages
Log management.
If your system is CentOS 7+ or Ubuntu 16+, you should usesystemd
InsteadSysVinit
。
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.