Tech article: how to have a very fast boot time with Raspberry Pi

by Joseph, on 2015 May 20th

First of all, if you're into music, and not especially interested in programming / Linux, etc., don't read this article.

Is it possible to have your Raspberry Pi app running less than 8 seconds after you plugged the power cord? Or less than 3 seconds after the Linux boot has started?

Yes. Proof:

How to do that?

It's simple: you need systemd, the new boot management system in Linux, instead of the previous standard sysvinit . It has now become the new standard on recent distributions like Raspbian Jessie, ArchLinux, etc.

Here is how to create a service that will run as soon as possible.

Just create a file /etc/systemd/system/samplerbox.service containing:

[Unit] Description=Starts SamplerBox DefaultDependencies=false # Very important! Without this line, the service # would wait until networking.service # has finished initialization. This could add 10 # more seconds because of DHCP, IP attribution, etc. [Service] Type=simple ExecStart=/root/SamplerBox/samplerbox.sh WorkingDirectory=/root/SamplerBox/ [Install] WantedBy=local-fs.target

and then do:

systemctl enable samplerbox

On next reboot, it will start!

Moreover, systemd has really great built-in tools to tune the boot time:

systemd-analyze will print the boot time,

systemd-analyze blame will print the list of the most time-consuming services in decreasing order! Just tune the first listed-services, and you will solve 80% of your boot time problem. Another great example of the Pareto principle.

systemd-analyze plot > plot.svg : this will display in a graphical way when all the services start. Really great. As it's a SVG file (you can view it in your browser), you can even CTRL+F and search where the relevant services are.