背景

今天在 Ubuntu 中运用 apt-get 卸载软件时, 体系提示我有多余的没用依靠库, 能够运用 autoremove 删去. 所以听信了, 删去后当时体系运用没有什么问题. 悲慛的是晚上重新电脑后, 默认进入的是 tty1, 并不是 tty7 显现办理器.
即便我运用 ctrl+alt+F7 切换, 也没有任何反响, 我猜测可能是因为 autoremove 删去了显现办理器的相关依靠库了, 有必要得想方法填坑了.

解决过程

因为 autoremove 删去了许多的库, 当时也没有留意有哪些库, 所以只能从根本原因查找了.

首先运用 tty1 登录体系, 准备重新发动我的显现办理器 ( lightdm ), 可是重新发动失利.

 ➜  service lightdm restart

 # output
 [sudo] password for guoxiangxun:
 Job for lightdm.service failed because the control process exited with error code.
 See "systemctl status lightdm.service" and "journalctl -xe" for details.

根据上面的提示, 经过 systemctl 查看 lightdm 的状况. 是发动失利的状况, 可是详细原因还是不知道.

 ➜  ~ systemctl status lightdm.service

 # output
 ● lightdm.service - Light Display Manager
 Loaded: loaded (/lib/systemd/system/lightdm.service; indirect; vendor preset: enabled)
 Active: failed (Result: exit-code) since Wed 2022-12-14 20:12:45 CST; 19s ago
 Docs: man:lightdm(1)
 Process: 4524 ExecStart=/usr/sbin/lightdm (code=exited, status=1/FAILURE)
 Process: 4518 ExecStartPre=/bin/sh -c [ "$(basename $(cat /etc/X11/default-display-manager 2>/dev/null))" = "lightdm" ] (code=
         Main PID: 4524 (code=exited, status=1/FAILURE)
         Dec 14 20:12:45 guoxiangxun-Latitude-3330 systemd[1]: lightdm.service: Service hold-off time over, scheduling restart.
         Dec 14 20:12:45 guoxiangxun-Latitude-3330 systemd[1]: lightdm.service: Scheduled restart job, restart counter is at 5.
         Dec 14 20:12:45 guoxiangxun-Latitude-3330 systemd[1]: Stopped Light Display Manager.
         Dec 14 20:12:45 guoxiangxun-Latitude-3330 systemd[1]: lightdm.service: Start request repeated too quickly.
         Dec 14 20:12:45 guoxiangxun-Latitude-3330 systemd[1]: lightdm.service: Failed with result 'exit-code'.
         Dec 14 20:12:45 guoxiangxun-Latitude-3330 systemd[1]: Failed to start Light Display Manager.

经过查找相关的资料, 能够经过执行 ligthdm 带上 debug 相关的调试参数, 再分析详细的日志信息.

➜  ~ lightdm --test-mode --debug

# output
[+0.00s] DEBUG: Logging to /home/guoxiangxun/.cache/lightdm/log/lightdm.log
[+0.00s] DEBUG: Starting Light Display Manager 1.26.0, UID=1000 PID=18264
[+0.00s] DEBUG: Loading configuration dirs from /usr/share/lightdm/lightdm.conf.d
[+0.00s] DEBUG: Loading configuration from /usr/share/lightdm/lightdm.conf.d/50-disable-guest.conf
[+0.00s] DEBUG: Loading configuration from /usr/share/lightdm/lightdm.conf.d/50-disable-log-backup.conf
[+0.00s] DEBUG: Loading configuration from /usr/share/lightdm/lightdm.conf.d/50-greeter-wrapper.conf
[+0.00s] DEBUG: Loading configuration from /usr/share/lightdm/lightdm.conf.d/50-guest-wrapper.conf
[+0.00s] DEBUG: Loading configuration from /usr/share/lightdm/lightdm.conf.d/50-ubuntu.conf
[+0.00s] DEBUG: Loading configuration from /usr/share/lightdm/lightdm.conf.d/50-unity-greeter.conf
[+0.00s] DEBUG: Loading configuration from /usr/share/lightdm/lightdm.conf.d/50-unity.conf
[+0.00s] DEBUG: Loading configuration from /usr/share/lightdm/lightdm.conf.d/50-xserver-command.conf
[+0.00s] DEBUG: Loading configuration dirs from /usr/local/share/lightdm/lightdm.conf.d
[+0.00s] DEBUG: Loading configuration dirs from /etc/xdg/lightdm/lightdm.conf.d
[+0.00s] DEBUG: Loading configuration from /etc/lightdm/lightdm.conf
[+0.00s] DEBUG: Running in user mode
[+0.00s] DEBUG: Registered seat module local
[+0.00s] DEBUG: Registered seat module xremote
[+0.00s] DEBUG: Registered seat module unity
[+0.00s] DEBUG: Using D-Bus name org.freedesktop.DisplayManager
[+0.21s] DEBUG: Monitoring logind for seats
[+0.21s] DEBUG: New seat added from logind: seat0
[+0.21s] DEBUG: Seat seat0: Loading properties from config section Seat:*
[+0.21s] DEBUG: Seat seat0: Starting
[+0.21s] DEBUG: Seat seat0: Creating greeter session
[+0.21s] DEBUG: Loading users from org.freedesktop.Accounts
[+0.22s] DEBUG: User /org/freedesktop/Accounts/User1000 added
[+0.31s] DEBUG: Seat seat0: Creating display server of type x
[+0.31s] DEBUG: Seat seat0: Starting local X display
[+0.32s] DEBUG: XServer 0: Logging to /home/guoxiangxun/.cache/lightdm/log/x-0.log
[+0.32s] DEBUG: XServer 0: Can't launch X server X -core, not found in path            ==>主要错误信息
[+0.32s] DEBUG: XServer 0: X server stopped
[+0.32s] DEBUG: Seat seat0: Display server stopped
[+0.32s] DEBUG: Seat seat0: Can't create display server for greeter
[+0.32s] DEBUG: Seat seat0: Session stopped
[+0.32s] DEBUG: Seat seat0: Stopping display server, no sessions require it
[+0.32s] DEBUG: Seat seat0: Stopping
[+0.32s] DEBUG: Seat seat0: Stopped
[+0.32s] DEBUG: Failed to start seat: seat0

经过日志 [+0.32s] DEBUG: XServer 0: Can't launch X server X -core, not found in path 发现是缺少 X server 相关库.

终究经过装置 xserver-org 重新发动即康复正常.

➜  ~ sudo apt-get install xserver-xorg

Summary

总的来说, 问题的原因就是因为 autoremove 删去了一些本不应该删去的依靠库, 导致了lightdm 显现办理器出现了问题, 大家可能还会遇到其它类似的问题, 但解决问题的思路和过程大致应该差不多.

同时了解了一下 autoremove 命令, 主要是删去已卸载软件所不需要运用的依靠库.

autoremove (apt-get(8))
autoremove is used to remove packages that were automatically installed to satisfy
dependencies for other packages and are now no longer needed as dependencies changed
or the package(s) needing them were removed in the meantime.

一般来说如果你一切的软件装置都是经过 apt 进行办理的话, autoremove 应该是安全的, 他的数据库会记载相关依靠的引证计数. 如果运用了多种软件办理器, 很有可能会打扰 apt 的数据库依靠关系,这时运用 autoremove 是适当风险的工作.
在运用 autoremove 时, 能够先加上 -s--dry-run 的参数试运行下 ( 不会真实执行 ), 看下输出的要删去的依靠是否是真实不需要的.

References

  • www.debugpoint.com/failed-to-s…
  • manpages.ubuntu.com/manpages/ki…
  • manpages.ubuntu.com/manpages/ki…