3

I create containers with

# debootstrap --variant=minbase --include=systemd,iproute2 buster "/var/lib/machines/test"

And then I run it with:

# systemd-nspawn --machine test

Just for testing purposes. The container boot, when I try to access it with machinectl I get the error:

# machinectl shell test
Failed to get shell PTY: Protocol error

After some googling, I realized that there was an old bug that generated this behavior, but this was fixed in systemd v226, and /usr/bin/systemd --version on my debian shows me the version 246.

I can get into the container using the "non systemd container" method, but my container runs systemd, I should be able to use machinectl.

2 Answers 2

7

It looks like I was missing dbus inside the container.

# chroot /var/lib/machines/test apt install dbus

Or using from the beginning:

# debootstrap --variant=minbase --include=systemd,dbus buster "/var/lib/machines/test"

both solves the problem.

0

Tutorial

Create Debian container

This step creates the minimal container including the two essential packages enabling effortless "machinectl login debiancontainer" later on, without any "Failed to get login PTY" errors. Notice the absense of minbase (this avoids errors when using passwd).

debootstrap --include=systemd,dbus unstable /var/lib/machines/debiancontainer

Set root password

This one-time step configures the root password inside the new container.

systemd-nspawn --machine debiancontainer

Example output that should follow

 systemd-nspawn --machine debiancontainer 
Spawning container debiancontainer on /var/lib/machines/debiancontainer.
Press ^] three times within 1s to kill container.
root@debiancontainer:~#

Now just execute and finish with exit or CTRL-D

root@debiancontainer:~# passwd
New password: 
Retype new password: 
passwd: password updated successfully
root@debiancontainer:~# 
logout

Start container using machinectl

Note: These commands can be used as normal user, so provide the applicable password in the requestor dialog.

machinectl start debiancontainer
machinectl list

Example output:

local@yourhost:~$ machinectl list
MACHINE         CLASS     SERVICE        OS     VERSION ADDRESSES
debiancontainer container systemd-nspawn debian -       -        

1 machines listed.

Login using machinectl

Example output

$ machinectl login debiancontainer
Connected to machine debiancontainer. Press ^] three times within 1s to exit session.

Debian GNU/Linux bookworm/sid yourhost pts/1

yourhost login: root
Password: 
Linux yourhost 5.13.19-2 #1 SMP 5.13.19-4 (Mon, 29 Nov 2021 12:10:09 +0100) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
root@yourhost:~#

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .