如何确定导致 Lubuntu 启动时间缓慢的原因是什么?

如何确定导致 Lubuntu 启动时间缓慢的原因是什么?

我不确定在 Linux 世界中什么才算是启动慢或快,但似乎我这里的 Lubuntu 机器(规格在这里),启动速度似乎有点慢(大约 50 秒)。我的父母开始向我抱怨启动速度太慢,我想我应该研究一下。

LXSession 配置向导没有显示任何会减慢启动速度的内容。它显示以下服务将在计算机启动时启动(计算机不是英文的,所以我不确定我是否翻译正确):电源管理、软件更新程序、网络服务、屏幕锁定程序、用户文件夹更新、AT-SPI D-Bus 总线。

然后我查看了一下dmesg,我认为它在行首显示了启动时间,然后发现了一些奇怪的行为:

[   21.827368] audit: type=1400 audit(1471992144.548:9): apparmor="STATUS" operation="profile_load" profile="unconfined" name="/usr/sbin/tcpdump" pid=1854 comm="apparmor_parser"
[   21.944457] audit: type=1400 audit(1471992144.668:10): apparmor="STATUS" operation="profile_load" profile="unconfined" name="/usr/bin/evince" pid=1850 comm="apparmor_parser"
[   21.944478] audit: type=1400 audit(1471992144.668:11): apparmor="STATUS" operation="profile_load" profile="unconfined" name="/usr/bin/evince//sanitized_helper" pid=1850 comm="apparmor_parser"
[   32.425176] IPv6: ADDRCONF(NETDEV_UP): enp0s25: link is not ready
[   32.892255] IPv6: ADDRCONF(NETDEV_UP): enp0s25: link is not ready
[   34.236909] e1000e: enp0s25 NIC Link is Up 100 Mbps Full Duplex, Flow Control: Rx/Tx
[   34.237022] e1000e 0000:00:19.0 enp0s25: 10/100 speed: disabling TSO
[   34.237060] IPv6: ADDRCONF(NETDEV_CHANGE): enp0s25: link becomes ready
[   42.868183] ata1.00: configured for UDMA/100
[   42.868192] ata1: EH complete

因此,不知为何,在第 21 秒它就挂起了,并开始加载与我无关的 IPv6 服务。这可能是启动缓慢的原因吗?如果是,我该如何排除故障?

我已经在 Google 上搜索了一段时间,但并没有找到对我有帮助的好建议。我尝试过的方法都没有解决问题。

如果有人能帮助我调查导致这台 Lubuntu 机器启动缓慢的原因,我将不胜感激。

谢谢!

编辑:一位用户致电波江座建议我看一下一个名为systemd-分析,这也许能帮助我发现是什么拖慢了启动时间。
下面是命令的输出systemd-analyze plot > ~/Desktop/systemd.html下载链接(找不到更好的方法来分享)。

Arch Linux 博客中建议的另一个命令是systemd-analyze critical-chain,其输出如下:

~$ systemd-analyze critical-chain
The time after the unit is active or started is printed after the "@" character.
The time the unit takes to start is printed after the "+" character.

graphical.target @38.425s
└─multi-user.target @38.425s
  └─teamviewerd.service @36.611s +1.812s (displayed in red color)
    └─network-online.target @36.598s
      └─NetworkManager-wait-online.service @24.297s +12.301s (displayed in red color)
        └─NetworkManager.service @19.493s +4.785s (displayed in red color)
          └─dbus.service @15.022s
            └─basic.target @14.901s
              └─paths.target @14.901s
                └─systemd-networkd-resolvconf-update.path @14.901s
                  └─sysinit.target @14.869s
                    └─apparmor.service @6.651s +8.167s (displayed in red color)
                      └─local-fs.target @6.646s
                        └─run-user-1000.mount @34.907s
                          └─local-fs-pre.target @6.646s
                            └─systemd-remount-fs.service @6.533s +100ms (displayed in red color)
                              └─system.slice @1.934s
                                └─-.slice @1.851s

NetworkManager 和 apparmor.service 似乎需要花费相当多的时间才能加载。我可以调整一些东西来让它们加载得更快吗?

再说,考虑到我的规格,44 秒是否是比较好的启动时间?我能否使用一些更轻量级的发行版将其缩短一点(再说,我也不想失去那么多可用性,因为这是我父母的电脑,当前的 Lubuntu GUI 已经足够好了,我可能也会尝试 Xubuntu)。

谢谢您的帮助。

编辑2:显然该disable命令实际上并没有禁用NetworkManager-wait-online.service,所以我使用了以下命令:

systemctl disable NetworkManager-wait-online.service  
systemctl mask NetworkManager-wait-online.service

并将系统启动时间从这个:Startup finished in 5.647s (kernel) + 38.452s (userspace) = 44.100s改为这个:Startup finished in 5.487s (kernel) + 26.994s (userspace) = 32.481s。虽然从心理学角度来看,这似乎并没有快 12 秒,但如果数字表明了这一点,那么我也没什么可争论的。

