dd86k's blog

Machine code enthusiast

Optimizing boot-time for Ubuntu Server

Author: dd
Published: October 8, 2019
Last modified: December 25, 2022 at 15h02
Categories:

I recently got Ubuntu Server on my Raspberry Pi and I found it a bit slow to boot, so off I investigate!

Introduction

Since that I have a little project for my little Raspberry Pi 3 B+ v1.3, I decided to get a pre-installed distro for it, so I went for ubuntu-18.04.3-preinstalled-server-arm64+raspi3.img.xz. Flashed and ready to run! After setting things further and rebooting the thing a few times, I noticed it takes a bit of a while for it to boot. So being the server edition of Ubuntu, which includes a bit too many things, I’ll give you a few tricks to make it a tad lighter on boot.

Using Dash

Dash, an acronym for Debian Almquist shell, is a script and command interpreter fully compatible with bash aiming to be much smaller — but here’s the best part — it’s usually faster than bash and sh.

To install dash, as root you’ll have to run:

# apt install dash -y

Then to configure it as the shell that points to /bin/sh:

# dkpg-reconfigure dash

And that’s it!

Using systemd-analyze

systemd comes with a wide variety of tools, and one of them is systemd-analyze. This command alone will show how much time the kernel and user-space took to start up. The sub-command we are interested in is blame, as in git blame!

As root, you can see which service is taking the most time to start with:

# systemd-analyze blame

Then you will get a list like this (taken from my Ubuntu Server 18.04 VM):

15.056s rabbitmq-server.service
3.770s postgresql@10-main.service
3.322s dev-sda2.device
2.721s snapd.service
2.155s cloud-config.service
2.140s cloud-init-local.service
1.607s vboxadd.service
1.192s cloud-init.service
1.135s cloud-final.service
1.102s dev-loop2.device
1.084s apport.service
1.066s dev-loop0.device
1.005s dev-loop1.device

You’ll notice that some services are quite heavy! To disable anything you don’t need, you’ll have to run systemctl disable SERVICE one-by-one. I recommend disabling any cloud-*, apt-daily, and apt-daily.timer services (and that rabbitmq-server in my case).

Using SSH: Update MOTDs

I often connect to my RPi using SSH, and trust me, there are a lot of welcoming scripts, which makes initial SSH connections rather slow.

To lighten things up, you might want to remove, or move, scripts located in /etc/update-motd.d/ because after all, I personally don’t need all that info!

That pretty much concludes it. If I find anything else, or I get more tricks from people, I’ll update this post.