biglesp
Posts: 3
Joined: Fri Jun 12, 2020 1:43 pm

Shortening the boot time of a Raspberry Pi 4

Fri Jun 12, 2020 1:54 pm

Hello, I'm Les Pounder, better known as @biglesp on Twitter. https://twitter.com/biglesp
In a former life I was part of the Picademy team travelling the UK help educators take their first step with the Raspberry Pi.
These days I am Associate Editor at Tom's Hardware and I specialise in Raspberry Pi and Linux stories.

I'm working on a new project to shorten the boot time of a Raspberry Pi 4 to sub twenty seconds. And by this I mean from power on, to usable desktop experience.
Has anyone tried this, and do you have any pointers?
What services can be cut?

Thanks!

jahboater
Posts: 5670
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: Shortening the boot time of a Raspberry Pi 4

Fri Jun 12, 2020 2:16 pm

The following two commands may help decide which services to disable:

Code: Select all

systemd-analyze blame

Code: Select all

systemd-analyze critical-chain
This helps a little:

Code: Select all

initial_turbo=30
My Pi4 8GB running PIOS64 on a Sandisk A1 SD card, starts in:

Code: Select all

pi@raspberrypi:~ $ systemd-analyze 
Startup finished in 1.174s (kernel) + 2.467s (userspace) = 3.641s 
graphical.target reached after 2.442s in userspace
pi@raspberrypi:~ $ 
Pi4 8GB running PIOS64

biglesp
Posts: 3
Joined: Fri Jun 12, 2020 1:43 pm

Re: Shortening the boot time of a Raspberry Pi 4

Mon Jun 22, 2020 9:42 am

Thanks very much I shall give this a try.
Best wishes, and sorry for the slow reply.

User avatar
DougieLawson
Posts: 38852
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Shortening the boot time of a Raspberry Pi 4

Mon Jun 22, 2020 11:20 am

I think you're tilting at windmills. My RPi3B with the official display got this

Code: Select all

root@tranquility:~ # systemd-analyze critical-chain
The time after the unit is active or started is printed after the "@" character.
The time the unit takes to start is printed after the "+" character.

graphical.target @15.949s
└─multi-user.target @15.948s
  └─tvheadend.service @10.227s +5.718s
    └─remote-fs.target @10.174s
      └─remote-fs-pre.target @8.445s
        └─rpcbind.service @7.917s +490ms
          └─systemd-tmpfiles-setup.service @7.744s +163ms
            └─local-fs.target @7.698s
              └─boot.mount @7.637s +55ms
                └─systemd-fsck@dev-disk-by\x2dpartuuid-0c3a490b\x2d01.service @6
                  └─dev-disk-by\x2dpartuuid-0c3a490b\x2d01.device @6.600s
root@tranquility:~ #

This was from a timed shutdown -r 17:30 (with a stable clock).

Code: Select all

root@tranquility:~ # uptime -s
2020-06-18 17:30:38
root@tranquility:~ #
so that was 38 seconds to shutdown and reboot. You're not going to strip any time out of that.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

biglesp
Posts: 3
Joined: Fri Jun 12, 2020 1:43 pm

Re: Shortening the boot time of a Raspberry Pi 4

Mon Jun 22, 2020 3:32 pm

DougieLawson wrote:
Mon Jun 22, 2020 11:20 am
I think you're tilting at windmills. My RPi3B with the official display got this

Code: Select all

root@tranquility:~ # systemd-analyze critical-chain
The time after the unit is active or started is printed after the "@" character.
The time the unit takes to start is printed after the "+" character.

graphical.target @15.949s
└─multi-user.target @15.948s
  └─tvheadend.service @10.227s +5.718s
    └─remote-fs.target @10.174s
      └─remote-fs-pre.target @8.445s
        └─rpcbind.service @7.917s +490ms
          └─systemd-tmpfiles-setup.service @7.744s +163ms
            └─local-fs.target @7.698s
              └─boot.mount @7.637s +55ms
                └─systemd-fsck@dev-disk-by\x2dpartuuid-0c3a490b\x2d01.service @6
                  └─dev-disk-by\x2dpartuuid-0c3a490b\x2d01.device @6.600s
root@tranquility:~ #

This was from a timed shutdown -r 17:30 (with a stable clock).

Code: Select all

root@tranquility:~ # uptime -s
2020-06-18 17:30:38
root@tranquility:~ #
so that was 38 seconds to shutdown and reboot. You're not going to strip any time out of that.
Thanks Dougie, I am going to persevere and see what can be done, if it results in nothing then at least I have found the answer and learnt a little bit more about systemd.
Best
Les!

