Ubuntu 20.04 启动时间过长

Ubuntu 20.04 启动时间过长

ubuntu 启动需要 1 分 25 秒,以下是 systemd-analyze critical-chain 日志

graphical.target @1min 20.643s
└─multi-user.target @1min 20.643s
  └─snapd.seeded.service @1min 10.553s +37ms
    └─snapd.service @38.570s +31.978s
      └─basic.target @37.598s
        └─sockets.target @37.598s
          └─snapd.socket @37.595s +2ms
            └─sysinit.target @37.433s
              └─snapd.apparmor.service @36.725s +706ms
                └─apparmor.service @34.732s +1.989s
                  └─local-fs.target @34.729s
                    └─boot-efi.mount @34.644s +84ms
                      └─systemd-fsck@dev-disk-by\x2duuid-9CF8\x2dBDA7.service @>
                        └─dev-disk-by\x2duuid-9CF8\x2dBDA7.device @32.121s

systemd-analyze 责备日志看起来像这样

32.976s plymouth-quit-wait.service                                             >
31.978s snapd.service                                                          >
28.705s udisks2.service                                                        >
26.038s dev-sda8.device                                                        >
13.347s accounts-daemon.service                                                >
12.292s NetworkManager-wait-online.service                                     >
11.534s dev-loop7.device                                                       >
11.211s dev-loop8.device                                                       >
10.921s dev-loop3.device                                                       >
10.733s dev-loop2.device                                                       >
10.451s dev-loop5.device                                                       >
 9.934s dev-loop9.device                                                       >
 9.686s dev-loop4.device                                                       >
 9.532s NetworkManager.service                                                 >
 9.332s avahi-daemon.service                                                   >
 9.326s bluetooth.service                                                      >
 9.326s dev-loop0.device                                                       >
 9.057s dev-loop6.device                                                       >
 8.898s polkit.service                                                         >
 8.468s switcheroo-control.service                                             >
 8.451s thermald.service                                                       >
 8.447s systemd-logind.service                                                 >
 8.232s wpa_supplicant.service                                                 >
 8.027s dev-loop1.device                                                       >
 6.343s systemd-resolved.service                                               >
 5.664s systemd-udevd.service                                                  >
 4.572s gpu-manager.service                                                    >
 4.227s mono-xsp4.service                                                      >
 4.138s apport.service                                                         >
 4.019s ModemManager.service                                                   >
 3.765s secureboot-db.service                                                  >
 3.580s gdm.service                                                            >
 3.345s e2scrub_reap.service                                                   >
 3.322s rc.local.service                                                       >
 2.942s grub-common.service                                                    >
 2.495s systemd-fsck@dev-disk-by\x2duuid-9CF8\x2dBDA7.service                  >
 2.214s networking.service                                                     >
 2.060s systemd-modules-load.service                                           >
 1.989s apparmor.service                                                       >
 1.693s systemd-tmpfiles-setup-dev.service                                     >
 1.663s keyboard-setup.service                                                 >
 1.609s systemd-sysusers.service                                               >
 1.599s grub-initrd-fallback.service                                           >
 1.303s lm-sensors.service                                                     >
 1.263s rsyslog.service                                                        >
 1.203s plymouth-start.service                                                 >
 1.136s [email protected]                                                   >
 1.098s systemd-random-seed.service                                            >
 1.048s resolvconf-pull-resolved.service                                       >
 1.028s systemd-udev-trigger.service                                           >
 1.016s systemd-sysctl.service                                                 >
  855ms systemd-tmpfiles-setup.service                                         >
  792ms ufw.service                                                            >
  706ms snapd.apparmor.service                                                 >
  698ms snap-core18-2074.mount                                                 >
  695ms snap-wine\x2dplatform\x2d6\x2dstable-5.mount                           >
  642ms snap-wine\x2dplatform\x2d6\x2dstable-8.mount                           >
  641ms dns-clean.service                                                      >
  634ms binfmt-support.service                                                 >
  611ms snap-wine\x2dplatform\x2druntime-240.mount                             >
  592ms snap-snapd-12704.mount                                                 >
  557ms pppd-dns.service                                                       >
  542ms kerneloops.service                                                     >
  522ms snap-snapd-12883.mount                                                 >
  506ms systemd-backlight@backlight:intel_backlight.service                    >
  497ms ifupdown-pre.service                                                   >
  459ms hddtemp.service                                                        >
  401ms snap-wine\x2dplatform\x2druntime-239.mount                             >
  400ms snap-core18-2128.mount                                                 >
  396ms openvpn.service                                                        >
  375ms systemd-timesyncd.service                                              >
  352ms dev-hugepages.mount                                                    >
  351ms dev-mqueue.mount                                                       >
  351ms sys-kernel-debug.mount                                                 >
  350ms sys-kernel-tracing.mount                                               >
  348ms systemd-journald.service                                               >
  348ms kmod-static-nodes.service                                              >
  336ms console-setup.service                                                  >
  316ms systemd-remount-fs.service                                             >
  303ms packagekit.service                                                     >
  282ms upower.service                                                         >
  269ms snap-gtk\x2dcommon\x2dthemes-1515.mount                                >
  252ms tlp.service                                                            >
  210ms snap-gnome\x2d3\x2d28\x2d1804-161.mount                                >
  200ms plymouth-read-write.service                                            >
  188ms [email protected]                                                      >
  179ms systemd-update-utmp.service                                            >
  172ms dev-disk-by\x2duuid-fd7235f1\x2d1d46\x2d4b9e\x2da017\x2dd9d72c3566b2.sw>
  130ms proc-sys-fs-binfmt_misc.mount                                          >
   94ms systemd-user-sessions.service                                          >
   84ms boot-efi.mount                                                         >
   76ms colord.service                                                         >
   54ms systemd-journal-flush.service                                          >
   52ms setvtrgb.service                                                       >
   37ms snapd.seeded.service                                                   >
   34ms [email protected]                                          >
   32ms systemd-update-utmp-runlevel.service                                   >
   14ms alsa-restore.service                                                   >
   13ms ureadahead-stop.service                                                >
   10ms rtkit-daemon.service                                                   >
    2ms sys-fs-fuse-connections.mount                                          >
    2ms snapd.socket                                                           >
    1ms sys-kernel-config.mount                                                >

