Raspberry Pi Zero boot speed
I enjoy working on embedded systems, but there’s a significant amount of work you have to do in getting the platform ready before getting to the more interesting business logic. The Raspberry Pi Zero W solves most of these problems: it’s small, has decent I/O, a decent price ($10 + $6 for storage + $4 for shipping) and runs full Linux so I can use my current language of choice.
One problem is boot speed. It’s common to power cycle an embedded project so a long boot time slows down the build/test cycle. A long boot time can also affect the safety of the system.
Because of this, I had a hack on the Raspbian boot time. The
.target units are boot milestones such as basics ready, filesystem
ready, and networking ready.
systemd-analyze plot shows where the
time went and what was running in parallel such as:
$ grep target boot-2.svg <text class="left" x="390.802" y="94.000">remote-fs-pre.target</text> <text class="left" x="391.128" y="114.000">cryptsetup.target</text>
As a bonus, the
x attribute is the time in centi-seconds the span
started which makes it easer to measure.
The biggest savings were through disabling unneeded services and
final boot order was:
- 2.70 s before userspace.
- 3.91 s is the earliest a no-dependency service can start. Useful for any safety response.
- 7.42 s to local-fs: filesystem is up and usable
- 7.94 s to basic
- 17.8 s to network up. Includes the wifi and DHCP time so network dependent.
Moving from ext4 to f2fs made no difference. There’s probably another 1 s to be saved through shrinking the kernel and, say, moving USB to a module so it can init later.
I switched to a custom kernel with no printk() and USB as a module. I also switched from the Debian services to things like systemd-timesyncd and disabling the Debian dhcpcd. Times now are:
- 0.80 s before userspace.
- 1.70 s is the earliest a no-dependency service can start. Useful for any safety response.
- 5.11 s to local-fs: filesystem is up and usable
- 5.88 s to basic
- 7.03 s to network - although it’s hard to tell if the network is up