Skip to main content

Solutions when Termux proot cannot use the systemctl command

·
Categories Smartphones Termux Tutorials
Tags Systemd Proot-Distro Chroot OpenRC Runit
Table of Contents

Systemd is an init program. Almost all Linux distributions use Systemd to manage system services, and common commands include systemctl, journalctl, and so on.

However, Termux cannot use Systemd. If you run commands related to systemctl start inside a Termux proot-distro or chroot container environment, you will see this error: System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down

This is because the container environment does not support Systemd.

There is actually no real solution, unless the Termux development team learns from Microsoft WSL and finds a way to make Systemd run. However, we do have some alternatives to address this problem.

Method 1: Start the program directly from the executable path
#

First, understand that Systemd is just an init program for managing system services. It is responsible for starting programs after Linux boots and letting users turn programs on and off. But simply starting a program does not actually require systemctl.

  1. For example, to start the SSH service in proot Debian, the Systemd way is to run the following command:
sudo systemctl start sshd
  1. If we find Systemd’s service file /etc/systemd/system/sshd.service (most Systemd service files are here), we will see that what follows ExecStart= is the command it really executes:
[Service]
EnvironmentFile=-/etc/default/ssh
ExecStartPre=/usr/sbin/sshd -t
ExecStart=/usr/sbin/sshd -D
  1. Therefore, the SSH service can be started directly with this command and run in the background:
mkdir -p /run/sshd

/usr/sbin/sshd -D

Note: programs inside Termux proot-distro cannot use ports below 1000. When logging in to proot-distro, add the --fix-low-ports parameter to redirect SSH port 22 to 2022.

If you want to automatically start a specific program after logging in to proot-distro, the simplest way is to add the command you want to run to ~/.bashrc in the user’s home directory.

Method 2: Switch to a distribution that uses OpenRC
#

OpenRC and runit are more traditional init programs. They are not as complex as Systemd, and they can run and manage services in proot. Users unfamiliar with OpenRC commands can refer to the Systemd and OpenRC command comparison table below.

At present, the proot-distro distribution that uses OpenRC is Alpine Linux, while Artix Linux and Void Linux use runit.

  1. Install Alpine Linux
proot-distro install alpine
proot-distro login alpine
  1. Install the OpenRC package
apk add openrc
  1. After that, append this command when logging in to proot, and the OpenRC program will start
proot-distro login alpine --fix-low-ports -- /bin/ash -c "/sbin/openrc default; /bin/ash -l"
  1. After that, you can use OpenRC to manage services. For example, SSH can be managed with the rc-service command, without typing the executable path
sudo rc-service sshd start
  1. You can also configure the SSH service to start automatically after logging in to proot-distro.
sudo rc-update add sshd

Method 3: Run a full Linux system virtual machine
#

The ultimate solution is to emulate a full Linux system so that Systemd can run.

See Termux QEMU Ubuntu VM

The drawback of this method, however, is that it is too slow. Without KVM acceleration, QEMU’s execution efficiency is extremely poor.

References
#

Related


Thank you for reading. Public comments are not available on this website. I write to explore ideas honestly, not to chase social engagement or traffic. I would be glad to hear your thoughts after reading the article with care. If you found any errors, technical issues, or would like to share feedback, feel free to contact me via the email listed on the About page.