Customizing Armbian

I've been working on a hardware project that includes a small single board computer (SBC) running Linux... in this case, Armbian.  I didn't find any good instructions or scripts for customizing the image without fully rebuilding everything from source, so I did a little investigating.  Here are some of my notes and what I came up with.

The armbian images are shippped as 7z compressed disk images.  This may be board specific, but the image I used contained a MBR boot record as well as a single ext4 partition.  This partition is resized on first boot.

To modify the image, I have a debian development environment running under VirtualBox.

losetup -P /dev/loop0 filename.img (this sets up the loopback device and forces a partition scan)

All my configuration is done from a script called from rc.local.  It changes permission to 000 on rc.local when it is complete.  Among other things, this installs additional packages I include in the distribution.

From another identical SBC with a clean install of Armbian, I run the following to fetch the necessary packages

apt-get clean && apt-get install --download-only packge1 package2 pacakge3

where package1, etc are all the packages I want to add.  The deb files and necessary dependencies will be at /var/cache/apt/archives.  These can be copied onto the image and installation done by the first boot script.

After unmounting the loopback device, it can be written back to an SD card using dd on Linux or balenaEthcer, etc on Windows.

dd if=armbianimage.img of=/dev/sdc bs=1M oflag=direct status=progress