Linux优化开机启动项

1、审查开机启动日志

$ sudo cat /var/log/boot.log
复制代码

2、查看开机启动项

$ sudo systemctl list-unit-files --type=service | grep enabled
accounts-daemon.service                    enabled
anacron-resume.service                     enabled
anacron.service                            enabled
bluetooth.service                          enabled
brltty.service                             enabled
[...]
复制代码

1. 优化

1.1 禁止程序开机启动

#中止程序
$ sudo systemctl stop bluetooth.service

#禁止开机启动
$ sudo systemctl disable bluetooth.service
复制代码

1.2 查看程序运行状态

$ sudo systemctl status bluetooth.service
 bluetooth.service - Bluetooth service
  Loaded: loaded (/lib/systemd/system/bluetooth.service; disabled; vendor preset: enabled)
  Active: inactive (dead)
    Docs: man:bluetoothd(8)
复制代码

Loaded: 开机时是否加载:enabled 开机启动,disabled 禁用开机启动; 默认启动状态(vendor preset: enabled)mysql

Active: 程序的运行状态:运行时(running)、中止(dead)sql

2. 恢复

2.1 设置程序开机自启

# 启动程序
$ sudo systemctl start bluetooth.service

# 开机自启
$ sudo systemctl enable bluetooth.service
复制代码

3. 禁用无效

3.1 注销应用程序

$ sudo systemctl mask bluetooth.service
 Created symlink from /etc/systemd/system/bluetooth.service to /dev/null.
复制代码

注销后程序将不能被其余程序调用,(disabled无效时能够考虑使用)bash

3.2 取消注销程序

$ sudo systemctl unmask bluetooth.service
复制代码

3、查看程序耗时

1. 查看程序耗时

$ sudo systemd-analyze blame
        8.708s gpu-manager.service
        8.002s NetworkManager-wait-online.service
        5.791s mysql.service
        2.975s dev-sda3.device
        1.810s alsa-restore.service
        1.806s systemd-logind.service
        1.803s irqbalance.service
        1.800s lm-sensors.service
        1.800s grub-common.service
复制代码

2. 生成启动图表

# 生成图表
$ systemd-analyze plot > plot.svg

#打开图片
$ eog plot.svg
复制代码
相关文章
相关标签/搜索