我可以禁用 udisk2.service 来减少 Ubuntu 20.04 上的启动时间吗?

我可以禁用 udisk2.service 来减少 Ubuntu 20.04 上的启动时间吗?

以下是输出systemd-analyze critical-chain

The time when unit became active or started is printed after the "@" character.   
The time the unit took to start is printed after the "+" character.

graphical.target @22.413s
└─udisks2.service @14.245s +8.166s
  └─basic.target @13.822s
    └─sockets.target @13.820s
      └─uuidd.socket @13.817s
        └─sysinit.target @13.176s
          └─systemd-timesyncd.service @12.401s +772ms
            └─systemd-tmpfiles-setup.service @11.581s +770ms
              └─local-fs.target @11.546s
                └─boot-efi.mount @11.459s +86ms
                  └─systemd-fsck@dev-disk-by\x2duuid-507A\x2d2B05.service @11.238s +158ms
                    └─dev-disk-by\x2duuid-507A\x2d2B05.device @11.236s

还添加了输出systemd-analyze blame

8.166s udisks2.service                                      
7.102s accounts-daemon.service                              
6.851s dev-sda2.device                                      
5.069s NetworkManager.service                               
4.319s switcheroo-control.service                           
4.298s systemd-logind.service                               
4.287s wpa_supplicant.service                               
2.695s gpu-manager.service                                  
2.662s grub-common.service                                  
2.602s rsyslog.service                                      
2.433s fwupd.service                                        
2.207s systemd-resolved.service                             
1.954s e2scrub_reap.service                                 
1.853s grub-initrd-fallback.service                         
1.804s upower.service                                       
1.800s secureboot-db.service                                
1.574s gdm.service                                          
1.566s apparmor.service                                     
1.259s keyboard-setup.service                               
1.242s kerneloops.service                                   
1.141s networking.service                                   
1.065s systemd-udevd.service                                
 973ms systemd-sysusers.service                             
 926ms polkit.service                                       
 925ms colord.service                                       
 901ms swapfile.swap                                        
 867ms systemd-udev-trigger.service                         
 789ms systemd-modules-load.service                         
 772ms systemd-timesyncd.service                            
 770ms systemd-tmpfiles-setup.service                       
 691ms systemd-rfkill.service                               
 677ms systemd-sysctl.service                               
 629ms systemd-random-seed.service                          
 599ms systemd-backlight@backlight:intel_backlight.service  
 483ms [email protected]

您能帮助我指导我可以安全地禁用哪些服务吗?
我正在使用单启动的 Ubuntu 20.04。

更新 2

  cat /etc/fstab  

# /etc/fstab: static file system information.
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda2 during installation
UUID=b9113027-0606-4c19-9705-9df918cc858b /               ext4    errors=remount-ro 0       0
# /boot/efi was on /dev/sda1 during installation
UUID=507A-2B05  /boot/efi       vfat    umask=0077      0       1
/swapfile    
  sudo blkid :
  /dev/sda2: UUID="b9113027-0606-4c19-9705-9df918cc858b" TYPE="ext4" PARTUUID="652de5b4-beff-453f-b695-612578b781b1"
  /dev/sda1: UUID="507A-2B05" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="210b47a1-b7a5-4f99-a266-23aee6b19eb7"

free -h 
              total        used        free      shared  buff/cache   available
Mem:          3.7Gi       2.7Gi       156Mi       329Mi       883Mi       473Mi
Swap:         2.0Gi        65Mi       1.9Gi

还有 SMART 测试的屏幕截图:
SMART 测试 智能测试 2

grep -i FPDMA /var/log/syslog*没有显示任何内容。

grep -i sda /var/log/syslog* :https://paste.ubuntu.com/p/5stQZqPSGB/

grep -i swap /etc/fstab
/swapfile    none       swap    sw      0       0

答案1

就我而言,它在 Lubuntu 20.04 上看起来像这样:

$ systemd-analyze blame
1min 30.015s nmbd.service                                                                             
      7.411s NetworkManager-wait-online.service                                                       
      1.832s dev-sda1.device                                                                          
      1.234s systemd-logind.service                                                                   
      1.191s systemd-resolved.service                                                                 
      1.073s apt-daily-upgrade.service                                                                
       974ms upower.service                                                                           
       838ms motd-news.service                                                                        
       824ms systemd-timesyncd.service                                                                
       734ms systemd-journald.service                                                                 
       715ms networkd-dispatcher.service                                                              
       642ms accounts-daemon.service                                                                  
       599ms snapd.service                                                                            
       597ms udisks2.service                                                                          
       525ms fwupd-refresh.service                                                                    
       454ms fwupd.service                                                                            
       343ms avahi-daemon.service                                                                     
       331ms NetworkManager.service                                                                   
       305ms dundee.service                                                                           
       299ms polkit.service                                                                           
       275ms apport.service                 

$ man udisks

NAME
       udisks - Disk Manager

DESCRIPTION
       udisks provides interfaces to enumerate and perform operations on disks and storage devices. Any application (including unprivileged ones) can access the udisksd(8) daemon via
       the name org.freedesktop.UDisks2 on the system message bus[1]. In addition to the D-Bus API, a library, libudisks2 is also provided. This library can be used from C/C++ and any
       high-level language with GObjectIntrospection[2] support such as Javascript and Python. udisks is only indirectly involved in what devices and objects are shown in the user
       interface.

似乎在 udisks 服务禁用的情况下不会有任何积极的影响。因此最好确保您的驱动器已正确安装并且可以从用户会话中访问。

还可以使用它journalctl -b | grep udisks来查看操作系统启动期间可能发生的情况,因此需要花费大量时间来加载。

要了解哪些服务是必需的,哪些不是,请使用:

ps aux | grep servicename

例如:

$ ps aux | grep udisks
root         809  0.0  0.1 395468 15492 ?        Ssl  11:17   0:03 /usr/lib/udisks2/udisksd
spacer      1338  0.0  0.1 393924 12020 ?        Ssl  11:18   0:00 /usr/libexec/gvfs-udisks2-volume-monitor
root        7842  0.1  0.0  13916  4552 ?        Ss   14:31   0:03 /sbin/mount.ntfs /dev/sdb5 /media/spacer/SUPER -o rw,nodev,nosuid,windows_names,uid=1000,gid=1001,uhelper=udisks2
root        9153  0.0  0.0  12148  2704 ?        Ss   14:57   0:00 /sbin/mount.ntfs /dev/sdc1 /media/spacer/Passport -o rw,nodev,nosuid,windows_names,uid=1000,gid=1001,uhelper=udisks2

然后man servicename看看它做什么。

然后使用下一个命令查看哪些服务依赖于您想要禁用的服务:

$ systemctl list-dependencies udisks2 --all --reverse
udisks2.service
● └─graphical.target

在这种情况下graphical.target可能会受到影响。但是,您可以尝试阻止它并查看会发生什么(但这可能不安全):

$ sudo systemctl stop udisks2

答案2

开机时间

使用奔腾处理器、4G RAM、2G 交换空间、可能还有较旧的 HDD 和 Ubuntu 20.04,不要指望启动时间少于 60-90 秒。如果您想要更快的系统,请考虑使用 Xubuntu。

系统服务

首先,减少启动时间的方法不是禁用关键系统服务。因此...重新启用您停止/禁用的所有服务。

交换和内存

由于只有 4G RAM,2G 交换空间太小。您似乎还可以使用更多 RAM。成对添加 RAM,以便系统可以利用内存交错的速度优势。因此,如果您现在有一根 4G RAM 棒,请添加第二根 4G RAM 棒,或者用两根 8G RAM 棒替换一根 4G RAM 棒。

将您的交换从 2G 增加到 4G......

笔记:命令使用不当dd可能导致数据丢失。建议复制/粘贴。

sudo swapoff -a           # turn off swap
sudo rm -i /swapfile      # remove old /swapfile

sudo dd if=/dev/zero of=/swapfile bs=1M count=4096

sudo chmod 600 /swapfile  # set proper file protections
sudo mkswap /swapfile     # init /swapfile
sudo swapon /swapfile     # turn on swap
free -h                   # confirm 4G RAM and 4G swap
reboot                    # reboot and verify operation

磁盘

您的磁盘出现读取/寻道/重新分配错误,但在查看 /var/log/syslog 的片段时,我无法辨别问题可能是什么。您的硬盘可能出现故障,但我现在无法证明这一点。请保留好备份。

相关内容