现在我们有了apparmor.service左边的内容,加载大约需要 10 秒。以下是更新后的命令systemd-analyze critical-chain

:~$ systemd-analyze critical-chain
The time after the unit is active or started is printed after the "@" character.
The time the unit takes to start is printed after the "+" character.

graphical.target @26.958s
└─multi-user.target @26.958s
  └─ntp.service @26.590s +368ms (displayed in red)
    └─network-online.target @26.569s
      └─network.target @26.569s
        └─NetworkManager.service @23.537s +3.032s (displayed in red)
          └─dbus.service @16.973s
            └─basic.target @16.896s
              └─sockets.target @16.896s
                └─pcscd.socket @16.896s
                  └─sysinit.target @16.895s
                    └─apparmor.service @6.518s +10.348s (displayed in red)
                      └─local-fs.target @6.513s
                        └─local-fs-pre.target @6.456s
                          └─systemd-remount-fs.service @6.353s +88ms (displayed in red)
                            └─systemd-journald.socket @1.901s
                              └─-.mount @1.826s
                                └─system.slice @1.901s
                                  └─-.slice @1.826s

输出如下systemd-analyze blame | head

:~$ systemd-analyze blame | head
         10.348s apparmor.service
          9.634s dev-sda1.device
          7.510s ModemManager.service
          7.449s grub-common.service
          6.908s networking.service
          6.898s apport.service
          6.879s irqbalance.service
          6.791s systemd-logind.service
          6.724s ondemand.service
          6.595s alsa-restore.service

乐于助人的用户,波江座,要求输出两个命令,这可能有助于我解决 apparmor.service 运行缓慢的问题,它们如下:

~$ systemctl status apparmor
● apparmor.service - LSB: AppArmor initialization
   Loaded: loaded (/etc/init.d/apparmor; bad; vendor preset: enabled)
   Active: active (exited) since P 2016-08-28 20:00:10 EEST; 31min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 785 ExecStart=/etc/init.d/apparmor start (code=exited, status=0/SUCCESS)

    aug   28 19:59:59 dc7800 systemd[1]: Starting LSB: AppArmor initialization...
    aug   28 20:00:08 dc7800 apparmor[785]:  * Starting AppArmor profiles
    aug   28 20:00:09 dc7800 apparmor[785]: Skipping profile in /etc/apparmor.d/disable: usr.bin.firefox
    aug   28 20:00:09 dc7800 apparmor[785]: Skipping profile in /etc/apparmor.d/disable: usr.sbin.rsyslogd
    aug   28 20:00:10 dc7800 apparmor[785]:    ...done.
    aug   28 20:00:10 dc7800 systemd[1]: Started LSB: AppArmor initialization.

还有一个:

