我是 Debian 用户。
我删除了systemd,没有安装任何其他东西。
我跑了sudo apt remove systemd
。之后我就跑了 sudo apt autoremove systemd
。
之后,我的笔记本电脑无法连接到互联网,也无法使用 GUI;我陷入了命令行界面(我可以在登录后运行命令)。我怎么解决这个问题?
答案1
我假设下面的所有命令都以 root 用户身份运行。直接以 root 身份登录,或者如果不能,请以允许使用sudo
和使用的用户身份登录sudo -i
:应该有一个 root 提示符,#
末尾带有 a 。
/var/log/apt
您应该备份以下内容
cp -a /var/log/apt /root/log-apt-backup
这样您以后就可以找到可能需要安装回来的其他已删除的软件包。
由于对系统 V 的支持正在逐渐减少,我可以假设某些 GUI 部分依赖于 systemd 功能,因此无法启动。
您应该重新安装systemd
,但这可能还不够:要触发其他所需的依赖项,您应该删除提供 System V 的/sbin/init
:的内容sysvinit-core
。以同样的方式删除systemd
替换系统 V 软件包的触发安装,删除此软件包将触发 systemd 生态系统中的替换。
在空的 LXC 容器上进行了测试:
root@bookworm-test:~# apt remove systemd
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
initscripts insserv orphan-sysvinit-scripts sensible-utils startpar sysv-rc
sysvinit-core ucf
Suggested packages:
bootchart2 bootlogd
The following packages will be REMOVED:
dbus-user-session libnss-systemd libpam-systemd systemd systemd-resolved
systemd-sysv
The following NEW packages will be installed:
initscripts insserv orphan-sysvinit-scripts sensible-utils startpar sysv-rc
sysvinit-core ucf
0 upgraded, 8 newly installed, 6 to remove and 0 not upgraded.
稍后重新启动修复等(不要运行这个,还不够):
# apt install systemd
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
systemd-timesyncd
Suggested packages:
systemd-container systemd-homed systemd-userdbd systemd-boot
systemd-resolved libqrencode4 libtss2-esys-3.0.2-0 libtss2-mu0 libtss2-rc0
polkitd | policykit-1
The following NEW packages will be installed:
systemd systemd-timesyncd
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
不会做足够有用的事情(它将保留在 sys V init 中)。
反而:
root@bookworm-test:~# apt remove sysvinit-core
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
initscripts insserv startpar sysv-rc
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
dbus-user-session libnss-systemd libpam-systemd systemd systemd-sysv
systemd-timesyncd
Suggested packages:
systemd-container systemd-homed systemd-userdbd systemd-boot
systemd-resolved libqrencode4 libtss2-esys-3.0.2-0 libtss2-mu0 libtss2-rc0
polkitd | policykit-1
The following packages will be REMOVED:
sysvinit-core
The following NEW packages will be installed:
dbus-user-session libnss-systemd libpam-systemd systemd systemd-sysv
systemd-timesyncd
0 upgraded, 6 newly installed, 1 to remove and 0 not upgraded.
显得更有用。应至少安装一个建议的软件包:(通过在末尾polkitd
附加,这可以在一次操作中完成)。所以最终运行:+
remove
apt remove sysvinit-core polkitd+
这需要网络。默认情况下,OP(实际上是我的 LXC 测试)似乎不再有网络。使用名为的有线以太网接口应该可以轻松修复此问题eth0
(实际名称可以从ip -br link
结果中检索,eth0
如果需要,请用它替换下面的名称):
dhclient -v eth0
然后重试之前的apt
命令。
在最小的系统上会显示类似这样的内容:
# apt remove sysvinit-core polkitd+
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
initscripts insserv startpar sysv-rc
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
dbus-user-session libduktape207 libglib2.0-0 libglib2.0-data libicu72
libnss-systemd libpam-systemd libpolkit-agent-1-0 libpolkit-gobject-1-0
libxml2 sgml-base shared-mime-info systemd systemd-sysv systemd-timesyncd
xdg-user-dirs xml-core
Suggested packages:
low-memory-monitor polkitd-pkla sgml-base-doc systemd-container
systemd-homed systemd-userdbd systemd-boot systemd-resolved libqrencode4
libtss2-esys-3.0.2-0 libtss2-mu0 libtss2-rc0 debhelper
The following packages will be REMOVED:
sysvinit-core
The following NEW packages will be installed:
dbus-user-session libduktape207 libglib2.0-0 libglib2.0-data libicu72
libnss-systemd libpam-systemd libpolkit-agent-1-0 libpolkit-gobject-1-0
libxml2 polkitd sgml-base shared-mime-info systemd systemd-sysv
systemd-timesyncd xdg-user-dirs xml-core
0 upgraded, 18 newly installed, 1 to remove and 0 not upgraded.
然后重新启动,切换回 systemd。这可能会也可能不会恢复 GUI,但这应该已经切换回systemd
.为了验证这一点,可以运行(以 root 身份):
ldd /proc/1/exe | grep systemd
它应该有非空输出。
完成上述操作后,检查日志备份/root/log-apt-backup/history.log
并搜索类似于您执行的命令的行:Commandline: apt remove systemd
和Commandline: apt autoremove systemd
。检查其各自条目下方显示的所有已删除的软件包Remove:
,并添加回可能仍然缺少的内容。