编辑 1
禁用 NetworkManager-wait-online.service 和 snapd.service 后,
systemd-analyze critical-chain 日志看起来像

graphical.target @1min 19.553s
└─multi-user.target @1min 19.553s
  └─snapd.seeded.service @37.019s +32.434s
    └─snapd.service @37.813s +31.624s
      └─basic.target @36.069s
        └─sockets.target @36.069s
          └─snapd.socket @36.069s +554us
            └─sysinit.target @35.888s
              └─snapd.apparmor.service @34.888s +999ms
                └─apparmor.service @33.060s +1.825s
                  └─local-fs.target @33.060s
                    └─boot-efi.mount @32.970s +89ms
                      └─systemd-fsck@dev-disk-by\x2duuid-9CF8\x2dBDA7.service @>
                        └─dev-disk-by\x2duuid-9CF8\x2dBDA7.device @30.385s

systemd-analyze 指责看起来像

32.742s plymouth-quit-wait.service                                             >
32.434s snapd.seeded.service                                                   >
31.624s snapd.service                                                          >
24.802s dev-sda8.device                                                        >
22.646s udisks2.service                                                        >
13.990s accounts-daemon.service                                                >
10.964s dev-loop1.device                                                       >
10.335s NetworkManager.service                                                 >
10.306s dev-loop4.device                                                       >
10.121s dev-loop8.device                                                       >
10.065s dev-loop9.device                                                       >
10.023s dev-loop7.device                                                       >
10.012s dev-loop5.device                                                       >
 9.480s avahi-daemon.service                                                   >
 9.468s bluetooth.service                                                      >
 9.449s dev-loop0.device                                                       >
 9.095s polkit.service                                                         >
 8.814s dev-loop3.device                                                       >
 8.707s switcheroo-control.service                                             >
 8.696s thermald.service                                                       >
 8.684s systemd-logind.service                                                 >
 8.630s wpa_supplicant.service                                                 >
 8.422s dev-loop2.device                                                       >
 7.155s dev-loop6.device                                                       >
 5.716s systemd-udevd.service                                                  >
 4.381s gpu-manager.service                                                    >
 4.302s ModemManager.service                                                   >
 3.050s mono-xsp4.service                                                      >
 3.026s secureboot-db.service                                                  >
 2.992s systemd-resolved.service                                               >
 2.970s apport.service                                                         >
 2.861s e2scrub_reap.service                                                   >
 2.761s rsyslog.service                                                        >
 2.610s resolvconf-pull-resolved.service                                       >
 2.546s systemd-fsck@dev-disk-by\x2duuid-9CF8\x2dBDA7.service                  >
 2.464s grub-common.service                                                    >
 2.204s networking.service                                                     >
 2.076s plymouth-start.service                                                 >
 1.915s systemd-modules-load.service                                           >
 1.825s apparmor.service                                                       >
 1.781s gdm.service                                                            >
 1.679s systemd-tmpfiles-setup-dev.service                                     >
 1.668s systemd-sysusers.service                                               >
 1.500s lm-sensors.service                                                     >
 1.407s snap-gnome\x2d3\x2d28\x2d1804-161.mount                                >
 1.283s grub-initrd-fallback.service                                           >
 1.205s snap-wine\x2dplatform\x2d6\x2dstable-5.mount                           >
 1.170s rc.local.service                                                       >
 1.059s keyboard-setup.service                                                 >
 1.058s [email protected]                                                   >
 1.046s systemd-sysctl.service                                                 >
 1.031s snap-gtk\x2dcommon\x2dthemes-1515.mount                                >
  999ms snapd.apparmor.service                                                 >
  952ms snap-core18-2074.mount                                                 >
  923ms snap-snapd-12883.mount                                                 >
  869ms snap-wine\x2dplatform\x2druntime-239.mount                             >
  837ms systemd-random-seed.service                                            >
  805ms binfmt-support.service                                                 >
  799ms pppd-dns.service                                                       >
  790ms systemd-tmpfiles-setup.service                                         >
  646ms systemd-udev-trigger.service                                           >
  601ms snap-snapd-12704.mount                                                 >
  594ms tlp.service                                                            >
  592ms ufw.service                                                            >
  591ms hddtemp.service                                                        >
  569ms packagekit.service                                                     >
  534ms kerneloops.service                                                     >
  525ms snap-wine\x2dplatform\x2d6\x2dstable-8.mount                           >
  474ms dev-hugepages.mount                                                    >
  474ms dev-mqueue.mount                                                       >
  473ms sys-kernel-debug.mount                                                 >
  473ms sys-kernel-tracing.mount                                               >
  471ms systemd-journald.service                                               >
  470ms kmod-static-nodes.service                                              >
  408ms systemd-remount-fs.service                                             >
  405ms snap-wine\x2dplatform\x2druntime-240.mount                             >
  388ms snap-core18-2128.mount                                                 >
  378ms dev-disk-by\x2duuid-fd7235f1\x2d1d46\x2d4b9e\x2da017\x2dd9d72c3566b2.sw>
  374ms systemd-timesyncd.service                                              >
  372ms ifupdown-pre.service                                                   >
  345ms systemd-backlight@backlight:intel_backlight.service                    >
  308ms console-setup.service                                                  >
  298ms systemd-journal-flush.service                                          >
  253ms upower.service                                                         >
  197ms systemd-update-utmp.service                                            >
  186ms [email protected]                                                      >
  185ms dns-clean.service                                                      >
  178ms colord.service                                                         >
   95ms plymouth-read-write.service                                            >
   89ms boot-efi.mount                                                         >
   85ms openvpn.service                                                        >
   84ms systemd-user-sessions.service                                          >
   54ms proc-sys-fs-binfmt_misc.mount                                          >
   43ms geoclue.service                                                        >
   33ms setvtrgb.service                                                       >
   22ms realmd.service                                                         >
   21ms [email protected]                                          >
   16ms ureadahead-stop.service                                                >
   12ms alsa-restore.service                                                   >
    8ms systemd-update-utmp-runlevel.service                                   >
    5ms rtkit-daemon.service                                                   >
    2ms sys-fs-fuse-connections.mount                                          >
    2ms sys-kernel-config.mount                                                >
  554us snapd.socket                                                           >


