3 ms·
you know, I just wanted to run services from within the chroot, like you could do in the pre-systemd era. I mean, as long as you have /proc, /sys and etc bind-
by znpy 7y ago
you know, I just wanted to run services from within the chroot, like you could do in the pre-systemd era.
I mean, as long as you have /proc, /sys and etc bind-mounted you should be okay, right ?
- Spivak 7y agoRight, but what you're describing as running a pre-systemd "service" is really just "run a shell script that sources some environment files and then double forks". Running a systemd service means talking to the /org/freedesktop/systemd1 object on the system bus typically listening on /run/dbus/system_bus_socket and asking it to start your service. This is all that systemctl really does. mkdir ./rootfs curl -O https://cloud-images.ubuntu.com/minimal/releases/bionic/release/ubuntu-18.04-minimal-cloudimg-amd64-root.tar.xz | tar -xJPC ./rootfs mount -o bind /proc ./rootfs/proc mount -o bind /sys ./rootfs/sys mkdir ./rootfs/run/dbus mkdir ./rootfs/run/systemd mount -o bind /run/dbus ./rootfs/dbus mount -o bind /run/systemd ./rootfs/systemd chroot ./rootfs bash # See that it works just by sending dbus messages. dbus-send --system --print-reply --type=method_call --dest=org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager.ListUnits # Now do the same with systemctl. export SYSTEMD_IGNORE_CHROOT=true systemctl list-units THIS IS ALMOST CERTAINLY NOT WHAT YOU WANT. You're just talking to the host systemd. You won't see any of the services in your chroot since how could systemd know about them? Your chrooted root is also now just root on the host. Just use systemd-nspawn. # undo all the bind mount junk. chroot ./rootfs bash useradd ubuntu -G sudo passwd ubuntu exit cd ./rootfs systemd-nspawn -x --private-network --boot # login sudo systemctl list-units
- zymhan 7y agoThis was very informative, thank you.