为什么 Ubuntu 桌面 20.04 启动非常慢

为什么 Ubuntu 桌面 20.04 启动非常慢

我尝试调整了一些事情,比如

  • 删除/禁用服务,
  • 检查了 HDD iostat [平均读取速率~ 120 MB/s]。

一切似乎都很好。但启动仍然需要大约 3 分钟。

的输出systemd-analyze plot可以在此链接

输出systemd-analyze blame

2min 140ms plymouth-quit-wait.service
   31.766s systemd-journal-flush.service
   28.994s dev-sdb1.device
   27.573s snapd.seeded.service
   25.841s udisks2.service
   25.712s snapd.service
   24.896s networkd-dispatcher.service
   22.360s accounts-daemon.service
   16.608s dev-loop15.device
   16.508s dev-loop13.device
   15.523s dev-loop5.device
   15.307s dev-loop7.device
   15.283s dev-loop8.device
   15.229s dev-loop12.device
   14.963s dev-loop6.device
   14.900s polkit.service
   14.875s dev-loop14.device
   14.799s dev-loop0.device
   14.478s avahi-daemon.service
   14.418s NetworkManager.service
   14.074s switcheroo-control.service
   14.067s thermald.service
   14.063s wpa_supplicant.service
   14.062s systemd-logind.service
   13.809s dev-loop1.device
   13.633s dev-loop9.device
   12.690s dev-loop10.device
   12.456s dev-loop11.device
   12.424s dev-loop2.device
   11.756s dev-loop3.device
   11.460s dev-loop4.device
    9.932s ModemManager.service
    9.213s systemd-udevd.service
    8.774s NetworkManager-wait-online.service
    8.357s smartmontools.service
    7.584s ufw.service
    6.966s systemd-resolved.service
    6.229s gpu-manager.service
    6.220s grub-initrd-fallback.service
    5.772s grub-common.service
    5.518s apport.service
    5.455s apparmor.service
    5.176s lm-sensors.service
    5.144s rsyslog.service
    5.013s kexec.service
    4.749s rc.local.service
    3.761s hddtemp.service
    3.399s networking.service
    3.354s e2scrub_reap.service
    3.320s monopd.service
    3.020s sysstat.service
    2.286s snap-core-9289.mount
    2.233s snapd.apparmor.service
    1.877s systemd-sysusers.service
    1.834s binfmt-support.service
    1.650s snap-core-9436.mount
    1.608s snap-core18-1705.mount
    1.581s snap-core18-1754.mount
    1.571s gdm.service
    1.560s apt-daily.service
    1.536s snap-core20-634.mount
    1.510s inetd.service
    1.492s snap-electron\x2dmail-24.mount
    1.491s snap-electron\x2dmail-25.mount
    1.474s systemd-modules-load.service
    1.463s snap-gimp-273.mount
    1.462s snap-gimp-281.mount
    1.386s snap-gnome\x2d3\x2d34\x2d1804-36.mount
    1.284s ssh.service
    1.254s kerneloops.service
    1.208s [email protected]
    1.192s dev-disk-by\x2duuid-820bee40\x2d75ec\x2d4794\x2daf59\x2d497ba69ebbe8.swap
    1.180s systemd-timesyncd.service
    1.162s setvtrgb.service
    1.135s snap-gtk2\x2dcommon\x2dthemes-13.mount
    1.021s systemd-sysctl.service
     990ms keyboard-setup.service
     981ms upower.service
     732ms systemd-random-seed.service
     668ms [email protected]
     666ms systemd-journald.service
     607ms systemd-tmpfiles-setup-dev.service
     601ms dev-hugepages.mount
     600ms dev-mqueue.mount
     600ms sys-kernel-debug.mount
     599ms sys-kernel-tracing.mount
     523ms dns-clean.service
     510ms console-setup.service
     499ms systemd-tmpfiles-setup.service
     476ms snap-gtk2\x2dcommon\x2dthemes-9.mount
     441ms kmod-static-nodes.service
     428ms atd.service
     427ms atieventsd.service
     404ms colord.service
     396ms snap-gtk\x2dcommon\x2dthemes-1502.mount
     343ms pppd-dns.service
     297ms systemd-udev-trigger.service
     288ms [email protected]
     271ms snap-snap\x2dstore-415.mount
     243ms snap-snap\x2dstore-467.mount
     189ms snap-gtk\x2dcommon\x2dthemes-1506.mount
     173ms ifupdown-pre.service
     157ms plymouth-start.service
     144ms alsa-restore.service
     112ms systemd-remount-fs.service
      88ms openvpn.service
      78ms systemd-user-sessions.service
      55ms systemd-update-utmp.service
      53ms finalrd.service
      51ms systemd-tmpfiles-clean.service
      49ms rtkit-daemon.service
      41ms proc-sys-fs-binfmt_misc.mount
      24ms [email protected]
      19ms [email protected]
      11ms plymouth-read-write.service
      11ms systemd-update-utmp-runlevel.service
      11ms resolvconf-pull-resolved.service
      11ms kexec-load.service
       3ms sys-fs-fuse-connections.mount
       3ms sys-kernel-config.mount
     980us snapd.socket

