刚接触 Linux 和 Ubuntu。我分享了我的笔记本电脑信息。启动时间太慢了。甚至启动 Firefox 也要花很长时间。
有人能帮我弄清楚如何优化我的系统吗?
使用 Lubuntu(Ubuntu 版本)
命令
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.2 LTS
Release: 18.04
Codename: bionic
命令
$ sudo lshw -short
H/W path Device Class Description
======================================================
system Aspire A515-51G (0000000000000000)
/0 bus Charmander_KL
/0/0 memory 128KiB BIOS
/0/4 processor Intel(R) Core(TM) i5-8250U CPU @ 1.60
/0/4/5 memory 256KiB L1 cache
/0/4/6 memory 1MiB L2 cache
/0/4/7 memory 6MiB L3 cache
/0/d memory 4GiB System Memory
/0/d/0 memory 4GiB SODIMM DDR4 Synchronous Unbuffer
/0/d/1 memory [empty]
/0/100 bridge Xeon E3-1200 v6/7th Gen Core Processo
/0/100/2 display UHD Graphics 620
/0/100/14 bus Sunrise Point-LP USB 3.0 xHCI Control
/0/100/14/0 usb1 bus xHCI Host Controller
/0/100/14/0/5 communication Bluetooth wireless interface
/0/100/14/0/7 multimedia HD WebCam
/0/100/14/1 usb2 bus xHCI Host Controller
/0/100/15 generic Sunrise Point-LP Serial IO I2C Contro
/0/100/15.1 generic Sunrise Point-LP Serial IO I2C Contro
/0/100/16 communication Sunrise Point-LP CSME HECI #1
/0/100/17 storage Sunrise Point-LP SATA Controller [AHC
/0/100/1c bridge Sunrise Point-LP PCI Express Root Por
/0/100/1c/0 display GP108M [GeForce MX150]
/0/100/1c.4 bridge Sunrise Point-LP PCI Express Root Por
/0/100/1c.4/0 generic RTL8411B PCI Express Card Reader
/0/100/1c.4/0.1 enp2s0f1 network RTL8111/8168/8411 PCI Express Gigabit
/0/100/1c.5 bridge Sunrise Point-LP PCI Express Root Por
/0/100/1c.5/0 wlp3s0 network Dual Band Wireless-AC 3168NGW [Stone
/0/100/1f bridge Intel(R) 100 Series Chipset Family LP
/0/100/1f.2 memory Memory controller
/0/100/1f.3 multimedia Sunrise Point-LP HD Audio
/0/100/1f.4 bus Sunrise Point-LP SMBus
/0/1 scsi0 storage
/0/1/0.0.0 /dev/sda disk 1TB WDC WD10SPZX-21Z
/0/1/0.0.0/1 /dev/sda1 volume 927GiB EXT4 volume
/0/1/0.0.0/2 /dev/sda2 volume 3970MiB Extended partition
/0/1/0.0.0/2/5 /dev/sda5 volume 3970MiB Linux swap volume
使用了这个命令
$ 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 @1min 6.870s
└─multi-user.target @1min 6.870s
└─kerneloops.service @1min 6.842s +26ms
└─network-online.target @1min 6.836s
└─NetworkManager-wait-online.service @58.305s +8.529s
└─NetworkManager.service @48.794s +9.507s
└─dbus.service @48.775s
└─basic.target @48.690s
└─sockets.target @48.690s
└─snapd.socket @48.620s +69ms
└─sysinit.target @48.618s
└─systemd-timesyncd.service @48.458s +159ms
└─systemd-tmpfiles-setup.service @47.215s +1.185s
└─systemd-journal-flush.service @5.764s +41.448s
└─systemd-remount-fs.service @4.325s +1.438s
└─systemd-journald.socket @4.229s
└─system.slice @4.229s
└─-.slice @4.170s
看到这个帖子 我们可以讨论一下 Ubuntu 18.04 的启动时间吗?
冉
$ systemd-analyze time
Startup finished in 4.907s (kernel) + 7min 8.181s (userspace) = 7min 13.089s
graphical.target reached after 1min 6.870s in userspace
冉
$ service --status-all | grep '+' | wc -l
27
答案1
此外cmak.fr
我调查了systemd-journal-flush.service 有什么用途?
sudo nano /etc/systemd/journald.conf
在日志部分取消注释并修改:
Storage=auto
SystemMaxFileSize=1G
SystemMaxFiles=5
保存并重新启动。
keyboard-setup.service 启动时间过长(20+秒)
sudo gedit /lib/systemd/system/keyboard-setup.service
已更改
TimeoutStartSec=10sec
sudo nano /lib/systemd/system/NetworkManager-wait-online.service
将 30 改为 15
[Service]
Type=oneshot
ExecStart=/usr/bin/nm-online -s -q --timeout=30
sudo update-grub
现在
$ systemd-analyze critical-chain
graphical.target @59.292s
└─multi-user.target @59.291s
└─kerneloops.service @59.278s +12ms
└─network-online.target @59.277s
└─NetworkManager-wait-online.service @52.596s +6.681s
└─NetworkManager.service @45.820s +6.773s
└─dbus.service @45.792s
└─basic.target @45.790s
└─sockets.target @45.790s
└─snapd.socket @45.745s +44ms
└─sysinit.target @45.743s
└─swap.target @45.543s
└─dev-disk-by\x2duuid-f01c80a9\x2d4d4b\x2d4e60\x2dbeb0\x2d
└─dev-disk-by\x2duuid-f01c80a9\x2d4d4b\x2d4e60\x2dbeb0\x
和
$ systemd-analyze time
Startup finished in 4.770s (kernel) + 59.301s (userspace) = 1min 4.072s
graphical.target reached after 59.292s in userspace
从7min 13.089s
一个1min 4.072s
巨大的进步,如果有人有我不知道的更多改进,请分享。
答案2
1. 日志大小限制
systemd-journal-flush.service
可以通过日志大小限制来调整耗时。
编辑日志配置文件
sudo nano /etc/systemd/journald.conf
# uncomment and configure the value
SystemMaxUse=50M
# personnaly i use 2M ;)
# Then restart the journald service
sudo systemctl restart systemd-journald
1.1 日志清理
sudo journalctl --rotate
sudo journalctl --vacuum-time=1s
供参考,日志大小由以下命令给出:
journalctl --disk-usage
2. 启动应用程序
加快用户空间加载延迟的另一个步骤是禁用一些启动应用程序
查看如何显示所有这些应用程序:https://help.ubuntu.com/community/ShowHiddenStartupApplications
sudo sed -i "s/NoDisplay=true/NoDisplay=false/g" /etc/xdg/autostart/*.desktop
了解如何打开启动应用程序小程序:https://help.ubuntu.com/stable/ubuntu-help/startup-applications.html
gnome-session-properties
答案3
以下是我对这个小事的贡献展示与讲述:
$ 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 @2.490s
└─multi-user.target @2.489s
└─snapd.service @1min 34.450s +153ms
└─basic.target @2.227s
└─sockets.target @2.226s
└─snapd.socket @2.205s +13ms
└─sysinit.target @2.197s
└─systemd-update-utmp.service @2.136s +54ms
└─systemd-tmpfiles-setup.service @2.116s +9ms
└─local-fs.target @2.108s
└─run-user-1000-gvfs.mount @1min 26.644s
└─run-user-1000.mount @1min 25.977s
└─local-fs-pre.target @192ms
└─systemd-remount-fs.service @172ms +10ms
└─systemd-fsck-root.service @110ms +39ms
└─systemd-fsckd.socket @109ms
└─-.slice @81ms
比较一下2.49 秒到SDC 的答案的59.29 秒它有一些额外的耗时功能,我已经从启动时删除了它们:
└─kerneloops.service @59.278s +12ms
└─network-online.target @59.277s
└─NetworkManager-wait-online.service @52.596s +6.681s
└─NetworkManager.service @45.820s +6.773s
└─dbus.service @45.792s
└─snapd.socket @45.745s +44ms
└─swap.target @45.543s
└─dev-disk-by\x2duuid-f01c80a9\x2d4d4b\x2d4e60\x2dbeb0\x2d
└─dev-disk-by\x2duuid-f01c80a9\x2d4d4b\x2d4e60\x2dbeb0\x
主要特征:
- 删除网络管理器等待从启动开始。
- 删除 snapd 刷新服务从启动开始。
Systemd 日志控制增强功能
$ cat /etc/systemd/journald.conf
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See journald.conf(5) for details.
[Journal]
#Storage=auto
# Aug 4 2018 - recommended: https://www.freedesktop.org/software/systemd/man/journald.conf.html
storage=persistent
值得注意的细节是大胆的。
因为journalctl
文件在启动时不再刷新,所以我将它们设置为真空吸尘每月一次:
我经常想知道系统崩溃后需要重启时发生了什么。默认情况下,journalctl
文件不会显示之前的启动记录。因此我打开了多重启动历史记录:
今天就到这里。我会尽量记得更新这个答案。