运行此命令后编辑 2

sudo systemctl stop snapd.service and sudo systemctl mask snapd.service

日志看起来像

graphical.target @1min 16.891s
└─multi-user.target @1min 16.891s
  └─ModemManager.service @45.278s +5.350s
    └─polkit.service @38.513s +6.761s
      └─basic.target @37.579s
        └─sockets.target @37.579s
          └─uuidd.socket @37.579s
            └─sysinit.target @37.512s
              └─snapd.apparmor.service @36.546s +965ms
                └─apparmor.service @33.786s +2.759s
                  └─local-fs.target @33.785s
                    └─boot-efi.mount @33.701s +83ms
                      └─systemd-fsck@dev-disk-by\x2duuid-9CF8\x2dBDA7.service @>
                        └─dev-disk-by\x2duuid-9CF8\x2dBDA7.device @31.041s


31.507s plymouth-quit-wait.service                                             >
25.108s dev-sda8.device                                                        >
23.215s udisks2.service                                                        >
11.035s dev-loop6.device                                                       >
10.919s dev-loop7.device                                                       >
10.632s dev-loop1.device                                                       >
10.555s accounts-daemon.service                                                >
10.166s dev-loop5.device                                                       >
10.163s dev-loop4.device                                                       >
 9.656s dev-loop3.device                                                       >
 9.646s dev-loop8.device                                                       >
 9.570s dev-loop0.device                                                       >
 9.545s dev-loop9.device                                                       >
 9.411s dev-loop2.device                                                       >
 7.520s avahi-daemon.service                                                   >
 7.518s bluetooth.service                                                      >
 7.224s NetworkManager.service                                                 >
 6.761s polkit.service                                                         >
 6.657s switcheroo-control.service                                             >
 6.651s thermald.service                                                       >
 6.649s systemd-logind.service                                                 >
 6.432s wpa_supplicant.service                                                 >
 

相关内容