[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Hyper-typematic and Firefox responsiveness in Weston.



On Tue, 4 Jan 2022 at 08:42, David Wright <deblis@lionunicorn.co.uk> wrote:
> On Mon 03 Jan 2022 at 16:25:47 (+1100), David wrote:

> > So I now run 'kbdrate' inside the initrd. This seems to have
> > solved the problem there and in all subsequent layers.

> I presume you do this by placing something like
>   /sbin/kbdrate -r 8 -d 500 -s
> ± a shebang, into a file like
>   /etc/initramfs-tools/scripts/<something>/kbdrate.sh
> Which <something> is appropriate?

Hi David,

Well, you are on the right track, but it did take quite a bit more
thinking than that for me, because I had to ensure that it ran ahead
of the interactive cryptsetup password prompt script in the initrd,
which was the tricky aspect.

But it all came together quite easily. And that particular issue
might be irrelevant for you, but I will explain it anyway to demystify
some details in the scripts that I share below. And it answers your question.

Anyway, I'm glad you responded to my hint and I encourage you to try it.

See 'man initramfs-tools' for the details.

Aside: everywhere I'm using '/usr/sbin/kbdrate' your system may or may
not require that string to be changed to '/sbin/kbdrate' in any or all
places I give below. You can use a boot parameter 'break=top' to
examine the initrd environment. If I do that, '/sbin' and '/usr/sbin'
contents look the same and
  # echo $PATH
  /sbin:/usr/sbin:/bin/:/usr/bin
so I don't think it matters much. I think maybe I did just specify
'/usr/sbin' in anticipation of the future. The only detail that I have
forgotten is if there is some reason why I have used '/sbin/kbdrate'
in script #2 below. I can't remember.

Anyway, let's talk about the two main steps taken from 'man
initramfs-tools':
Step #1: make '/usr/sbin/kbdrate' available in the initrd filesystem.
Step #2: a script to run '/usr/sbin/kbdrate' at the right time, with
the desired arguments.

Step #1:

is done with what the manpage calls a "configuration hook script".

These contain some boilerplate that I figured out by looking at other
similar scripts in /usr/share/initramfs-tools/hooks, and I came up
with this:

#-------------------------------------------------------
$ sudo cat /etc/initramfs-tools/hooks/my_kbdrate
#!/bin/sh
set -e
PREREQ=""
prereqs()
{
    echo "$PREREQ"
}
case "$1" in
    prereqs)
        prereqs
        exit 0
        ;;
esac
. /usr/share/initramfs-tools/hook-functions
# Hooks for loading kbdrate software into the initramfs
copy_exec /sbin/kbdrate
exit 0
$
#-------------------------------------------------------

The only line of real interest in that script is the 'copy_exec'
statement. And 'copy_exec' is in the 'hook-functions' file sourced in
the statement before. The rest is boilerplate that does nothing
in this case.

Once this is in place, I can use a boot parameter 'break=top'
to confirm that '/usr/sbin/kbrate' is installed in the initrd.

Step #2:

is done with what the manpage calls a "boot script" and this is what I
came up with:
#-------------------------------------------------------
$ sudo cat /usr/share/initramfs-tools/scripts/local-top/my_kbdrate
#!/bin/sh
PREREQ=""
prereqs()
{
    echo "$PREREQ"
}
case $1 in
# get pre-requisites
prereqs)
    prereqs
    exit 0
    ;;
esac
f="/usr/sbin/kbdrate"
if [ -x "${f}" ]; then
    "${f}" -d 700 -r 20 >/dev/null
fi
$
#-------------------------------------------------------

There are a couple of unexpected aspects to script #2, which I will
explain ...

a) Script sequencing

or "Why has he put it under /usr ?"

All the PREREQ= and prereqs stuff is a mechanism to control the
sequencing of scripts in each subdirectory under
'*/initramfs-toos/scripts/'.

How to use that mechanism will depend on how the other scripts present
are already using it. Above I left it unused because I had to use a
different approach, so PREREQ was irrelevant and I never assigned it
any values. This seems common in other scripts too, when order does
not matter.

For my situation it was essential to ensure that Step #2 ran before
the interactive cryptsetup password prompt script in the initrd.

So I had to take note of where that occurs in the whole sequence of
different subdirectories, and ensure that my script ran before.

And a complicating factor is that 'man initramfs-tools' says:

  Please notice that PREREQ is only honored inside a single directory.
  So first the scripts in /usr/share/initramfs-tools are ordered
  according to their PREREQ values and executed. Then all scripts in
  /etc/initramfs-tools are ordered according to their PREREQ values and
  executed. This mean that currently there is no possibility to have a
  local script (/etc/initramfs-tools) get executed before one from the
  package (/usr/share/initramfs-tools).

Note the last sentence. Even though I suspect it ambiguously
overstates the problem, that explains why my script *must* be placed
in '/usr/..../local-top' subdirectory and not under /etc as would be
more desirable. I could not see any way to have it under /etc and
be sure that it would run early enough. I tried that, and it worked.

b) '/usr/sbin/kbdrate' options

Even though 'man kbdrate' says that '-s' does "No messages are
printed", this turns out to be untrue. So I used >/dev/null
instead.

And, after all that, it works \o/

ps: Happy New Year to all list readers :)


Reply to: