Recently encountered a problem: when entering init 1, it gives an error: init: must be run as PID 1. I Entering ps and it turns out that /sbin/init has PID 1. How now can I use init?
- 27,473
- 9
- 58
- 102
- 5
- 1
- 6
-
2*"use `init`"* to do what, exactly? – steeldriver Jan 18 '20 at 18:14
-
Have you tried `telinit`? systemd manual says that its `init` will forward to `telinit` if PID is not 1 (not being init, but being used to message init). – ctrl-alt-delor Jan 18 '20 at 18:16
-
`command not found: telinit` – thedimas3007 Jan 18 '20 at 18:18
-
What OS are you running? – Paulo Tomé Jan 18 '20 at 18:19
-
I'm running Alpine linux – thedimas3007 Jan 18 '20 at 18:19
-
What are you trying to do? – Kusalananda Jan 18 '20 at 18:20
-
1Switch system to a single-user mode – thedimas3007 Jan 18 '20 at 18:23
-
1try `rc single` if alpine is still using openrc that might work, ... https://wiki.alpinelinux.org/wiki/Alpine_Linux_Init_System – frostschutz Jan 18 '20 at 18:26
-
Thanks, it's working – thedimas3007 Jan 18 '20 at 18:30
-
A related question, for a systemd operating system, is https://unix.stackexchange.com/q/389289/5132 . – JdeBP Jan 18 '20 at 19:13
1 Answers
You cannot use init. It is the wrong program for the job.
You need to un-learn the idea that init can be invoked as a normal command. The init programs where this is/was true are not the init program that you have. There are 4 init programs where one can invoke it as a normal command, and you are not using any of them. Rather, you are using BusyBox init, which if it detects that it has been invoked as anything other than process #1 on the system, prints that message and exits. It has no functionality for other than as process #1.
There is no telinit in BusyBox, either. Its init does not have a client/server interface over a FIFO.
To shut down, you must do something that eventually results in SIGPWR, SIGUSR1, SIGUSR2, or SIGTERM being sent to process #1. Note that, as with other system management toolsets, "single-user mode" (a misnomer since 1995) is not a shutdown target. One does not shut down to such a mode, and BusyBox init is not actually involved in enacting such a mode.
Rather, in systems using OpenRC on top of BusyBox init, this is a mode that is entirely the province of OpenRC mechanisms. openrc single changes to the mis-named "single" mode. (Using OpenRC's own init, which is not the case for you, there is a shutdown command that talks to it. But that's just a quite roundabout way of running openrc single, it turns out.)
Alpine Linux is documenting an outdated OpenRC, note. OpenRC itself does not have a single directory any more. That was removed in 2019. Furthermore, the rc command changed to openrc in 2014.
Further reading
- 66,967
- 12
- 159
- 343