背景
今天在 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
的参数试运行下 ( 不会真正执行 ), 看下输出的要删除的依赖是否是真正不需要的.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。