:~$ journalctl |grep apparmor
aug   28 20:00:08 dc7800 apparmor[785]:  * Starting AppArmor profiles
aug   28 20:00:09 dc7800 audit[1849]: AVC apparmor="STATUS" operation="profile_load" profile="unconfined" name="/sbin/dhclient" pid=1849 comm="apparmor_parser"
aug   28 20:00:09 dc7800 audit[1849]: AVC apparmor="STATUS" operation="profile_load" profile="unconfined" name="/usr/lib/NetworkManager/nm-dhcp-client.action" pid=1849 comm="apparmor_parser"
aug   28 20:00:09 dc7800 audit[1849]: AVC apparmor="STATUS" operation="profile_load" profile="unconfined" name="/usr/lib/NetworkManager/nm-dhcp-helper" pid=1849 comm="apparmor_parser"
aug   28 20:00:09 dc7800 audit[1849]: AVC apparmor="STATUS" operation="profile_load" profile="unconfined" name="/usr/lib/connman/scripts/dhclient-script" pid=1849 comm="apparmor_parser"
aug   28 20:00:09 dc7800 kernel: audit: type=1400 audit(1472403609.772:2): apparmor="STATUS" operation="profile_load" profile="unconfined" name="/sbin/dhclient" pid=1849 comm="apparmor_parser"
aug   28 20:00:09 dc7800 kernel: audit: type=1400 audit(1472403609.772:3): apparmor="STATUS" operation="profile_load" profile="unconfined" name="/usr/lib/NetworkManager/nm-dhcp-client.action" pid=1849 comm="apparmor_parser"
aug   28 20:00:09 dc7800 kernel: audit: type=1400 audit(1472403609.772:4): apparmor="STATUS" operation="profile_load" profile="unconfined" name="/usr/lib/NetworkManager/nm-dhcp-helper" pid=1849 comm="apparmor_parser"
aug   28 20:00:09 dc7800 kernel: audit: type=1400 audit(1472403609.772:5): apparmor="STATUS" operation="profile_load" profile="unconfined" name="/usr/lib/connman/scripts/dhclient-script" pid=1849 comm="apparmor_parser"
aug   28 20:00:09 dc7800 audit[1848]: AVC apparmor="STATUS" operation="profile_load" profile="unconfined" name="/usr/lib/lightdm/lightdm-guest-session" pid=1848 comm="apparmor_parser"
aug   28 20:00:09 dc7800 audit[1848]: AVC apparmor="STATUS" operation="profile_load" profile="unconfined" name="/usr/lib/lightdm/lightdm-guest-session//chromium" pid=1848 comm="apparmor_parser"
aug   28 20:00:09 dc7800 apparmor[785]: Skipping profile in /etc/apparmor.d/disable: usr.bin.firefox
aug   28 20:00:09 dc7800 kernel: audit: type=1400 audit(1472403609.852:6): apparmor="STATUS" operation="profile_load" profile="unconfined" name="/usr/lib/lightdm/lightdm-guest-session" pid=1848 comm="apparmor_parser"
aug   28 20:00:09 dc7800 kernel: audit: type=1400 audit(1472403609.852:7): apparmor="STATUS" operation="profile_load" profile="unconfined" name="/usr/lib/lightdm/lightdm-guest-session//chromium" pid=1848 comm="apparmor_parser"
aug   28 20:00:09 dc7800 audit[1852]: AVC apparmor="STATUS" operation="profile_load" profile="unconfined" name="/usr/sbin/ntpd" pid=1852 comm="apparmor_parser"
aug   28 20:00:09 dc7800 apparmor[785]: Skipping profile in /etc/apparmor.d/disable: usr.sbin.rsyslogd
aug   28 20:00:09 dc7800 kernel: audit: type=1400 audit(1472403609.920:8): apparmor="STATUS" operation="profile_load" profile="unconfined" name="/usr/sbin/ntpd" pid=1852 comm="apparmor_parser"
aug   28 20:00:09 dc7800 audit[1854]: AVC apparmor="STATUS" operation="profile_load" profile="unconfined" name="/usr/sbin/tcpdump" pid=1854 comm="apparmor_parser"
aug   28 20:00:10 dc7800 kernel: audit: type=1400 audit(1472403609.996:9): apparmor="STATUS" operation="profile_load" profile="unconfined" name="/usr/sbin/tcpdump" pid=1854 comm="apparmor_parser"
aug   28 20:00:10 dc7800 audit[1850]: AVC apparmor="STATUS" operation="profile_load" profile="unconfined" name="/usr/bin/evince" pid=1850 comm="apparmor_parser"
aug   28 20:00:10 dc7800 audit[1850]: AVC apparmor="STATUS" operation="profile_load" profile="unconfined" name="/usr/bin/evince//sanitized_helper" pid=1850 comm="apparmor_parser"
aug   28 20:00:10 dc7800 audit[1850]: AVC apparmor="STATUS" operation="profile_load" profile="unconfined" name="/usr/bin/evince-previewer" pid=1850 comm="apparmor_parser"
aug   28 20:00:10 dc7800 audit[1850]: AVC apparmor="STATUS" operation="profile_load" profile="unconfined" name="/usr/bin/evince-previewer//sanitized_helper" pid=1850 comm="apparmor_parser"
aug   28 20:00:10 dc7800 audit[1850]: AVC apparmor="STATUS" operation="profile_load" profile="unconfined" name="/usr/bin/evince-thumbnailer" pid=1850 comm="apparmor_parser"
aug   28 20:00:10 dc7800 audit[1850]: AVC apparmor="STATUS" operation="profile_load" profile="unconfined" name="/usr/bin/evince-thumbnailer//sanitized_helper" pid=1850 comm="apparmor_parser"
aug   28 20:00:10 dc7800 kernel: audit: type=1400 audit(1472403610.068:10): apparmor="STATUS" operation="profile_load" profile="unconfined" name="/usr/bin/evince" pid=1850 comm="apparmor_parser"
aug   28 20:00:10 dc7800 kernel: audit: type=1400 audit(1472403610.072:11): apparmor="STATUS" operation="profile_load" profile="unconfined" name="/usr/bin/evince//sanitized_helper" pid=1850 comm="apparmor_parser"
aug   28 20:00:10 dc7800 apparmor[785]:    ...done.

我也在尝试用谷歌搜索,但我也希望得到这里的好想法 :) 感谢大家的帮助,尤其是波江座

答案1

好吧,从几个方面来说明一下,我有一个相对较快的系统(使用 Ubuntu),它启动大约需要 8 秒(i7 @ 3.6GHz、16GB Ram @ 1866MHz 和一个包含根分区的 M.2 驱动器)。

桌面规格看起来相对较低(1.8 GHz、1 GB Ram @ 667MHz、3GBps 的硬盘速度低于平均水平)。使用此系统,您不会获得出色的加载时间。现在 lubuntu 比 Ubuntu 更轻量,所以它应该会有所帮助,但启动时仍然需要相当多的加载。

从检查来看,内存可能是一个瓶颈,这与硬盘的速度有关。我猜想您的硬盘访问指示灯在 T: 21 秒时会频繁闪烁?

不过,你似乎认为它并不总是这么慢。你添加的服务越多,加载时间就越慢。尤其是,如果你的硬盘已满,那么寻找和查找信息将需要更多时间。

虽然这并不能真正解决您的问题,但它有助于从正确的角度看待问题并显示出加载时的一些潜在问题。

相关内容