Ubuntu 22.04机械硬盘(HDD)开机速度优化咨询
Hey there! I totally get wanting to speed up that boot time on your HDD—1 minute 31 seconds does feel sluggish, especially since your kernel loads up pretty fast (only 8 seconds!). Let’s dive into your systemd-analyze output and walk through actionable tweaks you can try.
First, here’s the breakdown you shared:
Boot Time Summary
systemd-analyze Startup finished in 8.061s (kernel) + 1min 23.131s (userspace) = 1min 31.192s graphical.target reached after 1min 23.055s in userspace
Top Time-Consuming Services
systemd-analyze blame 42.635s plymouth-quit-wait.service 23.877s systemd-journal-flush.service 22.750s networkd-dispatcher.service 20.374s snapd.service 19.755s NetworkManager-wait-online.service 14.015s udisks2.service 13.017s apache2.service 12.189s dev-sda2.device 11.926s ModemManager.service 11.647s cups.service 10.216s dev-loop15.device 9.726s dev-loop5.device 9.033s gdm.service 8.706s accounts-daemon.service 7.684s NetworkManager.service 7.063s snapd.seeded.service 5.838s dev-loop3.device 5.807s dev-loop14.device 5.784s dev-loop11.device 5.781s dev-loop16.device 5.761s dev-loop10.device 5.522s power-profiles-daemon.service 5.440s polkit.service 5.150s dev-loop12.device 5.128s dev-loop13.device 5.111s dev-loop17.device 5.072s dev-loop6.device 4.961s dev-loop9.device 4.926s dev-loop8.device 4.878s dev-loop2.device 4.806s dev-loop0.device 4.540s avahi-daemon.service 4.538s bluetooth.service 4.108s thermald.service 3.806s switcheroo-control.service 3.799s systemd-logind.service 3.775s wpa_supplicant.service 3.180s dev-loop4.device 2.733s systemd-resolved.service 2.705s dev-loop7.device 2.644s gpu-manager.service 2.240s systemd-tmpfiles-setup.service 2.212s secureboot-db.service 2.179s rsyslog.service
Actionable Optimizations
Let’s tackle the biggest culprits first:
plymouth-quit-wait.service (42s+): This service waits for the boot splash screen to exit, which is a massive bottleneck on HDDs. Disable it with:
sudo systemctl disable plymouth-quit-wait.serviceYou’ll still see the boot splash, but the system won’t hang around waiting for it to close.
NetworkManager-wait-online.service (19s+): This pauses boot until your network is fully connected. If you don’t have critical services that need internet right at startup, disable it:
sudo systemctl disable NetworkManager-wait-online.serviceYour network will still connect automatically after boot—this just stops the system from waiting for it.
systemd-journal-flush.service (23s+): This flushes system logs to your HDD on boot. To speed this up, adjust the journal configuration:
- Open
/etc/systemd/journald.confwith a text editor (e.g.,sudo nano /etc/systemd/journald.conf) - Uncomment the
Storageline and change it toStorage=volatile(this keeps logs in RAM, so they’ll clear on reboot—great if you don’t need long-term logs) - Or, if you want to keep logs, uncomment
SystemMaxUseand set a reasonable limit (likeSystemMaxUse=100M) to reduce the data written on boot. - Save the file and run
sudo systemctl restart systemd-journald
- Open
networkd-dispatcher.service (22s+): This is for systemd-networkd, but you’re using NetworkManager (seen in your output). You can safely disable this service:
sudo systemctl disable networkd-dispatcher.servicesnapd.service & snapd.seeded.service (20s + 7s): Snap apps mount multiple loop devices (all those
dev-loop*entries in your blame list), which is slow on HDDs.- First, uninstall any Snap apps you don’t use (run
snap listto see installed ones, thensudo snap remove <app-name>) - If you still use Snaps, disable the seeded service (it waits for Snap to finish initializing):
sudo systemctl disable snapd.seeded.service
- First, uninstall any Snap apps you don’t use (run
apache2.service (13s): If you don’t need your web server to start automatically on boot, disable it:
sudo systemctl disable apache2.serviceYou can start it manually when needed with
sudo systemctl start apache2.service.ModemManager.service (11s+): If you don’t use a dial-up modem or mobile broadband, disable this:
sudo systemctl disable ModemManager.servicecups.service (11s+): If you don’t have a printer connected, disable the printing service:
sudo systemctl disable cups.service
Additional HDD-Specific Tweaks
- Optimize disk mount options: Edit your
/etc/fstabfile (withsudo nano /etc/fstab) and addnoatimeto your root partition (dev-sda2) line. This disables writing access times to the disk, reducing unnecessary HDD activity. The line should look something like:UUID=xxxxxx / ext4 errors=remount-ro,noatime 0 1 - Defragment the disk: While ext4 handles fragmentation automatically, you can run a manual defrag on your root partition to speed up reads/writes:
Note: This may take a while, so run it when you don’t need to use the system.sudo e4defrag /dev/sda2
After making these changes, reboot and run systemd-analyze again to see the improvement—you should notice a significant drop in boot time!
备注:内容来源于stack exchange,提问作者user1566092

