Thời lượng ước tính: 40 phút.
Phân tích quá trình khởi động Linux: đo thời gian boot và xác định service làm chậm boot bằng systemd-analyze (blame / critical-chain / --failed),
giải thích 5 tầng boot (firmware → GRUB → kernel → initramfs → systemd) và đề xuất cách khắc phục boot chậm.
Địa chỉ IP trong bài là địa chỉ minh hoạ thuộc dải dành cho tài liệu (RFC 5737): dattqh-nat = 192.0.2.21, dattqh-client = 192.0.2.22; khi làm, thay bằng IP thật của máy bạn.
Quy trình chuẩn tìm boot chậm là systemd-analyze → blame → critical-chain → --failed (systemd-analyze(1)).
# Trên dattqh-nat (192.0.2.21)
systemd-analyze
systemd-analyze blame | head -10
systemd-analyze critical-chain | head -20
systemctl --failed
sudo journalctl -b -u systemd-networkd-wait-online --no-pager | tail
Ghi chú: Quan sát:
systemd-analyze → 4.065s (kernel) + 2min 2.993s (userspace). blame top = 2min 131ms systemd-networkd-wait-online.service. systemctl --failed liệt kê unit này FAILED. journal:
Timeout occurred while waiting for network connectivity.
Cùng image, VM dattqh-client boot trong 8.9s.
# Trên dattqh-client (192.0.2.22)
systemd-analyze
systemd-analyze blame | head -6
systemctl --failed
sudo journalctl -b -u systemd-networkd-wait-online --no-pager | tail -3
Ghi chú: Quan sát: systemd-analyze → 4.322s + 4.663s = 8.985s. blame: 1.140s systemd-networkd-wait-online.service (xong nhanh). systemctl --failed trống. journal: Finished systemd-networkd-wait-online.service (~1s, không timeout).
Hiểu boot không chỉ là đo thời gian mà còn đọc được hiện trạng từng tầng: kernel cmdline, GRUB, initramfs, default.target.
# Trên 171 — đọc từng tầng (read-only)
cat /proc/cmdline
ps -p 1 -o pid,comm
findmnt /
lsinitramfs /boot/initrd.img-$(uname -r) | grep -iE 'lvm|virtio' | head
systemctl get-default
# CÁCH FIX wait-online (tham khảo — không chạy trên VM lab):
# sudo nano /etc/netplan/50-cloud-init.yaml -> thêm 'optional: true' dưới ens160
# sudo netplan try && sudo netplan apply
# hoặc bỏ 'dhcp4: true' nếu chỉ dùng static.
Ghi chú: Quan sát: cat /proc/cmdline → BOOT_IMAGE=/vmlinuz-6.8.0-31-generic root=/dev/mapper/ubuntu--vg-ubuntu--lv ro. ps -p 1 → 1 systemd. findmnt / → root trên /dev/mapper/ubuntu--vg-ubuntu--lv. systemctl get-default → graphical.target.
systemd-analyze: userspace 2 phút; blame đứng đầu = systemd-networkd-wait-online.
systemctl --failed + journal: wait-online timeout 120s → status=1/FAILURE.
Cùng image: boot 9s, wait-online xong 1.1s, không unit nào FAILED → thủ phạm là service treo, không phải phần cứng.