Ubuntu 启动与关机优化实操指南
一 诊断与总体思路
systemd-analyze timesystemd-analyze blamesystemd-analyze critical-chain二 启动速度优化
systemctl list-unit-files --type servicesudo systemctl disable bluetooth.service cups.service ModemManager.servicesudo systemctl mask <service>gnome-session-properties,关闭不需要的启动程序(如蓝牙、打印队列、远程桌面等)。/etc/default/grub,将 GRUB_TIMEOUT=2(单位秒),保存后执行 sudo update-grub。如需保留选择内核/恢复模式,不要设为 0。discard 或启用定时 TRIM:sudo systemctl enable fstrim.timersudo apt autoremove --purge,释放 /boot 空间,避免内核选择界面过长。linux 行末尾追加 profile,按 Ctrl+X 启动一次以生成新列表(下次启动生效)。三 关机时间优化
journalctl -rb -1(倒序查看)。若未见日志,确保持久化日志已开启:创建 /var/log/journal 并检查 /etc/systemd/journald.conf 中 Storage=auto|persistent。sudo cp /etc/systemd/system.conf /etc/systemd/system.conf.origDefaultTimeoutStopSec=90s 改为更小值(如 5s 或 10s),保存后执行 sudo systemctl daemon-reloadDefaultTimeoutStartSec 设得过小(例如 1s 可能导致无法正常进入系统),如需调整请谨慎并保留恢复入口。ps -af | grep watch/etc/systemd/system.conf 中降低 ShutdownWatchdogSec(如从默认 10 分钟调低),或按需禁用相关服务。四 常见问题与注意事项
journalctl -rb -1 定位,再决定是修复该服务还是调整超时。/etc/default/grub,将 GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" 改为 "",保存并执行 sudo update-grub;排查完成后可恢复。GRUB_TIMEOUT 设为 0,否则无法进入高级选项与恢复模式;建议保留 1–2 秒 并可在倒计时时按键中断。system.conf、grub),并确保有可用的恢复模式入口,避免配置不当导致无法启动。