Markdown source

# How to implement a customized boot process with splash page and no messages in Debian Stretch

<abstract>
This article illustrates how to achieve a customized boot process with a boot image shown. 
A Debian Stretch lite operating system is assumed.
</abstract>

<div class="alert alert-danger">
  <h2><strong>Danger ahead !!</strong></h2><p>Many if not all, of suggestions contained in this article
  could, if misapplied, easily make your system unreachable or ill behaving in many unexpected ways.
  So, before you start to do changes on some system travelling on next ESA deep space probe or sitting 
  on Mt. Everest top, try them at home on a serial console equipped test system.
  <p>
  Moreover, keep in mind that when everything else fails, you can physically dismount the SD card and edit the offending files off-line. 
</div>

## How to hide all the boot messages and prompts

The first step is meant to get rid of all messages and prompts at the boot.

Edit the following files and carefully make the changes in **bold**.

<pre class="prettyprint">
sudo nano /boot/cmdline.txt 

dwc_otg.lpm_enable=0 console=serial1,115200 console=<b>tty3</b> root=PARTUUID=6b391ee6-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait <b>consoleblank=0 loglevel=3 quiet logo.nologo  vt.global_cursor_default=0</b>
</pre>

<pre class="prettyprint">
sudo nano /boot/config.txt 

<b># custom splash
disable_splash=1</b>
</pre>

Next run the following commands that remove the login prompt and Debian native screen saver: 

<pre class="prettyprint">
sudo systemctl disable getty@tty1
sudo systemctl mask plymouth-start.service
</pre>

Next reboot and check: you should see no messages anymore (black screen).

	sudo systemctl reboot


## Install and run a customized splash screen

Create under /home/pi an images/ directory and copy there the splash screen bitmap:

	cd
	mkdir images
	cp splash.png images/

Install the **fim** graphical utility that is able to copy a bitmap into the frame buffer memory area:

	sudo apt-get install fim
   
Create a dedicated service

    sudo systemctl edit boot-splashscreen-2.service --force

with the following contents:

<pre class="prettyprint">
[Unit]
Description=boot splash screen

DefaultDependencies=no
# Do not put here any After/Before clauses, just let systemd do its job !

[Service]

StandardInput=tty
StandardOutput=tty

ExecStart=/usr/bin/fim -q -a /home/pi/images/splash.png 

ExecStartPost=/bin/sleep 3

[Install]
WantedBy=<b>sysinit.target</b>
</pre>

Test the service 

	sudo systemctl start boot-splashscreen-2.service
   
enable the service

	sudo systemctl enable boot-splashscreen-2.service
   
 reboot to check everything is as expected:
 
	sudo systemctl reboot

What is expected is a full black screen at the start, after few seconds the 
splash screen is shown.
If you didn't configre any other grapphical application, it will stay there till
the next reboot/halt.

Using the following command we can verify that the boot 
splash panel has been started just whene we want.

<pre>
pi@cm3panel:~ $ sudo systemd-analyze critical-chain
</pre>

The boot splash is shown in <b style='color:red'>red</b> (bold mine),
just after local-fs.target and well before the achievement of sysinit, as per
its service file.

<pre>
graphical.target @13.296s
└─multi-user.target @13.295s
  └─ssh.service @13.046s +248ms
    └─network.target @13.039s
      └─dhcpcd.service @4.928s +8.109s
        └─basic.target @4.921s
          └─sockets.target @4.921s
            └─triggerhappy.socket @4.921s
              └─<b>sysinit.target</b> @4.920s
                └─systemd-timesyncd.service @4.678s +242ms
                  └─systemd-tmpfiles-setup.service @4.649s +23ms
                    └─<b style='color:red'>boot-splashscreen-2.service</b> @1.630s +3.015s
                      └─<b>local-fs.target</b> @1.616s
                        └─boot.mount @1.601s +14ms
                          └─systemd-fsck@dev-disk-by\x2dpartuuid-6b391ee6\x2d01.service @1.322s +274ms
                            └─dev-disk-by\x2dpartuuid-6b391ee6\x2d01.device @1.294s
