You are not logged in.

#1 2023-02-05 20:49:57

EdsLx
Member
Registered: 2023-02-01
Posts: 17

[SOLVED] Colorizing custom boot messages

I wanted to make a custom boot message saying "Welcome to Arch Linux!" because I want to have that on the booting screen, but not the init messages and the "Arch Linux" in another color. So I enabled (actually it was already enabled smile) quiet boot and managed to add my custom boot message. But now I'm stuck at the color. How can I colorize this part of my boot message text? I've read that ANSI is supported, but I've never worked with that before and thus I don't know how to include that, and I can't find anything helpful when researching for this particular situation. I'd be very thankful for any kind of help smile
Greetings
EdsLx

Last edited by EdsLx (2023-02-06 18:51:49)

Offline

#2 2023-02-05 21:13:41

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 9,003
Website

Re: [SOLVED] Colorizing custom boot messages

This works for me in /etc/issue:

Welcome to \e{lightmagenta}Arch Linux!\e{reset}

See also agetty(1).

EDIT: hold on, that's not what you mean, is it? Please provide the exact steps taken so far, your vague description is too ambiguous, at least for me. Which bootloader are you using?

Last edited by Head_on_a_Stick (2023-02-05 21:22:39)


Jin, Jîyan, Azadî

Offline

#3 2023-02-05 21:33:30

EdsLx
Member
Registered: 2023-02-01
Posts: 17

Re: [SOLVED] Colorizing custom boot messages

EDIT: hold on, that's not what you mean, is it? Please provide the exact steps taken so far, your vague description is too ambiguous, at least for me. Which bootloader are you using?

I've created files in /etc/initcpio/hooks and /etc/initcpio/install and I created a file named bootmsg in /etc. I also appended bootmsg to the HOOKS array in /etc/mkinitcpio.conf and then used the command

sudo mkinitcpio -P

This got the boot message on my booting screen. Now I try to colorize the "Arch Linux" in the output, but have no idea how to do that, which is my problem.
I use Grub and can post the content of the mentioned files if necessary.

Last edited by EdsLx (2023-02-05 21:34:28)

Offline

#4 2023-02-05 22:24:52

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 9,003
Website

Re: [SOLVED] Colorizing custom boot messages

Please provide the hook, the install file, /etc/bootmsg and the GRUB files. Thanks.

I'll be afk until tomorrow though, or maybe later.


Jin, Jîyan, Azadî

Offline

#5 2023-02-06 08:30:54

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,387

Re: [SOLVED] Colorizing custom boot messages

/etc/bootmsg is so hyperspecific that the OP probably got it from https://www.reddit.com/r/linuxquestions … e_on_boot/

The thread also explains that "Welcome to Arch Linux!" comes from systemd: https://cgit.freedesktop.org/systemd/sy … in.c#n1214
You can edit the ansi colors and text in /etc/os-release

Offline

#6 2023-02-06 10:49:04

EdsLx
Member
Registered: 2023-02-01
Posts: 17

Re: [SOLVED] Colorizing custom boot messages

seth wrote:

/etc/bootmsg is so hyperspecific that the OP probably got it from https://www.reddit.com/r/linuxquestions … e_on_boot/

Yes, this is exactly what I've used to get my boot message displayed, and I pretty much just pasted the contents of the files on the website into the files I've created (except for /etc/bootmsg).

seth wrote:

The thread also explains that "Welcome to Arch Linux!" comes from systemd: https://cgit.freedesktop.org/systemd/sy … in.c#n1214

Well, I didn't quite catch that part...

seth wrote:

You can edit the ansi colors and text in /etc/os-release

Doesn't that just change how the "Arch Linux" is displayed when quiet boot is disabled? But I don't want the init messages being displayed, this is why I used a custom boot message. Do you now any other way of doing that? But even if there was another way, I'd still wanted to know how to colorize boot messages, because with them, I can write whatever I want wink

Head_on_a_Stick wrote:

Please provide the hook, the install file, /etc/bootmsg and the GRUB files. Thanks.

/etc/initcpio/hooks/bootmsg:

#!/usr/bin/ash

run_hook() {
  cat /etc/bootmsg
}

/etc/initcpio/install/bootmsg:

#!/usr/bin/ash

build() {
  add_file /etc/bootmsg && add_runscript
}

help() {
  cat <<HELPEOF
This hooks allows to output an arbitrary boot message.
HELPEOF
}