硬件信息:

*-memory
   description: System memory
   physical id: 0
   size: 16GiB

*-cpu
   product: AMD FX(tm)-8350 Eight-Core Processor
   vendor: Advanced Micro Devices [AMD]
   physical id: 1
   bus info: cpu@0
   size: 1399MHz
   capacity: 4GHz

*-display
   description: VGA compatible controller
   product: Baffin [Radeon RX 460/560D / Pro 450/455/460/555/555X/560/560X]
   vendor: Advanced Micro Devices, Inc. [AMD/ATI]
   physical id: 0
   bus info: pci@0000:01:00.0
   version: e5
   width: 64 bits
   clock: 33MHz
   capabilities: vga_controller bus_master cap_list rom
   configuration: driver=amdgpu latency=0

输出cat /etc/default/grub

# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
#   info -f grub -n 'Simple configuration'

GRUB_DEFAULT=0
#GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="crashkernel=2G-6G:256M,6G-8G:512M,8G-:768M"
GRUB_CMDLINE_LINUX="quiet splash noresume"

# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"

# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console

# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
#GRUB_GFXMODE=640x480

# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true

# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_RECOVERY="true"

# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"

笔记: 几年前,它是全新安装的(Ubuntu LTS 12.04 或 14.04,我现在记不清了)。然后它每 2 年更新到最新的 LTS,使用sudo do-release-upgrade

最初它使用不同的硬件设置运行

  • 英特尔酷睿2双核处理器
  • 华硕主板。
  • 4 GB RAM。

然后它变成了当前设置

编辑:根据@heynnema 的要求更新。

$ free -h

              total        used        free      shared  buff/cache   available
Mem:           15Gi       763Mi        12Gi        34Mi       2.0Gi        14Gi
Swap:         3.4Gi          0B       3.4Gi

$ grep -i swap /etc/fstab

# swap was on /dev/sda4 during installation
UUID=820bee40-75ec-4794-af59-497ba69ebbe8 none            swap    sw              0       0
#/dev/sdc2: UUID="820bee40-75ec-4794-af59-497ba69ebbe8" TYPE="swap" PARTUUID="000de4b8-02"

$ sudo blkid

[sudo] password for sourav:
/dev/sdb1: UUID="6955c8fd-22d3-4b9b-8a29-f98cec0419bb" TYPE="ext4" PARTUUID="000de4b8-01"
/dev/loop0: TYPE="squashfs"
/dev/loop1: TYPE="squashfs"
/dev/loop2: TYPE="squashfs"
/dev/loop3: TYPE="squashfs"
/dev/loop4: TYPE="squashfs"
/dev/loop5: TYPE="squashfs"
/dev/loop6: TYPE="squashfs"
/dev/loop7: TYPE="squashfs"
/dev/sdd: UUID="f836547b-4a89-7446-abac-281f4559fb1e" UUID_SUB="390af95a-5039-db0b-4e20-d50b472d70cf" LABEL="ubuntu:0" TYPE="linux_raid_member"
/dev/sdb2: UUID="820bee40-75ec-4794-af59-497ba69ebbe8" TYPE="swap" PARTUUID="000de4b8-02"
/dev/sdb3: LABEL="DATA_790" UUID="201855474559DE32" TYPE="ntfs" PTTYPE="atari" PARTUUID="000de4b8-03"
/dev/sdb5: UUID="1cdafd4a-1908-4bff-be5c-6ecfe722f53b" TYPE="ext4" PARTUUID="000de4b8-05"
/dev/sdb6: UUID="C7A7-EC12" TYPE="vfat" PARTUUID="000de4b8-06"
/dev/sda: UUID="f836547b-4a89-7446-abac-281f4559fb1e" UUID_SUB="272a4d7f-bd7f-3a05-b9be-143179b4731c" LABEL="ubuntu:0" TYPE="linux_raid_member"
/dev/sdc: UUID="f836547b-4a89-7446-abac-281f4559fb1e" UUID_SUB="42ab19e9-932b-6318-c23f-2c6f7fb9e48d" LABEL="ubuntu:0" TYPE="linux_raid_member"
/dev/md127p1: LABEL="DATA_100G" UUID="258b4ae7-f26d-4648-a332-105d71998b40" TYPE="ext4" PARTUUID="7b1fc87a-01"
/dev/md127p3: LABEL="DATA_1.8T" UUID="796B821272CAD4DC" TYPE="ntfs" PTTYPE="atari" PARTUUID="7b1fc87a-03"
/dev/md127p5: UUID="e9918fc1-6f8e-4c37-9b60-0d7342d46f07" TYPE="swap" PARTUUID="7b1fc87a-05"
/dev/loop8: TYPE="squashfs"
/dev/loop9: TYPE="squashfs"
/dev/loop10: TYPE="squashfs"
/dev/loop11: TYPE="squashfs"
/dev/loop12: TYPE="squashfs"
/dev/loop13: TYPE="squashfs"
/dev/loop14: TYPE="squashfs"
/dev/loop15: TYPE="squashfs"

