Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Boot command line argument to make OpenRC pause?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3390
Location: Rasi, Finland

PostPosted: Sat Mar 12, 2022 5:25 pm    Post subject: Boot command line argument to make OpenRC pause? Reply with quote

What's the (if any) command line argument, for kernel, to make OpenRC pause and wait for the famous anykey after each line/service started?
I'd then use the same argument for my custom initrd to make things consistent. Or can I do it via initrd when or before exec'ing switch_root?

Also note that I'm using openrc-init as init program here.

Thanks in advance.
_________________
..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
pingtoo
l33t
l33t


Joined: 10 Sep 2021
Posts: 963
Location: Richmond Hill, Canada

PostPosted: Sat Mar 12, 2022 6:55 pm    Post subject: Reply with quote

In /etc/rc.conf
Code:
# Global OpenRC configuration settings

# Set to "YES" if you want the rc system to try and start services
# in parallel for a slight speed improvement. When running in parallel we
# prefix the service output with its name as the output will get
# jumbled up.
# WARNING: whilst we have improved parallel, it can still potentially lock
# the boot process. Don't file bugs about this unless you can supply
# patches that fix it without breaking other things!
#rc_parallel="NO"

# Set rc_interactive to "YES" and you'll be able to press the I key during
# boot so you can choose to start specific services. Set to "NO" to disable
# this feature. This feature is automatically disabled if rc_parallel is
# set to YES.
#rc_interactive="YES"

# If we need to drop to a shell, you can specify it here.
# If not specified we use $SHELL, otherwise the one specified in /etc/passwd,
# otherwise /bin/sh
# Linux users could specify /sbin/sulogin
rc_shell=/sbin/sulogin
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3390
Location: Rasi, Finland

PostPosted: Sat Mar 12, 2022 7:00 pm    Post subject: Reply with quote

Well, looked everywhere but inside the config files. :P
But sadly this doesn't solve my issue. I need to be able to enable that via kernel command line or via initrd.
_________________
..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
pingtoo
l33t
l33t


Joined: 10 Sep 2021
Posts: 963
Location: Richmond Hill, Canada

PostPosted: Sat Mar 12, 2022 7:34 pm    Post subject: Reply with quote

Could you not invent a command line argument then before switch_root, but after mount root, do a change configuration value based on your command line argument setting?
Code:
# Handle kernel command-line parameters
CMDLINE=$(cat /proc/cmdline 2>/dev/null)
for x in ${CMDLINE}
do
        case "${x}" in
                interactive) INTERACTIVE=1;;
        esac
done

# Mount ${ROOT} ${CHROOT}

if [ "${INTERACTIVE}" = '1' ]
then
   echo 'rc_interactive="YES"' >> ${CHROOT}/etc/c.conf
fi

good_msg "Switching to real root: switch_root ${CHROOT} ${init} ${init_opts}"
exec switch_root "${CHROOT}" "${init}" ${init_opts}
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3390
Location: Rasi, Finland

PostPosted: Sat Mar 12, 2022 8:23 pm    Post subject: Reply with quote

I thought that. In fact that's the only way I know right now how to achieve that, but it feels so ugly way to accomplish it.
EDIT to add: Sadly this topic came on the first page of search results when I tried to search from the web.
_________________
..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
Leonardo.b
Guru
Guru


Joined: 10 Oct 2020
Posts: 302

PostPosted: Sat Mar 12, 2022 8:57 pm    Post subject: Reply with quote

Patch OpenRC.

rc.conf is sourced in sh/init.sh*.
As soon as /proc is avaiable, you can check the kernel command line and override "$rc_interactive".
It looks funny.
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3390
Location: Rasi, Finland

PostPosted: Sat Mar 12, 2022 9:23 pm    Post subject: Reply with quote

Thanks.
I looked at init.sh, and I can place .conf -file under /etc/rc.conf.d/. Since all the *.conf files there are directly sourced by /bin/sh (based on the shebang of init.sh) I can write my .conf file as a shell script which checks /proc/cmdline and then sets rc_interactive accordingly.

I'll test this in near future.
_________________
..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3390
Location: Rasi, Finland

PostPosted: Sun Mar 13, 2022 9:05 am    Post subject: Reply with quote