</pre>


## What is delaying my bootstrap process ?

In case you need a very short boot time (e.g. if you are using the CM3-Panel as an appliance controller), 
the following suggestions could help

* Disable plymouth-* services
* Disable any other service not strictly needed (e.g. lightttpd)
* Put a static IP address instead of using DHCP client daemon (due to protocol mandatory timeout it takes up to 8 seconds to start)
* Disable avahi-daemon (due to protocol mandatory timeout it takes up to 8 seconds to start)

## dhcpcd.service is lasting forever, how can I speedup it?

In the current Raspbian lite images, the dhcpcd.service has a so-called 
drop-in file, i.e. a file that is changing the package prrovided
systemd .service file.
Specifically, the option -w is getting added: it causes the process dhcpcd to wait
till all the interfaces achieve an IP address.

<pre>
$ sudo systemctl cat dhcpcd.service 

# /lib/systemd/system/dhcpcd.service
[Unit]
Description=dhcpcd on all interfaces
Wants=network.target
Before=network.target

[Service]
Type=forking
PIDFile=/run/dhcpcd.pid
ExecStart=/usr/lib/dhcpcd5/dhcpcd -q -b
ExecStop=/sbin/dhcpcd -x

[Install]
WantedBy=multi-user.target
Alias=dhcpcd5.service

# /etc/systemd/system/dhcpcd.service.d/wait.conf
[Service]
ExecStart=
ExecStart=/usr/lib/dhcpcd5/dhcpcd -q <b>-w</b>
</pre>

Removing that option the service is able to start in less than one second instead of 12.
Of course, that could even trigger anomalous behavior, so it is advisable to use this 
configuration only on systems where the network services are not critical to the appliance working.

## Links

* [How to make a splash screen last longer?](https://www.raspberrypi.org/forums/viewtopic.php?t=195227)
* [Debian plymouth](https://wiki.debian.org/plymouth)
* [Guide: A custom splash screen on the Raspberry Pi, for Raspbian Jessie (The XBone, part 1)](https://yingtongli.me/blog/2016/12/21/splash.html)
* [Custom boot up screen](https://raspberry-projects.com/pi/pi-operating-systems/raspbian/custom-boot-up-screen)
* [Running a splash screen, shutting down screens and an IoT product service with Python on Raspberry Pi](https://www.madebymany.com/stories/fun-with-systemd-running-a-splash-screen-shutting-down-screens-and-an-iot-product-service-with-python-on-raspberry-pi)
* [How do I change the splash screen? RPi3Bv1.2 Jessie](https://www.raspberrypi.org/forums/viewtopic.php?t=184043)
* [Silent boot on Raspbian Stretch in Console](Mode https://scribles.net/silent-boot-on-raspbian-stretch-in-console-mode/)
* [Plymouth](https://wiki.archlinux.org/index.php/plymouth)
* [Raspberry Pi early boot splash / logo screen](http://blog.fraggod.net/2015/11/28/raspberry-pi-early-boot-splash-logo-screen.html)
* [Fixed splash screen with network information after Raspbian Boot](https://devjournal.eu/raspberry-pi-fixed-splash-screen-after-boot-d171fce6e167)
* [Guide: A custom splash screen on the Raspberry Pi, for Raspbian Jessie (The XBone, part 1)](https://yingtongli.me/blog/2016/12/21/splash.html)
* [I ❤️ systemd: Running a splash screen, shutting down screens and an IoT product service with Python on Raspberry PI]( https://www.madebymany.com/stories/fun-with-systemd-running-a-splash-screen-shutting-down-screens-and-an-iot-product-service-with-python-on-raspberry-pi)



@include='bio_andrea_montefusco'