$ cat /etc/initramfs-tools/conf.d/resume

RESUME=UUID=820bee40-75ec-4794-af59-497ba69ebbe8

$ sudo lshw -C memory

  *-firmware                
       description: BIOS
       vendor: American Megatrends Inc.
       physical id: 0
       version: V1.4
       date: 12/24/2015
       size: 64KiB
       capacity: 8MiB
       capabilities: pci upgrade shadowing cdboot bootselect socketedrom edd int13floppy1200 int13floppy720 int13floppy2880 int5printscreen int9keyboard int14serial int17printer acpi usb biosbootspecification uefi
  *-cache:0
       description: L1 cache
       physical id: 5
       slot: L1-Cache
       size: 384KiB
       capacity: 384KiB
       clock: 1GHz (1.0ns)
       capabilities: pipeline-burst internal write-back unified
       configuration: level=1
  *-cache:1
       description: L2 cache
       physical id: 6
       slot: L2-Cache
       size: 8MiB
       capacity: 8MiB
       clock: 1GHz (1.0ns)
       capabilities: pipeline-burst internal write-back unified
       configuration: level=2
  *-cache:2
       description: L3 cache
       physical id: 7
       slot: L3-Cache
       size: 8MiB
       capacity: 8MiB
       clock: 1GHz (1.0ns)
       capabilities: pipeline-burst internal write-back unified
       configuration: level=3
  *-memory
       description: System Memory
       physical id: 27
       slot: System board or motherboard
       size: 16GiB
     *-bank:0
          description: DIMM DDR3 Synchronous Unbuffered (Unregistered) 800 MHz (1.2 ns)
          product: TS1GLK64V6H
          vendor: Transcend
          physical id: 0
          serial: 000ABB8B
          slot: A1_DIMM0
          size: 8GiB
          width: 64 bits
          clock: 800MHz (1.2ns)
     *-bank:1
          description: DIMMProject-Id-Version: lshwReport-Msgid-Bugs-To: FULL NAME <EMAIL@ADDRESS>PO-Revision-Date: 2012-02-05 00:26+0000Last-Translator: Andi Chandler <Unknown>Language-Team: English (United Kingdom) <[email protected]>MIME-Version: 1.0Content-Type: text/plain; charset=UTF-8Content-Transfer-Encoding: 8bitX-Launchpad-Export-Date: 2020-04-16 17:42+0000X-Generator: Launchpad (build 2e26c9bbd21cdca248baaea29aeffb920afcc32a) Synchronous [empty]
          product: Array1_PartNumber1
          vendor: A1_Manufacturer1
          physical id: 1
          serial: A1_SerNum1
          slot: A1_DIMM1
     *-bank:2
          description: DIMM DDR3 Synchronous Unbuffered (Unregistered) 800 MHz (1.2 ns)
          product: V01L3LF8GB52852816
          vendor: Undefined
          physical id: 2
          serial: 00000000
          slot: A1_DIMM2
          size: 8GiB
          width: 64 bits
          clock: 800MHz (1.2ns)
     *-bank:3
          description: DIMMProject-Id-Version: lshwReport-Msgid-Bugs-To: FULL NAME <EMAIL@ADDRESS>PO-Revision-Date: 2012-02-05 00:26+0000Last-Translator: Andi Chandler <Unknown>Language-Team: English (United Kingdom) <[email protected]>MIME-Version: 1.0Content-Type: text/plain; charset=UTF-8Content-Transfer-Encoding: 8bitX-Launchpad-Export-Date: 2020-04-16 17:42+0000X-Generator: Launchpad (build 2e26c9bbd21cdca248baaea29aeffb920afcc32a) Synchronous [empty]
          product: Array1_PartNumber3
          vendor: A1_Manufacturer3
          physical id: 3
          serial: A1_SerNum3
          slot: A1_DIMM3

