6

I did not measure it, but I think it takes about twice as long to boot a fresh Raspbian Lite image than an image that has already been booted. I don't know why that's the case. I'm curious what happens during first boot.

1
  • For the record: a lot of different OS will boot slower the first time than the second. This is not specific to Raspbian, although every OS has its own reasons and configurations to make in order.
    – Mast
    Jan 26, 2020 at 8:39

2 Answers 2

9

There's a service that run only on the first boot, then disables itself. It's a Debian SysV style script in /etc/init.d, resize2fs_once. It does this:

    log_daemon_msg "Starting resize2fs_once"
    ROOT_DEV=$(findmnt / -o source -n) &&
    resize2fs $ROOT_DEV &&
    update-rc.d resize2fs_once remove &&
    rm /etc/init.d/resize2fs_once &&
    log_end_msg $?

There's a detailed description of resize2fs in man resize2fs. As the name implies, it is for resizing filesystems. This is actually the second step in expanding the filesystem to fill the SD card; the first is resizing the partition which contains the filesystem.

That's done via this kernel parameter in /boot/config.txt:

init=/usr/lib/raspi-config/init_resize.sh

That tells the kernel to start the userspace with that shell script, rather than the default /sbin/init. The script resizes the partition, removes that parameter, and reboots.

So, the "first boot" referred to above is actually the second boot, which uses the normative /sbin/init that starts system services including resize2fs_once. The real first boot of init_resize.sh probably does not take more than a few seconds -- resizing a partition is trivial. Resizing a filesystem is more complex.

4

It's not clear from your question what you observed, but it might be because it gets booted twice the first time, once to resize the file system and again to start up "for real."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.