متقدم
البحث فيأدلة «كيف»
طريقة البحث
  • اكتب المهمة بكلماتك (find port، open firewall، disk full) أو الصق رسالة الخطأ بين علامتي تنصيص.
  • اختر «الإجابة السريعة» لترى الأوامر فقط، أو مجالًا لتبقى في مجال واحد.
  • "كلمتان" تجد العبارة بالضبط.
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث
جرّب:

كيف 98System · systemd

How to find slow services at boot

A server needs three minutes to come back after a patch reboot — that is three minutes of downtime every time. systemd-analyze shows where the boot time goes: which units are slow, and which ones are really on the critical path (others wait for them). This how-to finds the slow part and fixes the usual causes: waiting for the network, broken mounts, and services nobody needs.

  • 5 الدروس
  • 6 الأوامر

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

$ مستخدم عادي# بصلاحية root (أو مع sudo)

98.1

The quick answer

systemd-analyze
Startup finished in 1.9s (kernel) + 3.1s (initrd) + 1min 42.5s (userspace) = 1min 47.5s
systemd-analyze blame | head -10
systemd-analyze critical-chain

98.2

Step by step

  1. Total time — kernel, initrd, userspace. Userspace (the services) is usually where the minutes are.
  2. Slowest units — but careful: many start in parallel, so a slow unit is not always the problem:
systemd-analyze blame | head -10
     1min 30.022s NetworkManager-wait-online.service
          8.410s cloud-init.service
          3.201s mnt-share.mount
          2.110s dnf-makecache.service
  1. The critical chain — what the boot really waited for:
systemd-analyze critical-chain
multi-user.target @1min 42.5s
└─app.service @1min 31.2s +11.2s
  └─network-online.target @1min 31.1s
    └─NetworkManager-wait-online.service @1.1s +1min 30.0s

Here: the app waits for "network online", and that waits 90 seconds (a timeout).

  1. Fix the usual causes:
Slow unitUsual causeFix
NetworkManager-wait-onlineAn interface without link/DHCP answer (a second, unused NIC).Set the unused connection to not auto-connect; or ipv4.may-fail; fix DHCP.
*.mount / remote-fs.targetAn NFS/SMB share that is not reachable._netdev,nofail and x-systemd.mount-timeout=30, or automount.
cloud-init*Waits for a metadata service that is not there.Configure the right datasource, or disable cloud-init on non-cloud VMs.
dnf-makecache, apt-dailyPackage cache refresh at boot.Move to a timer later (often already a timer).
A service you do not useDefault installs.systemctl disable --now NAME (or mask).
  1. A picture of the whole boot (open it in a browser):
systemd-analyze plot > /tmp/boot.svg
  1. Warnings and errors of this boot — failed units also cost time:
systemctl --failed
journalctl -b -p warning --no-pager | tail -30

98.3

Check that it worked

Reboot in a maintenance window, then:

systemd-analyze
systemd-analyze critical-chain

The userspace time is much lower, no unit waits for a timeout, and systemctl --failed is empty.

98.4

Common problems

ProblemCauseFix
Bootup is not yet finishedA unit is still starting (or hangs).systemctl list-jobs; look at that unit's log.
Boot hangs with "A start job is running for …"A mount or service waits for a timeout (often 90 s).Fix the mount (nofail, timeout) or the service; DefaultTimeoutStartSec only as last resort.
Disabling a unit broke somethingAnother unit needed it.systemctl list-dependencies --reverse NAME before disabling.
Fast to boot, app still starts lateApp waits for the DB/network on its own.Proper After=/Wants= and retries in the app.
Firmware/BIOS time is longHardware checks (not Linux).systemd-analyze shows firmware on bare metal; change BIOS settings.
Kernel/initrd slowBig initramfs, disk detection, LUKS prompt.Check dmesg timing; rebuild initramfs with only needed drivers.

98.5

Go further

1Why is systemd-analyze blame alone not enough?

Units start in parallel; a slow unit only matters if others wait for it — critical-chain shows that.

2Boot waits 90 s on NetworkManager-wait-online. What is a usual cause?

An interface that never gets a link or DHCP answer (for example an unused second NIC).

كل الأوامر في هذا الفصل