启动时间过长

启动时间过长

我的笔记本电脑上安装了 Ubuntu 22.04.2 LTS。启动需要 2 分钟以上的时间,这对我来说太长了。几个月前,我在电脑上安装 Ubuntu 时,并没有花这么多时间。以下是“systemd-analyze”和“system-analyze blame”分别生成的日志

isaac@Isaac-Lenovo-IdeaPad-S145-15AST:~$ systemd-analyze 

Startup finished in 4.979s (firmware) + 8.472s (loader) + 4.847s (kernel) + 1min 59.732s (userspace) = 2min 18.032s graphical.target reached after 1min 59.606s in userspace

isaac@Isaac-Lenovo-IdeaPad-S145-15AST:~$ systemd-analyze blame

1min 22.046s fstrim.service

 57.290s plymouth-quit-wait.service
 37.756s systemd-journal-flush.service
 33.487s dev-mapper-vgubuntu\x2droot.device
 31.672s apt-daily.service
 26.775s snapd.service
 23.608s logrotate.service
 21.060s networkd-dispatcher.service
 20.841s snap-bare-5.mount
 19.967s snap-core18-2714.mount
 19.579s NetworkManager-wait-online.service
 19.316s snap-core18-2721.mount
 18.666s udisks2.service
 18.013s snap-core20-1778.mount
 16.502s snap-core20-1852.mount
 13.452s snap-core22-583.mount
 13.435s ModemManager.service
 13.344s accounts-daemon.service
 13.160s dev-loop28.device
 13.022s dev-loop19.device
 12.719s dev-loop18.device
 12.715s dev-loop23.device
 12.713s dev-loop26.device

以下是我的规格

CPU : AMD® A6-9225 radeon r4, 5 compute cores 2c+3g × 2
GPU : No external. iGPU (STONEY (stoney, LLVM 15.0.6, DRM 3.42, 5.15.0-69-generic))
HDD : 1TB
RAM : 4GB 
OS  : Ubuntu 22.04.2 LTS (64 bit)
SSD : No SSD

那么这个问题有解决办法吗?我的系统有故障吗?还是我只需要升级硬件……?

[已解决] 感谢@Archisman Panigrahi,我能够删除所有 snap 应用程序和 snap 本身,这显著缩短了我的启动时间。以下是删除 snap 后的日志

isaac@Isaac-Lenovo-IdeaPad-S145-15AST:~$ systemd-analyze

Startup finished in 5.810s (firmware) + 5.990s (loader) + 5.145s (kernel) + 1min 35.600s (userspace) = 1min 52.547s
graphical.target reached after 1min 35.524s in userspace

isaac@Isaac-Lenovo-IdeaPad-S145-15AST:~$ systemd-analyze blame

49.362s plymouth-quit-wait.service
31.030s systemd-journal-flush.service
23.653s dev-mapper-vgubuntu\x2droot.device
17.721s systemd-udevd.service
16.684s networkd-dispatcher.service
15.613s NetworkManager-wait-online.service
13.481s udisks2.service
10.818s accounts-daemon.service
 8.654s ModemManager.service
 7.616s power-profiles-daemon.service
 7.567s polkit.service
 7.249s cups.service
 7.019s gdm.service
 6.680s NetworkManager.service
 6.674s bluetooth.service
 6.170s switcheroo-control.service
 6.134s thermald.service
 6.133s systemd-logind.service
 5.845s wpa_supplicant.service
 4.695s systemd-resolved.service
 3.518s rsyslog.service
 3.078s apparmor.service
 2.785s e2scrub_reap.service

答案1

日志显示 snap 事件在启动时需要花费大量时间。我本人也曾在装有 HDD 的旧电脑中遇到过这个问题,删除 snap 后启动速度显著提高。将所有 snap 应用替换为 apt 应用,然后卸载 snapd。

这里如果你使用 Firefox,那么如何替换 Firefox snap?这里是如何彻底删除 snapd。


您也可以禁用apt-daily.service(然后您将必须定期手动检查更新,并保持系统更新)。

sudo systemctl disable apt-daily.service

此外,systemd-journal-flush.service这需要花费大量时间。因此,清除 systemd 日志可以进一步加快启动过程。

sudo journalctl --flush --rotate
sudo journalctl --vacuum-size=20M

您还可以安全地禁用NetworkManager-wait-online.service

sudo systemctl disable NetworkManager-wait-online.service

相关内容