额外的

$ lsblk

loop0         7:0    0    97M  1 loop  /snap/core/9289
loop1         7:1    0    55M  1 loop  /snap/core18/1705
loop2         7:2    0  96.5M  1 loop  /snap/core/9436
loop3         7:3    0    55M  1 loop  /snap/core18/1754
loop4         7:4    0    61M  1 loop  /snap/core20/634
loop5         7:5    0   164M  1 loop  /snap/electron-mail/24
loop6         7:6    0 164.6M  1 loop  /snap/electron-mail/25
loop7         7:7    0 176.4M  1 loop  /snap/gimp/281
loop8         7:8    0 255.6M  1 loop  /snap/gnome-3-34-1804/36
loop9         7:9    0 175.9M  1 loop  /snap/gimp/273
loop10        7:10   0  62.1M  1 loop  /snap/gtk-common-themes/1506
loop11        7:11   0   132K  1 loop  /snap/gtk2-common-themes/9
loop12        7:12   0  54.8M  1 loop  /snap/gtk-common-themes/1502
loop13        7:13   0  49.8M  1 loop  /snap/snap-store/467
loop14        7:14   0  43.2M  1 loop  /snap/snap-store/415
loop15        7:15   0   140K  1 loop  /snap/gtk2-common-themes/13
sda           8:0    1 931.5G  0 disk  
└─md127       9:127  0   1.8T  0 raid5 
  ├─md127p1 259:0    0  93.1G  0 part  
  ├─md127p2 259:1    0     1K  0 part  
  ├─md127p3 259:2    0   1.7T  0 part  
  └─md127p5 259:3    0   4.7G  0 part  
sdb           8:16   1 931.5G  0 disk  
├─sdb1        8:17   1  95.4G  0 part  /
├─sdb2        8:18   1   3.4G  0 part  [SWAP]
├─sdb3        8:19   1 731.2G  0 part  
├─sdb4        8:20   1     1K  0 part  
├─sdb5        8:21   1 100.6G  0 part  
└─sdb6        8:22   1   992M  0 part  
sdc           8:32   1 931.5G  0 disk  
└─md127       9:127  0   1.8T  0 raid5 
  ├─md127p1 259:0    0  93.1G  0 part  
  ├─md127p2 259:1    0     1K  0 part  
  ├─md127p3 259:2    0   1.7T  0 part  
  └─md127p5 259:3    0   4.7G  0 part  
sdd           8:48   1 931.5G  0 disk  
└─md127       9:127  0   1.8T  0 raid5 
  ├─md127p1 259:0    0  93.1G  0 part  
  ├─md127p2 259:1    0     1K  0 part  
  ├─md127p3 259:2    0   1.7T  0 part  
  └─md127p5 259:3    0   4.7G  0 part  

解决方案:在本案中,普利茅斯是罪魁祸首。感谢@heynnema!

详细systemd-analyze plot之前(~188 秒)之后(约 45 秒)移除普利茅斯

故障排除期间进行的其他更改

  • 更新/etc/default/grub
    • GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
    • GRUB_CMDLINE_LINUX=""
  • 删除了 psensor$ sudo apt remove psensor
  • 精简到仅剩核心 snap 包 ( core, core18, core20, gnome-3-34-1804, gtk-common-themes, gtk2-common-themes, snap-store)

答案1

GRUB

您的/etc/default/grub内容不正确。请编辑它...

sudo -H /etc/default/grub

改变这个:

GRUB_CMDLINE_LINUX_DEFAULT="crashkernel=2G-6G:256M,6G-8G:512M,8G-:768M"
GRUB_CMDLINE_LINUX="quiet splash noresume"

对此:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""

sudo update-grub

reboot

文件系统检查

fsck所有磁盘。您的 RAID 的设备名称可能与 sdXX 不同。请根据需要进行调整。

  • 以“试用 Ubuntu”模式启动 Ubuntu Live DVD/USB
  • terminalCtrl+ Alt+打开窗口T
  • 类型sudo fdisk -l
  • 识别“Linux 文件系统”的 /dev/sdXX 设备名称
  • 输入sudo fsck -f /dev/sdXX,替换sdXX为您之前找到的数字
  • fsck如果有错误则重复命令
  • 类型reboot

普利茅斯

plymouth使用以下方法从系统中删除:

sudo apt-get purge plymouth

这将减少启动时间。

相关内容