Drop-in directory to run scripts before rc.local?

Qubes docs and qubes-issues suggests the following possibility:

/rw/config/rc.local.d/*.rc - scripts run at VM startup just before /rw/config/rc.local

After creating this directory and placing (executable) test scripts there, without success, a little digging suggested that this setup requires installing the qubes-core-agent-linux package. However, this package is missing from the qubes repositories and appears to conflict with qubes-core-agent.

apt-cache show qubes-core-agent
Package: qubes-core-agent
Version: 4.2.42-1+deb12u1 ...
Conflicts: qubes-core-agent-linux

So I’m left wondering, is this really possible in r4.2? If so, how should one go about setting it up?

1 Like

Related:
From Qubes docs:

/rw/config/rc.local-early.d/*.rc, /rw/config/rc.local-early - scripts similar to /rw/config/rc.local, but running earlier in the system startup sequence - just before sysinit.target, and setting up the network.

and forum:

It looks like you don’t need the qubes-core-agent-linux package to get it.
Check the following script and see if you have the following code:

/usr/lib/qubes/init/misc-post.sh
[...]
for rc in /rw/config/rc.local.d/*.rc /rw/config/rc.local; do
    [ -f "${rc}" ] || continue
    [ -x "${rc}" ] || continue
    "${rc}"
done
[...]

If so, check the service responsible for executing that part and look for any errors:

sudo journalctl -b -u qubes-misc-post.service

Thanks for the helpful response. Looks like I have the correct setup- the code exists and there aren’t any suspicious errors.

Is your .rc file executable?
I tested with a file in /rw/config/rc.local.d/test.rc and it worked on my side with a simple echo "test" inside.

yes. The script works fine when I execute it manually. For reference, I used test.rc with

#!/bin/sh

echo "123" > abc.txt

That’s strange, mine works fine when I reboot the qube:

$ cat /rw/config/rc.local.d/test.rc 
#!/bin/sh

echo "TEST"
$ ls -l /rw/config/rc.local.d/test.rc 
-rwxr-xr-x 1 root root 23 May 24 18:26 /rw/config/rc.local.d/test.rc
$ sudo journalctl -b -u qubes-misc-post
systemd[1]: Starting qubes-misc-post.service - Qubes misc post-boot actions...
misc-post.sh[641]: TEST
systemd[1]: Finished qubes-misc-post.service - Qubes misc post-boot actions.

To make sure the issue isn’t with the qube itself, could you try using a different one?

I already tried in a different qube, with the same result. But now that I know it’s possible I’ll keep digging to see if I can identify the problem. The permissions and ownership of my test.rc are identical to yours…

I was able to successfully replicate your test! So the problem appears to be with trying to automatically run a script that creates a new file in the directory. Running my script manually created the file abc.txt, but this file was not created automatically when restarting the qube.

Since the script is run by root and you didn’t specify a path for the file, I would guess that it’s in the root (/) directory. Have you checked there?

I didn’t find anything in the root directory, but the path did need to be specified! I was successful with the following test.rc script:

#!/bin/sh

echo "123" > /rw/config/rc.local.d/abc.txt

Live and learn! Thanks for your help, which led me to the issue much faster than I could have accomplished on my own.

1 Like