I am making a script that uses systemd-nspawn to boot a second linux root filesystem in a container.

The script is currently using this line to boot the container: systemd-nspawn -b --machine virtualdesktop -D "/mnt/virtualdesktop" The host and container are based on Debian and use systemd. (Raspbian Buster to be exact)

The guest boots up correctly and after logging in, gives me a shell.
But that is not all I want - the script should also load the graphics of the guest. The host has a Xephyr window open, running a second X display on :1. Then the guest will run lxsession on display :1.

It is easy to do this manually by typing this command in the guest's shell: DISPLAY=:1 lxsession -s LXDE-pi -e LXDE, but here's what I need help with: running that command automatically, not requiring the operator to input the guest's password and type in the lxsession command.

I have tried:

  • Appending the desired lxsession command to the end of the systemd-nspawn command, like this: systemd-nspawn -b --machine virtualdesktop -D "/mnt/virtualdesktop" 'DISPLAY=:1 lxsession -s LXDE-pi -e LXDE', but nothing happened.
  • using systemd-run, as suggested here. Ran this command while container is running: systemd-run --machine virtualdesktop "/usr/binlxsession -s LXDE-pi -e LXDE", but Xephyr doesn't display anything and journalctl reports Failed to execute command: No such file or directory
    Failed at step EXEC spawning /usr/bin/lxsession -s LXDE-pi -e LXDE: No such file or directory

Remove the quotes from your commands and use the -E, --setenv option:

systemd-nspawn --machine virtualdesktop -D "/mnt/virtualdesktop" -E DISPLAY=:1 lxsession -s LXDE-pi -e LXDE


systemd-run --machine virtualdesktop -E DISPLAY=:1 /usr/bin/lxsession -s LXDE-pi -e LXDE

You try to execute the files 'DISPLAY=:1 lxsession -s LXDE-pi -e LXDE' and '/usr/bin/lxsession -s LXDE-pi -e LXDE':

systemd-run [OPTIONS...] COMMAND [ARGS...]
systemd-nspawn [OPTIONS...] [COMMAND [ARGS...]]
  • using -b flag makes systemd-nspawn ignore any commands to run, therefore I need an alternative. Similar question here. – Botspot Sep 12 '19 at 2:15
  • I have started researching expect to see if it can input the commands automatically in the guest's shell. – Botspot Sep 12 '19 at 2:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.