SoFunction
Updated on 2025-05-15

Systemd and SysVinit in Linux

1. What are systemd and SysVinit?

systemdandSysVinitAllLinux 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 systemsinitProcess, responsible for system guidance and service management.

(1) How SysVinit works

  • Read/etc/inittabSureRunlevel
  • 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

  • SysVinituse/etc//scriptAs a service management method:
/etc//nginx start
/etc//nginx stop
/etc//nginx restart
  • Can also be usedserviceOrder:
service nginx status
service nginx restart
  • chkconfigUsed 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

systemdIt's from modern LinuxinitProcess, replaceSysVinit, providing faster startup speed and stronger service management capabilities.

(1) systemdFeatures

  • ✅ Parallel startup: Multiple services are started at the same time to speed up the system boot.
  • ✅ Automatic dependencies processing: no manual configuration requiredchkconfig
  • ✅UsageunitFile replacementinitScripts: More structured and easier to maintain.
  • ✅ Built-injournalctlLog management: It is more convenient to query logs.
  • ✅ SupportcgroupsProcess control: manages process lifecycle.

(2) systemdStart the service

  • systemctlyessystemdService 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

  • systemduse/etc/systemd/system/In the directory.serviceFile 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=
  • systemdReadunitAfter the file, you can use itsystemctlDirect management services:
systemctl daemon-reload  # Reload the configurationsystemctl restart nginx  # Restart the service

(4) systemd log management

  • systemdusejournalctlRecord 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
  • illustrateusesystemd
  • if/sbin/inityes/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 returnsystemdVersion number (such assystemd 249),illustrateusesystemd
  • ifsystemctlThe 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:

  • SysVinityesTraditional Linux boot management system,useScripts, slow startup, rely on manual management.
  • systemdyesModern Linux standardsinitsystem,supportParallel startupAutomatically manage dependencies, greatly improvedStartup speed
  • systemctlReplacedserviceandchkconfig, provide stronger management capabilities.
  • journalctlReplaces tradition/var/log/messagesLog management.

If your system is CentOS 7+ or Ubuntu 16+, you should usesystemdInsteadSysVinit。 

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.