<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>OpenRC on Ivon's Blog</title><link>https://ivonblog.com/en-us/tags/openrc/</link><description>Recent content in OpenRC on Ivon's Blog</description><generator>Hugo -- gohugo.io</generator><language>en</language><managingEditor>infoivonblog.nkfjt@aleeas.com (Ivon Huang)</managingEditor><webMaster>infoivonblog.nkfjt@aleeas.com (Ivon Huang)</webMaster><copyright>You are welcome to share articles of Ivon's Blog (ivonblog.com). Please include the original URL when citing articles, and abide by CC BY-NC-ND 4.0 license. For commercial use, please write an e-mail to me.</copyright><lastBuildDate>Sat, 31 Aug 2024 23:00:00 +0800</lastBuildDate><atom:link href="https://ivonblog.com/en-us/tags/openrc/index.xml" rel="self" type="application/rss+xml"/><item><title>Solutions when Termux proot cannot use the systemctl command</title><link>https://ivonblog.com/en-us/posts/termux-systemd-issues/</link><pubDate>Sat, 31 Aug 2024 23:00:00 +0800</pubDate><author>infoivonblog.nkfjt@aleeas.com (Ivon Huang)</author><guid>https://ivonblog.com/en-us/posts/termux-systemd-issues/</guid><description>&lt;!-- Co-translated by ChatGPT --&gt;
&lt;p&gt;Systemd is an init program. Almost all Linux distributions use Systemd to manage system services, and common commands include &lt;code&gt;systemctl&lt;/code&gt;, &lt;code&gt;journalctl&lt;/code&gt;, and so on.&lt;/p&gt;
&lt;p&gt;However, Termux cannot use Systemd. If you run commands related to &lt;code&gt;systemctl start&lt;/code&gt; inside a Termux proot-distro or chroot container environment, you will see this error: &lt;code&gt;System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;This is because the container environment does not support Systemd.&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;

&lt;h2 class="relative group"&gt;Method 1: Start the program directly from the executable path
 &lt;div id="method-1-start-the-program-directly-from-the-executable-path" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#method-1-start-the-program-directly-from-the-executable-path" aria-label="Anchor"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h2&gt;
&lt;p&gt;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 &lt;code&gt;systemctl&lt;/code&gt;.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;For example, to start the SSH service in proot Debian, the Systemd way is to run the following command:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo systemctl start sshd&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;ol start="2"&gt;
&lt;li&gt;If we find Systemd&amp;rsquo;s service file &lt;code&gt;/etc/systemd/system/sshd.service&lt;/code&gt; (most Systemd service files are here), we will see that what follows &lt;code&gt;ExecStart=&lt;/code&gt; is the command it really executes:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="o"&gt;[&lt;/span&gt;Service&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nv"&gt;EnvironmentFile&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;-/etc/default/ssh
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nv"&gt;ExecStartPre&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/usr/sbin/sshd -t
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nv"&gt;ExecStart&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/usr/sbin/sshd -D&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;ol start="3"&gt;
&lt;li&gt;Therefore, the SSH service can be started directly with this command and run in the background:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;mkdir -p /run/sshd
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;/usr/sbin/sshd -D&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Note: programs inside Termux proot-distro cannot use ports below 1000. When logging in to proot-distro, add the &lt;code&gt;--fix-low-ports&lt;/code&gt; parameter to redirect SSH port 22 to 2022.&lt;/p&gt;
&lt;p&gt;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 &lt;code&gt;~/.bashrc&lt;/code&gt; in the user&amp;rsquo;s home directory.&lt;/p&gt;

&lt;h2 class="relative group"&gt;Method 2: Switch to a distribution that uses OpenRC
 &lt;div id="method-2-switch-to-a-distribution-that-uses-openrc" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#method-2-switch-to-a-distribution-that-uses-openrc" aria-label="Anchor"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h2&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;At present, the proot-distro distribution that uses OpenRC is Alpine Linux, while Artix Linux and Void Linux use runit.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Install Alpine Linux&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;proot-distro install alpine
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;proot-distro login alpine&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;ol start="2"&gt;
&lt;li&gt;Install the OpenRC package&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;apk add openrc&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;ol start="3"&gt;
&lt;li&gt;After that, append this command when logging in to proot, and the OpenRC program will start&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;proot-distro login alpine --fix-low-ports -- /bin/ash -c &lt;span class="s2"&gt;&amp;#34;/sbin/openrc default; /bin/ash -l&amp;#34;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;ol start="4"&gt;
&lt;li&gt;After that, you can use OpenRC to manage services. For example, SSH can be managed with the &lt;code&gt;rc-service&lt;/code&gt; command, without typing the executable path&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo rc-service sshd start&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;ol start="5"&gt;
&lt;li&gt;You can also configure the SSH service to start automatically after logging in to proot-distro.&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo rc-update add sshd&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 class="relative group"&gt;Method 3: Run a full Linux system virtual machine
 &lt;div id="method-3-run-a-full-linux-system-virtual-machine" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#method-3-run-a-full-linux-system-virtual-machine" aria-label="Anchor"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h2&gt;
&lt;p&gt;The ultimate solution is to emulate a full Linux system so that Systemd can run.&lt;/p&gt;</description></item></channel></rss>