Well. My plan failed. :|
My guess is that OpenRC (upon the very beginning) reads /etc/rc.conf as a key-value config file and not as a shell script. Later when init scripts are being run /etc/rc.conf and /etc/rc.conf.d/* files are being sourced as shell scripts. I placed simple echo command there so I could see that these scripts are sourced many times during boot. This means placing any script code in the files will not be executed early enough to "inject" rc_interactive="YES" there.

Continuing digging for solution...
_________________
..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3390
Location: Rasi, Finland

PostPosted: Sun Mar 13, 2022 10:14 am    Post subject: Reply with quote

Snip of rc.c:
   if (!rc_yesno(getenv ("EINFO_QUIET")) &&
       rc_conf_yesno("rc_interactive"))
      printf("Press %sI%s to enter interactive boot mode\n\n",
          ecolor(ECOLOR_GOOD), ecolor(ECOLOR_NORMAL));
... suggest that OpenRC really only reads value of rc_interactive from the config file.
However (if this is even valid C code)
Code:
if (!rc_yesno(getenv ("EINFO_QUIET")) &&
       (rc_conf_yesno("rc_interactive")) || rc_proc_getent("rc_interactive") == "YES")
... could do it. So if one passes rc_interactive=YES on kernel command line, then OpenRC should go into interactive mode.

C programmers? Anyone? OpenRC devs? ;)

I should maybe open a bug for this.
_________________
..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
pingtoo
l33t
l33t


Joined: 10 Sep 2021
Posts: 963
Location: Richmond Hill, Canada

PostPosted: Sun Mar 13, 2022 1:58 pm    Post subject: Reply with quote

Zucca wrote:
However (if this is even valid C code)
Code:
if (!rc_yesno(getenv ("EINFO_QUIET")) &&
       (rc_conf_yesno("rc_interactive")) || rc_proc_getent("rc_interactive") == "YES")
... could do it. So if one passes rc_interactive=YES on kernel command line, then OpenRC should go into interactive mode.

C programmers? Anyone? OpenRC devs? ;)

I should maybe open a bug for this.


I think you need
Code:
if (!rc_yesno(getenv ("EINFO_QUIET")) &&
       (rc_conf_yesno("rc_interactive") || (strcmp(rc_proc_getent("rc_interactive"), "YES") == 0)


I have not written single line of C code for more than 20 years now, so I could be wrong in the code. But I know one thing for sure, the rc_proc_getent("rc_interactive") == "YES" will fail because rc_proc_gentent() return a char * pointer which will not be same as "YES"
Back to top
View user's profile Send private message
Leonardo.b
Guru
Guru


Joined: 10 Oct 2020
Posts: 302

PostPosted: Sun Mar 13, 2022 2:51 pm    Post subject: Reply with quote

This function in src/librc/librc-misc.c looks interesting:
Code:

/*
 * Override some specific rc.conf options on the kernel command line
 */
#ifdef __linux__
static RC_STRINGLIST *rc_config_override(RC_STRINGLIST *config)
{


Just a random comment; I don't know C enough to understand the code well. Let alone change it.
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3390
Location: Rasi, Finland

PostPosted: Sun Mar 13, 2022 4:25 pm    Post subject: Reply with quote

Looks like only rc_parallel can be changed via kernel command line:
Code:
rc_stringlist_add(overrides, "rc_parallel");
It should be rather easy to create a patch to add rc_interactive there too.
And I think that's the "right" place to patch it.
_________________
..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3390
Location: Rasi, Finland

PostPosted: Thu Aug 25, 2022 7:23 pm    Post subject: Reply with quote

During initramfsphase premounting /run (into the real root), creating openrc directory there and create empty file named interactive into mentioned directory will result OpenRC to enter interactive mode. I'd guess this is in no way official way. In fact it still seems like a hack.

I created a function into my custom initramfs and it works.
_________________
..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
dbtx
Tux's lil' helper
Tux's lil' helper


Joined: 20 Jan 2020
Posts: 117

PostPosted: Wed Aug 31, 2022 11:27 pm    Post subject: Reply with quote

Zucca wrote:
Looks like only rc_parallel can be changed via kernel command line:
Code:
rc_stringlist_add(overrides, "rc_parallel");
It should be rather easy to create a patch to add rc_interactive there too.
And I think that's the "right" place to patch it.


You're quite right-- it's nothing at all. This WorksForMe™:

Code:
# cat /etc/portage/patches/sys-apps/openrc/interactive_kcmdline.diff
--- a/src/librc/librc-misc.c   2022-08-30 06:29:21.380500006 -0400
+++ b/src/librc/librc-misc.c   2022-08-31 19:06:29.461856239 -0400
@@ -278,6 +278,7 @@

    /* A list of variables which may be overridden on the kernel command line */
    rc_stringlist_add(overrides, "rc_parallel");
+   rc_stringlist_add(overrides, "rc_interactive");

    TAILQ_FOREACH(override, overrides, entries) {
       varlen = strlen(override->value);


The commit message presents rc_parallel as an example. Maybe they only added the one because for everything else, YAGNI, and adding them as needed would be trivial anyway.
_________________
quasi-religious systemic wrongism pessimizes indiscriminately
Back to top
View user's profile Send private message
sam_
Developer
Developer


Joined: 14 Aug 2020
Posts: 1699

PostPosted: Thu May 11, 2023 2:03 am    Post subject: Reply with quote

I've landed this upstream now.
Back to top
View user's profile Send private message
skellr
l33t
l33t


Joined: 18 Jun 2005
Posts: 976
Location: The Village, Portmeirion

PostPosted: Thu May 11, 2023 3:03 am    Post subject: Reply with quote

sam_ wrote:
I've landed this upstream now.


Thank you!
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3390
Location: Rasi, Finland

PostPosted: Thu May 11, 2023 5:56 pm    Post subject: Reply with quote

Thanks sam!
I've been using a hack via initramfs: after rootfs is mounted then do an early mount of (tmpfs) /run under the new root and then basically
*snip*:
mkdir "${sysroot}/run/openrc"
touch "${sysroot}/run/openrc/interactive"
... which is not ideal.

EDIT
: D'oh! I told the same few posts earlier.
_________________
..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum