making booting Linux more fun

I hope you're not tired of this dancing baby doll yet.

I hope you're not tired of this dancing baby doll yet.

Or another way to show your superiority over the “average Windows fan”.

Let's make friends between a modern meme and an old and almost forgotten instrument.

Background

If girls, after a difficult stage in life, do their hair in a bob, then software engineers reinstall the operating system on their home PC.

A difficult stage in my life did not happen, but I wanted to reinstall the system once again. And since I chose Arch Linux as the system, I decided to configure it as much as possible according to Feng Shui. The standard Gigabyte logo when booting the system did not meet my “feng shui” concepts, so I started looking for a solution and came across Plymouth.

What is Plymouth and what do you eat it with?

According to ArchWiki:

Plymouth is a Fedora project and one of the official projects freedesktop.orgwhich implements a graphical system boot screen without running text (logs) on the screen

Plymouth adds 2 binaries to your system:

  1. /sbin/plymouthd – “backend” Plymouth, writes logs, shows a splash screen;

  2. /bin/plymouth – “frontend” Plymouth, through it you can call various plymouthd actions;

and allows you to change the graphical system boot screen using the “theme” mechanism.

The Plymouth theme is a directory in /usr/share/plymouth/themes/which contains the following files:

  1. .plymouth (required) – the main theme file, through which plymouth understands the name of the theme, where the .script file (if any) and the directory with images are stored.

  2. .script – here the entire logic of the theme (if any) is described in a special language [8].

  3. .grub – additional bootloader script.

  4. Supporting files, usually images in the format .png

That is, using the Plymouth theme you can set any image/animation for the loading process. Sounds like exactly what we need, let's go install it!

Let's install!

I will show the installation process only for Arch + GRUB2 + GDM/GNOME. Installation on other distributions and configurations will be similar, or it will even be available out of the box (for example, Ubuntu).

  1. Installing the package

    yay -S plymouth-git
    Why AUR version?

    You can try using the version from the official repositories (pacman -S plymouth), but I couldn't get the theme to launch during boot.

  2. Configuring download parameters:

    1. Adding a parameter splash to kernel parameters to display graphical boot screen

    2. Adding a parameter quiet for silent booting

    /boot/grub/grub.cfg
    ...
    menuentry "Arch Linux" {
      ...
      linux ... quiet splash
      ...
    }
    ...
  3. Adding a hook plymouth in initramfs

    /etc/mkinitcpio.conf
    ...
    HOOKS = (... plymouth ...)
    ...
  4. Build the initramfs image and reboot the system

    # Запускать с правами root
    mkinitcpio -P && reboot
  5. ???

  6. PROFIT!

If only it were that simple… (aka Troubleshooting)

Usually the Plymouth installation goes smoothly, but if problems arise, I can recommend the following steps:

  1. Enable Plymouth debug logs

    /boot/grub/grub.cfg
    ...
    menuentry "Arch Linux" {
      ...
      linux ... quiet splash plymouth:debug
      ...
    }
    ...

    After the reboot the logs will appear in the file /var/log/plymouth-debug.log (updated after every restart)

  2. Carefully read the Tips&Tricks and Troubleshooting sections on ArchWiki

  3. Check that you have configured the proprietary drivers correctly NVIDIA

  4. We slow down the loading so that the animation has time to render

    An action that helped me launch my custom theme (more on that later).
    If systemd is available during Plymouth startup (as I understand, it is enough in /etc/mkinitcpio.conf replace hook udev on systemd), then you can make a service that will delay the system loading for n seconds so that the animation has time to be drawn.

    /etc/systemd/system/plymouth-wait-for-animation.service
    [Unit]
    Description=Waits for Plymouth animation to finish
    Before=plymouth-quit.service display-manager.service
    
    [Service]
    Type=oneshot
    ExecStart=/usr/bin/sleep animation_duration_in_secs
    
    [Install]
    WantedBy=plymouth-start.service
    

    Don't forget to enable the service: systemctl enable plymouth-wait-for-animation.service

Customization Time!

Phew, the hardest part is done, now you can start the creative process.

I came up with the idea to add a dancing baby raccoon to the loading process (yes, I'm a raccoon fan) from a popular meme on these tik toks of yours.

So let's get started! (Source)

  1. Create a directory for our new theme and its main files

    # Запускать с правами root
    mkdir /usr/share/plymouth/themes/pedro-raccoon
    cd /usr/share/plymouth/themes/pedro-raccoon
    touch pedro-raccoon.plymouth pedro-raccoon.script
  2. We describe pedro-raccoon.plymouth

    pedro-raccoon.plymouth
    [Plymouth Theme]
    Name=Pedro Raccoon Plymouth
    Description=Pedro Raccoon Meme Plymouth
    ModuleName=script
    
    [script]
    ImageDir=/usr/share/plymouth/themes/pedro-raccoon
    ScriptFile=/usr/share/plymouth/themes/pedro-raccoon/pedro-raccoon.script
    

    [Plymouth Theme] – Section that describes the meta information of the topic
    ModuleName – Didn’t find what other options there might be ModuleNamebut usually everyone puts the script
    [script] – Section that describes the meta information for the Plymouth script to work
    ImageDir – Root directory with images (for some reason everyone uses the root directory, I’m not sure if Plymouth can work with nested directories properly)

  3. Let's prepare a storyboard for the animation of our raccoon

    Suitable as a base image .gif or video file, I used .gif from here. We make a storyboard, for example, through ffmpeg:

    ffmpeg -i pedro-raccoon.gif animation-%d.png

    The resulting images must be placed in the root directory of images (along the path specified in ImageDir)

  4. Let's write a script:

    pedro-raccoon.script
    // Получаем настройки экрана
    screen.w = Window.GetWidth();
    screen.h = Window.GetHeight();
    screen.half.w = screen.w / 2;
    screen.half.h = screen.h / 2;
    
    // Подгружаем изображения для анимации
    images_count = 198;
    
    for (i = 0; i < images_count; ++i) {
        images[i] = Image("animation-" + (i + 1) + ".png");
    }
    
    // Plymouth рисует изображения, обёрнутые в объект Sprite
    // Готовим его и помещаем в центр экрана
    cur_sprite = Sprite();
    cur_sprite.SetX(screen.half.w - images[0].GetWidth() / 2);
    cur_sprite.SetY(screen.half.h - images[0].GetHeight() / 2);
    
    // Timestamp процесса отрисовки анимации 
    ts = 0;
    
    // Объявляем функцию для обновления экрана
    // Она будет вызываться до 50 раз в секунду
    fun update() {
        // Оборачиваем подгруженные изображения в Sprite
        // Цикл реализуем с помощью операции mod
        // Обратите внимания на костыль для замедления анимации (ts / 1.6)
        // Он нужен для того, чтобы наш енот танцевал не так быстро (значение подобрано эмпирически)
        cur_sprite.SetImage(images[Math.Int(ts / 1.6) % images_count]);
    
        ts++;   
    }
    
    Plymouth.SetRefreshFunction(update);
    
  5. Checking that everything is working

    # Запускать с правами root
    plymouth-set-default-theme -l
    
    bgrt
    details
    fade-in
    glow
    pedro-raccoon # <- Созданная нами тема
    script
    solar
    spinfinity
    spinner
    text
    tribar
    
    # Запускать с правами root
    plymouth-set-default-theme -R pedro-raccoon

    It is important to rebuild the initramfs image after installing the theme (flag -R does it automatically)

    Now let's start debugging Plymouth in the current tty:

    # Запускать с правами root
    plymouthd --debug --debug-file=/tmp/plymouth-debug-out ; plymouth --show-splash ; for ((I=0;I<10;I++)); do sleep 1 ; plymouth --update=event$I ; done ; plymouth --quit

    After running this command, you should see the Plymouth theme installed. If something went wrong, you can see it either in the console or in the file /tmp/plymouth-debug-out

  6. Reboot the system and see the beauty

Notes on Plymouth Script

  1. The language is similar in many ways to C and JS.

  2. Supports pictures (at least .png), but does not support .gif, video, sounds.

  3. Low popularity does not add to ease of use, but the language is quite simple.

  4. The language is powerful enough to, for example, write in it Tetris.

  5. Pay attention to the crutches for animation (slow down the animation)

Conclusion

With the proliferation of fast SSD drives, the system boot process on most devices takes a few seconds, which greatly reduces the relevance of Plymouth. Despite this, I still decided to sacrifice a couple of seconds of loading in order to make my system a little more friendly and a little less boring.

Unfortunately, I could not fit into this article all the “delights” that I encountered while I was setting up Plymouth and developing this topic, but most of them were related to my incomplete knowledge of Plymouth and Arch Linux in general .

Overall, I'm pleased with the result, and I hope that this article will draw attention to Plymouth and inspire someone to create interesting topics and uses for this tool and others like it.

Sources and links

  1. Article about Plymouth on ArchWiki

  2. Guide to installing proprietary NVIDIA drivers on Arch Linux

  3. Guide to creating your own Plymouth themes (Part 1)

  4. Guide to creating your own Plymouth themes (Part 2)

  5. Guide to creating your own Plymouth themes (Part 3)

  6. Guide to creating your own Plymouth themes (Part 4)

  7. Tetris on Plymouth

  8. Introduction to Plymouth Scripting Language

  9. Pedro Raccoon Plymouth Source Code

  10. Pedro Raccoon Plymouth on pling

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *