无法在 nspawn 容器中获取 shell:[email protected] 已存在

无法在 nspawn 容器中获取 shell:[email protected] 已存在

当尝试将 shell 放入容器虚拟机时,我收到以下错误消息:

$ doas machinectl shell user@machine
Failed to get shell PTY: Unit [email protected] already exists.

但这个单位不存在:

$ doas systemctl list-units 'container-shell*'
  UNIT LOAD ACTIVE SUB DESCRIPTION
0 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.

我无法杀死它:

$ doas systemctl kill [email protected]
Failed to kill unit [email protected]: Unit [email protected] not loaded.

答案1

这是因为您的最后一个 shell 没有正确终止。它很可能被另一个进程终止了。(被systemd-oomd?)

有问题的单元[email protected]位于机器内部。您可以使用它systemctl -M <machine_name> …来调用机器内部的命令,然后修复它:

$ doas systemctl -M machine list-units 'container-shell*'
  UNIT                      LOAD   ACTIVE SUB    DESCRIPTION[email protected] loaded failed failed Shell for User user

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.
1 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.

您还可以通过重新启动发生故障的单元来清理它,从而强制它自行清理:

$ doas systemctl -M machine start [email protected]
$ doas systemctl -M machine list-units 'container-shell*'
  UNIT LOAD ACTIVE SUB DESCRIPTION
0 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
$ doas machinectl shell root@machine
Connected to machine machine. Press ^] three times within 1s to exit session.
root@machine:~# profit!!!

相关内容