Custom Raspberry Pi distribution

Content might be outdated

The default distribution for Raspberry Pi is Raspbian, but of course there are several other options that might suit your needs better. If you would like to use Raspbian, but you would like to do some modification, either add something or remove something (or both), there are options for building a custion version of Raspbian (but you should name it something else to avoid confusion about why certain things doesn't work as expected in a pure Raspbian installation).

Use https://github.com/RPi-Distro/pi-gen

Customize

  • Remove packages in step4 by placing # first on the lines you don't want (or just delete the lines)
  • Look at the scripts, it might be something to add / remove
  • Add your own stuff, either as a package or in a script (where????)
1/stage1/00-boot-files/files
2cmdline.txt  config.txt
3
4/stage2/01-sys-tweaks/00-patches
5 07-resize-init.diff (changes cmdline.txt)
1--- a/rootfs/boot/cmdline.txt
2+++ b/rootfs/boot/cmdline.txt
3@@ -1 +1 @@
4-dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=ROOTDEV rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
5+dwc_otg.lpm_enable=0 console=serial0,115200 console=tty3 root=ROOTDEV rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet init=/usr/lib/raspi-config/init_resize.sh logo.nologo consoleblank=0 loglevel=3 vt.global_cursor_default=0 plymouth.ignore-serial-consoles
1 splash - show splash image
2 logo.nologo - don't show the raspberries
3 consoleblank=0 - don't show the log during boot
4 vt.global_cursor_default=0 - removes blinking cursor

Ref:

Build

1export IMG_NAME=<name of image>
2./build-docker.sh

Consider using an apt-cache to reduce download times

Create installation files

The build process generates .img files, while we need boot.tar.xz and root.tar.xz

Find start of each partition inside .img file

 1 $ sudo fdisk -l 2018-02-13-corppi3_20180213_1045.img
 2 Disk 2018-02-13-corppi3_20180213_1045.img: 2,6 GiB, 2818572288 bytes, 5505024 sectors
 3 Units: sectors of 1 * 512 = 512 bytes
 4 Sector size (logical/physical): 512 bytes / 512 bytes
 5 I/O size (minimum/optimal): 512 bytes / 512 bytes
 6 Disklabel type: dos
 7 Disk identifier: 0x2a3e05f0
 8
 9 Device                               Boot Start     End Sectors  Size Id Type
10 2018-02-13-corppi3_20180213_1045.img1       8192   93268   85077 41,6M  c W95 FAT32 (LBA)
11 2018-02-13-corppi3_20180213_1045.img2      94208 5505023 5410816  2,6G 83 Linux

Mount boot partition and create boot.tar.xz

1sudo mount -o loop,offset=4194304 2018-02-13-corppi3_20180213_1045.img /mnt
2bsdtar --numeric-owner --format gnutar -cpf /tmp/boot.tar .
3xz -9 -e /tmp/boot.tar

Mount root partition and create root.tar.xz

1sudo mount -o loop,offset=48234496 2018-02-13-corppi3_20180213_1045.img /mnt
2sudo bsdtar --numeric-owner --format gnutar --one-file-system -cpf /tmp/root.tar .
3xz -9 -e /tmp/root.tar

Netinstall? https://github.com/debian-pi/raspbian-ua-netinst

NOOBS - New Out Of Box Software

https://github.com/raspberrypi/noobs

First

  • mount /dev/mmcblk0p1
  • edit recovery.cmdline
  • Add forcetrigger and silentinstall to end of line
  • Remove autoboot.txt (if it exists)

Then

  • Delete everything under os
  • Create a new directory corpimage
  • Copy
    • boot.tar.xz
    • os.json
    • partition_setup.sh
    • partitions.json
    • Raspbian.png
    • release_notes.txt
    • root.tar.xz
  • to corpimage

In Settings partition (usually /dev/mmcblk0p6)

  • Delete noobs.conf
  • Delete installed_os.json

Cleanup

  • Remove forcetrigger and silentinstall from recovery.cmdline
  • Add autoboot.txt to NOOB start partition (/dev/mmcblk0p1) with the following content
1boot_partition=<partition number>
2f.eks.
3boot_partition=6

Installation

  • Initial install requires a micro SD card with NOOBS.
  • Prepare the card as described above
  • Important: Configure ssh key based login and add the keys
  • Boot Raspberry Pi with the prepared SD card, it will install the custom CORP distro

Reinstallation

  • SSH into the Raspbarry Pi
  • Mount the NOOBS partition
  • Copy new versions of root.tar.xz and boot.tar.xz into the os/corp directory
  • Update the partitions.json file if necessary (set uncompressed_tarball_size to the size of the uncompressed tar.xz in MB)
  • Edit recovery.cmdline as described above
  • Remove autoboot.txt if it exists
  • Unmount the NOOBS partition
  • Reboot
  • SSH into the Raspbarry Pi
  • Mount the NOOBS partition
  • Edit recovery.cmdline as described above (clean up)
  • Add autoboot.txt