Cyjan's Blog

I don't know why are you here, but enjoy.


Epstein didn't kill himself | Design | General
Politically Incorrect | Raspberry PI | Technologic
btw I'm using Ubuntu Touch

Creating minimal Raspberry Pi OS image

July 14, 2020 | Raspberry PI

According to systemd-analyze it takes 1min and 15 seconds to boot my raspberry pi on clean install of raspbian.. I think that raspberry's definition of clean is different than mine.

First of all, I grab latest Raspberry Pi OS, flash it to my Raspberry Pi zero W and do following:

apt-get purge --yes --auto-remove aptitude aptitude-common apt-listchanges apt-utils blends-tasks xserver-common x11-xfs-utils x11-xserver-utils xinit libsmbclient blt gvfs gvfs-backends gvfs-daemons gvfs-fuse idle idle-python2.7 idle3 libaudio2 libice6 liblightdm-gobject-1-0 libpulse0 libqt4-svg libqtgui4 libsdl-image1.2 libsdl-mixer1.2 libsdl-ttf2.0-0 libsdl1.2debian libsm6 libsmpeg0 libwebkitgtk-1.0-0 libwebkitgtk-3.0-0 libxaw7 libxklavier16 libxmu6 libxss1 libxt6 libxtst6 lightdm lightdm-gtk-greeter lxde lxde-core midori obconf openbox python-pygame python-tk python3-tk scratch tk8.5 wpagui x11-common x11-utils x11-xkb-utils xinit xserver-common xserver-xorg xserver-xorg-core xserver-xorg-input-all xserver-xorg-input-evdev xserver-xorg-input-synaptics xserver-xorg-video-fbdev zenity xserver* x11-common x11-utils x11-xkb-utils x11-xserver-utils xarchiver xauth xkb-data console-setup xinit lightdm libx{composite,cb,cursor,damage,dmcp,ext,font,ft,i,inerama,kbfile,klavier,mu,pm,randr,render,res,t,xf86}* lxde* lx{input,menu-data,panel,polkit,randr,session,session-edit,shortcut,task,terminal} obconf openbox gtk* libgtk* alsa*  python-pygame python-tk python3-tk scratch tsconf desktop-file-utils cifs-utils samba-common smbclient scratch debian-reference-en dillo idle3 python3-tk idle python-pygame python-tk lightdm gnome-themes-standard gnome-icon-theme raspberrypi-artwork gvfs-backends gvfs-fuse desktop-base lxpolkit zenity xdg-utils mupdf gtk2-engines alsa-utils lxde lxtask menu-xdg gksu midori xserver-xorg xinit xserver-xorg-video-fbdev libraspberrypi-dev libraspberrypi-doc dbus-x11 libx11-6 libx11-data libx11-xcb1 x11-common x11-utils lxde-icon-theme gconf-service gconf2-common udhcpd avahi-daemon gcc-arm-linux-gnueabihf  geoip-database libgdbm* libperl* make patch perl perl-modules-* cups* rsync bluez bluez-firmware pi-bluetooth scratch debian-reference-en dillo idle3 python3-tk idle python-pygame python-tk lightdm gnome-themes-standard gnome-icon-theme raspberrypi-artwork gvfs-backends gvfs-fuse desktop-base lxpolkit zenity xdg-utils mupdf gtk2-engines alsa-utils lxde lxtask menu-xdg gksu midori xserver-xorg xinit xserver-xorg-video-fbdev libraspberrypi-dev libraspberrypi-doc dbus-x11 libx11-6 libx11-data libx11-xcb1 x11-common x11-utils lxde-icon-theme gconf-service gconf2-common firmware-atheros samba-common plymouth

That's... That's probably everything that could be considered as bloat. Just in case I've missed something you can do apt-get autoremove --purge

Then we can remove comments left in *.conf files find / -type f -name "*.conf" |xargs sed -i '\#^//#d'

We can also disable docs and locale files from installing via apt

cat > /etc/apt/apt.conf.d/80noadditional <<"EOF"
APT::Install-Recommends "0";
APT::Install-Suggests "0";
EOF

cat > /etc/dpkg/dpkg.cfg.d/nodoc <<"EOF"
path-exclude /usr/share/doc/* path-include /usr/share/doc/*/copyright path-exclude /usr/share/man/* path-exclude /usr/share/groff/* path-exclude /usr/share/info/* path-exclude /usr/share/lintian/* path-exclude /usr/share/linda/*
EOF

cat > /etc/dpkg/dpkg.cfg.d/nolocale <<"EOF"
path-exclude /usr/share/locale/*
EOF

Also, for faster ssh connection we can disable motd cat /dev/null > /etc/motd
Cleanup apt apt-get clean

Then we need to make some changes in /boot/config.txt

# http://rpf.io/configtxt
#https://www.raspberrypi.org/documentation/configuration/config-txt/overclocking.md
arm_freq=1100

#initial_turbo=30
#dtparam=i2c_arm=on
#dtparam=i2s=on
#dtparam=spi=on

# Disable stuff
dtparam=audio=off
dtoverlay=pi3-disable-bt

# Disable the ACT LED on the Pi Zero.
dtparam=act_led_trigger=none
dtparam=act_led_activelow=on

# Disable the splash screen
disable_splash=1
 
# Overclock the SD Card from 50 to 100MHz
# This can only be done with at least a UHS Class 1 card
dtoverlay=sdtweak,overclock_50=100
 
# Set the bootloader delay to 0 seconds. The default is 1s if not specified.
boot_delay=0
 
# Overclock the raspberry pi. This voids its warranty. Make sure you have a good power supply.
force_turbo=1

After that we can add quiet before rootwait in /boot/cmdline.txt, that will disable kernel logging

After that we can disable services that we won't use anyway

systemctl disable dphys-swapfile.service
systemctl disable apt-daily.service
systemctl disable apt-daily.timer
systemctl disable nfs-client.target
systemctl disable remote-fs.target
systemctl disable apt-daily-upgrade.timer
systemctl disable nfs-config.service