cleverca22
Posts: 545
Joined: Sat Aug 18, 2012 2:33 pm

Re: Shortening the boot time of a Raspberry Pi 4

Mon Jun 22, 2020 10:56 pm

Code: Select all

root@raspberrypi:~# ./uptime
 42.868002
31.22 100.38
root@raspberrypi:~# systemd-analyze critical-chain
The time after the unit is active or started is printed after the "@" character.
The time the unit takes to start is printed after the "+" character.

graphical.target @17.310s
└─multi-user.target @17.309s
  └─exim4.service @16.673s +633ms
    └─network-online.target @16.667s
      └─network.target @16.666s
        └─dhcpcd.service @5.059s +11.604s
          └─basic.target @4.978s
            └─sockets.target @4.975s
              └─triggerhappy.socket @4.972s
                └─sysinit.target @4.896s
                  └─systemd-timesyncd.service @4.543s +345ms
                    └─systemd-tmpfiles-setup.service @4.400s +127ms
                      └─local-fs.target @4.382s
                        └─boot.mount @4.330s +48ms
                          └─systemd-fsck@dev-disk-by\x2dpartuuid-6c586e13\x2d01.service @3.916s +398ms
                            └─dev-disk-by\x2dpartuuid-6c586e13\x2d01.device @3.703s
root@raspberrypi:~# 
source for uptime.c over here

`systemd-analyze` can only measure time relative to when linux gained control of the arm core

the `uptime.c` code in the above link, shows both the linux uptime (starts counting when linux gained control of arm) and the VPU uptime (starts counting when the reset signal was released)

the difference (42-31, aka 11 seconds) is how long it took for linux to even get control of the arm core

that 11 seconds includes the maskrom loading and validating bootcode.bin from SPI
bootcode.bin bringing dram online
> There are limits to how quickly the Pi 4 can boot - the SDRAM PHY has quite a lengthy training sequence, several seconds from what I remember.
bootcode.bin loading start4.elf from the uSD card (depends on SD speed)
start4.elf doing all of its init stuff, and loading linux+initrd from uSD (depends on kernel size, and SD speed)

kolsi
Posts: 42
Joined: Wed Jan 23, 2019 10:40 am

Re: Shortening the boot time of a Raspberry Pi 4

Tue Jun 23, 2020 8:02 am

For our setup, the slowest operation at boot is the login and Xorg starting up. We have custom gui.service that automatically logs in the user and then calls "startx" in .bash_profile. There is more than 2.5 seconds delay between gui.service startup time and the first line in Xorg.log.
boot_plot.PNG
boot_plot.PNG (25.14 KiB) Viewed 496 times

geev03
Posts: 172
Joined: Thu Jun 07, 2012 12:40 pm
Location: London, UK

Re: Shortening the boot time of a Raspberry Pi 4

Tue Jun 23, 2020 4:20 pm

biglesp wrote:
Fri Jun 12, 2020 1:54 pm
......
Has anyone tried this, and do you have any pointers?
What services can be cut?

Thanks!

Code: Select all

Startup finished in 6.152s (kernel) + 43.081s (userspace) = 49.233s
>>https://linux-hardware.org/index.php?pr ... md-analyze

ganzgustav22
Posts: 59
Joined: Tue Feb 11, 2020 1:04 pm

Re: Shortening the boot time of a Raspberry Pi 4

Tue Jun 23, 2020 8:41 pm

Code: Select all

disable_splash=1
boot_delay=0
In config.txt should shorten the boot time until the kernel starts by around 2 seconds (atleast it did on the Pi0/1/2/3).

cleverca22
Posts: 545
Joined: Sat Aug 18, 2012 2:33 pm

Re: Shortening the boot time of a Raspberry Pi 4

Tue Jun 23, 2020 9:17 pm

on my pi4, boot_delay=0 on its own had zero effect

disable_splash=1 on its own also has no effect

still no difference with both combined

boot_delay=10 has the expected effect, it now takes 21 seconds instead of 11, so the option at least does something, and must be defaulting to 0

User avatar
dickon
Posts: 1436
Joined: Sun Dec 09, 2012 3:54 pm
Location: Home, just outside Reading

Re: Shortening the boot time of a Raspberry Pi 4

Tue Jun 30, 2020 10:47 pm

If you're booting a 32b kernel, can you try setting kernel_address=0x2000000 and see if that makes a difference? I've been made aware that the Pi's bootloader loads 32b kernels at 0x8000, which is ludicrous and not recommended, although does appear to be weirdly common.

It should shave some time off the boot. Not sure how much.

Return to “Raspberry Pi OS”