使用systemd-analyze工具定位耗时服务,是优化启动速度的第一步。通过systemd-analyze blame查看各服务启动耗时(从长到短排序),systemd-analyze critical-chain生成关键路径分析,systemd-analyze plot > ~/boot.svg导出启动时间线图表。根据分析结果,禁用非必要服务(如蓝牙、打印服务等):sudo systemctl disable <service-name>.service。
编辑/etc/default/grub文件,调整以下参数缩短引导时间:
GRUB_TIMEOUT=2:将GRUB菜单显示时间从默认5秒缩短至2秒(若无需选择系统,可设为0实现直接启动);GRUB_TIMEOUT_STYLE="menu":强制显示GRUB菜单(若设为countdown,超时会自动选择默认项)。sudo update-grub使配置生效。通过systemctl命令管理系统服务:
sudo systemctl list-unit-files --type=service --state=enabled;bluetooth.service、postgresql.service):sudo systemctl disable <service-name>;sysv-rc-conf工具批量管理服务:sudo apt install sysv-rc-conf && sudo sysv-rc-conf。编辑/etc/sysctl.conf文件,添加或修改以下参数提升内核效率:
net.ipv4.tcp_tw_reuse=1:允许复用TIME-WAIT状态的TCP连接,减少网络延迟;net.core.somaxconn=4096:增加TCP监听队列长度,避免高并发时连接被拒绝;vm.swappiness=10:降低交换分区使用频率(设为10,值越小越优先使用物理内存)。sudo sysctl -p使参数生效。选择ext4(默认)或XFS(适合大文件、高并发)文件系统,提升磁盘I/O性能。若当前系统使用ext4,可通过tune2fs工具优化:
sudo tune2fs -o journal_data_writeback /dev/sdX(减少日志写入开销);sudo tune2fs -O dir_index /dev/sdX(加速目录查找)。定期清理临时文件、缓存和旧内核,释放磁盘空间并减少启动加载项:
sudo rm -rf /tmp/*;sudo apt clean && sudo apt autoclean;sudo apt autoremove --purge。