问题情况: 执行systemctl命令后出现
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
-
安装 daemonize和fontconfig
apt install -y fontconfig daemonize
-
编辑/etc/profile脚本,加入如下内容
SYSTEMD_PID=' | grep -v unshare | awk '{print $2}')
if [ -z "(ps -ef | grep '/lib/systemd/systemd --system-unit=basic.target' | grep -v unshare | awk '{print 2}') fi
if [ -n "SYSTEMD_PID" ] && [ "SYSTEMD_PID" != "1" ]; then exec sudo /usr/bin/nsenter -t LOGNAME fi
-
修改/etc/sudoers文件,加入如下内容:
%sudo ALL=(ALL) NOPASSWD: /usr/sbin/daemonize /usr/bin/unshare --fork --pid --mount-proc /lib/systemd/systemd --system-unit=basic.target %sudo ALL=(ALL) NOPASSWD: /usr/bin/nsenter -t [0-9]* -a su - [a-zA-Z0-9]*
执行 source /etc/profile
完美解决