Nixpkgs: systemd-nspawn does not work with debootstrap created systems

Created on 3 Nov 2016  ·  7Comments  ·  Source: NixOS/nixpkgs

Issue description

When you try to start with systemd-nspawn a system that you did create with debootstrap before it does not quit with the following error:

Cannot be run in a chroot() environment.
Freezing execution.

I have to add that I tested it only with a modified build of debootstrap that uses the ubuntu version of debootstrap and a ubuntu image, but on the mailing list @garbas did say that it did not work with a debian image and I guess the normal bootstrap command, too:

if nothing i can confirm your
error that running debian/ubuntu via debootstrap and systemd-nspawn
fails with error you provided.

Steps to reproduce

  1. debootstrap-ubuntu --no-check-gpg xenial ubuntu (thats what I did normal debootstrap with debian should be the same)
  2. sudo systemd-nspawn -b -D ubuntu/
bug community feedback

Most helpful comment

i had the same problem on a debian in debian systemd-nspawn. (i landed here via google)
The error message comes from systemd in the systemd-nspawn container.

core/main.c

if (arg_running_as == SYSTEMD_SYSTEM &&
            arg_action == ACTION_RUN &&
            running_in_chroot() > 0) {
                log_error("Cannot be run in a chroot() environment.");
                goto finish;
        }

shared/util.c

int running_in_chroot(void) {
        int ret;

        ret = files_same("/proc/1/root", "/");
        if (ret < 0)
                return ret;

        return ret == 0;
}

My problem was that the proc filesystem was mounted in the root directory of the container system.. I think deboostrap might let proc mounted in the destination. The fix is as simple as unmount the proc filesystem there.
```
umount ./DebianJessie/proc
````

Hopefully the next guy doesn't spend a couple of hours to find out whats wrong.

All 7 comments

here are my commands how to reproduce this

% nix-env -iA nixos.debootstrap
installing ‘debootstrap-1.0.80’
...
% debootstrap --arch=amd64 stable ./DebianJessie
...
% sudo systemd-nspawn -b -D ./DebianJessie                                                                                        ⏎
Spawning container DebianJessie on /home/rok/./DebianJessie.
Press ^] three times within 1s to kill container.
/etc/localtime does not point into /usr/share/zoneinfo/, not updating container timezone.
Cannot be run in a chroot() environment.

then execution freezes. i guess i'm more posting this as a self reference so that i can debug this once i find time.

i had the same problem on a debian in debian systemd-nspawn. (i landed here via google)
The error message comes from systemd in the systemd-nspawn container.

core/main.c

if (arg_running_as == SYSTEMD_SYSTEM &&
            arg_action == ACTION_RUN &&
            running_in_chroot() > 0) {
                log_error("Cannot be run in a chroot() environment.");
                goto finish;
        }

shared/util.c

int running_in_chroot(void) {
        int ret;

        ret = files_same("/proc/1/root", "/");
        if (ret < 0)
                return ret;

        return ret == 0;
}

My problem was that the proc filesystem was mounted in the root directory of the container system.. I think deboostrap might let proc mounted in the destination. The fix is as simple as unmount the proc filesystem there.
```
umount ./DebianJessie/proc
````

Hopefully the next guy doesn't spend a couple of hours to find out whats wrong.

yes this workaround works.

Are there any updates to this issue, please?

I am not using that bootstrap stuff anymore so I am probably will not give any updates to that anymore.

I would close this issue since the workaround from @pfy works

The problem is still present and the workaround still works on 20.03.

Was this page helpful?
0 / 5 - 0 ratings