Ubuntu启动时间非常慢 - 正在运行一个启动任务以提升网络接口

我正在运行 Ubuntu 16.04,最近几天开机需要大约5分钟。我查看了相关的问题,但是找不到如何排除故障的方法。当我运行:

systemd-analyze blame

我得到这个输出:
5min 2.242s networking.service
     21.128s vboxdrv.service
      5.637s NetworkManager-wait-online.service
      3.436s apt-daily.service
       592ms dev-sda1.device
       462ms lightdm.service
       442ms plymouth-quit-wait.service
       389ms libvirt-guests.service

所以我猜测 networking.service 是导致问题的原因。有人可以帮我修复吗?谢谢。

也许值得禁用启动画面/静默设置,以查看实际的启动过程。很可能你会在那里看到与你的网络设置相关的超时信息。 - dufte
@dufte 我禁用了启动画面/静默设置(http://askubuntu.com/questions/477821/how-can-i-permanently-remove-the-boot-option-quiet-splash),我看到以下内容:正在运行一个启动作业以提升网络接口(5分钟2秒)... - diegus
这篇帖子似乎描述了您的问题:https://ubuntuforums.org/showthread.php?t=2323253 - dufte
@dufte 看到答案了,谢谢你的帮助。 - diegus
3个回答

也许这只是一个权宜之计,但我可以按照https://ubuntuforums.org/showthread.php?t=2323253上的回答来减少启动时间,即通过编辑以下文件:
sudo vim /etc/systemd/system/network-online.targets.wants/networking.service

将文件末尾的以下行进行更改:
TimeoutStartSec=5min

给:
TimeoutStartSec=30sec

我已经重新启动了系统,现在它正常工作。
如果你不想再次重启系统,只需通过以下方式重启守护进程:
sudo systemctl daemon-reload

2这是编辑一个由软件包提供的文件,所以在升级时可能会丢失更改。请查看我的答案以获取另一种解决方案。 - Thomas

diegus的回答是有风险的,因为文件/etc/systemd/system/network-online.targets.wants/networking.service是一个指向/lib/systemd/system/networking.service的符号链接。这个文件属于ifupdown软件包,不应该被修改:在下次升级此软件包时,更改将被覆盖。
更好的方法是创建一个systemd override file

/etc/systemd/system/networking.service.d/override.conf

[Service]
TimeoutStartSec=30sec

创建这个文件最简单的方法是通过systemctl本身:
$ sudo systemctl edit networking.service

这将自动重新加载文件。使用systemctl cat networking.service来查看是否成功。

上述的解决方案对我没有帮助,因为我的USB WLAN适配器在那之后停止工作了。
但是,在Ubuntu 18.04下设置sudo nano /etc/network/interfaces
#from
auto lo br0
iface lo inet loopback

# to 
auto lo
allow-hotplug br0
iface lo inet loopback

在这里建议的情况下,帮助了:https://askubuntu.com/a/1061852/650800在按照这个教程安装KVM后,出现了启动缓慢的问题。