/etc/bootmsg:

Welcome to Arch Linux!

Which GRUB files do you need exactly?

Greetings
EdsLx

Offline

#7 2023-02-06 14:48:26

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,387

Re: [SOLVED] Colorizing custom boot messages

cat isn't gonna handle escape sequences, try

printf "$(cat /etc/bootmsg)"

(Trilby might know whether there's a cat-free variant for this on ash) or print the desired message directly.

printcolors.sh I somewhen stole together from the internet.

#!/bin/sh

if [ "$1" = "256" ]; then
    for fgbg in 38 48 ; do # Foreground / Background
        echo "\\e[${fgbg};5;<number>m"
        for color in {0..255} ; do # Colors
            # Display the color
            printf "\e[${fgbg};5;%sm  %3s  \e[0m" $color $color
            # Display 16 colors per lines
            if [ $((($color + 1) % 16)) == 0 ] ; then
                echo # New line
            fi
        done
        echo # New line
    done
else
    for x in 0 1 4 5 7 8; do
        for i in {30..37}; do
            for a in {40..47}; do
                printf "\e[$x;$i;$a""m\\\e[$x;$i;$a""m\e[0;37;40m "
            done
            echo
        done
    done
    echo
fi

Offline

#8 2023-02-06 17:21:55

EdsLx
Member
Registered: 2023-02-01
Posts: 17

Re: [SOLVED] Colorizing custom boot messages

seth wrote:

cat isn't gonna handle escape sequences, try

printf "$(cat /etc/bootmsg)"

It didn't work, but that might be because I'm using the Ansi escape codes in a wrong way. This is how I try to include them (content of /etc/bootmsg):

Welcome to \u001b[35mArch Linux\u001b[0m!

I don't know if that's correct because as I've already mentioned, I've never worked with Ansi before.

seth wrote:

printcolors.sh I somewhen stole together from the internet.

#!/bin/sh

if [ "$1" = "256" ]; then
    for fgbg in 38 48 ; do # Foreground / Background
        echo "\\e[${fgbg};5;<number>m"
        for color in {0..255} ; do # Colors
            # Display the color
            printf "\e[${fgbg};5;%sm  %3s  \e[0m" $color $color
            # Display 16 colors per lines
            if [ $((($color + 1) % 16)) == 0 ] ; then
                echo # New line
            fi
        done
        echo # New line
    done
else
    for x in 0 1 4 5 7 8; do
        for i in {30..37}; do
            for a in {40..47}; do
                printf "\e[$x;$i;$a""m\\\e[$x;$i;$a""m\e[0;37;40m "
            done
            echo
        done
    done
    echo
fi

I don't quite understand that. Where does that file belong to? (sorry for being so newbie, I'm pretty new to Linux)

Greetings
EdsLx

Offline

#9 2023-02-06 17:30:19

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,387

Re: [SOLVED] Colorizing custom boot messages

You can save that file wherever you want, chmod +x and run it.
It'll print the color escape sequences you can use.
"\e[0m" resets to default.

Offline

#10 2023-02-06 18:15:45

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 9,003
Website

Re: [SOLVED] Colorizing custom boot messages

Try this in /etc/initcpio/hooks/bootmsg (no need for /etc/bootmsg in this case):

#!/usr/bin/ash

run_hook() {
   printf 'Welcome to \e[35;1mArch Linux\e[0m!\n'
}

That's the shorthand version :-)

ANSI codes here: https://gist.github.com/fnky/458719343a … a4f7296797

EDIT: used bold code instead of aixterm spec.

Last edited by Head_on_a_Stick (2023-02-06 18:21:52)


Jin, Jîyan, Azadî

Offline

#11 2023-02-06 18:51:06

EdsLx
Member
Registered: 2023-02-01
Posts: 17

Re: [SOLVED] Colorizing custom boot messages

Head_on_a_Stick wrote:

Try this in /etc/initcpio/hooks/bootmsg (no need for /etc/bootmsg in this case):

#!/usr/bin/ash

run_hook() {
   printf 'Welcome to \e[35;1mArch Linux\e[0m!\n'
}

That's the shorthand version :-)

ANSI codes here: https://gist.github.com/fnky/458719343a … a4f7296797

EDIT: used bold code instead of aixterm spec.

That worked, thanks a lot!

Offline

Board footer

Powered by FluxBB