Just moozing

Before you can check your notes, you must make them…

Raspberry Pi – image fun

leave a comment »

800px-rpi-logo-landscape-printIt is pi day 3/14, so I have been looking more at raspberry pis. This blog post is about working with images and gitlab.

The goal was to use Ansible, bash scripts or the like and put it on gitlab, to automatically update raspberry pi images.

For the impatient the repository with the working example of updating files only on a raspberry image is here.

The design is

    1. Download latest rasbian
    2. Extract
    3. Mount
    4. Run update script
    5. Unmount
    6. Zip the result

I had this working in 20 minutes on my laptop. The update script is a generic “add my ssh key to authorized_keys”.

The issues started popping up, when I wanted to do it automatically using gitlab ci and expand it a bit. There are two main issues: the architecture and mounting the image.

Architecture issues

My raspberry pi 3:
$ uname -a
Linux osmc 4.14.78-4-osmc #1 SMP PREEMPT Wed Dec 12 17:58:11 UTC 2018 armv7l GNU/Linux

My laptop:
$ uname -a
Linux M67deb 4.19.0-1-amd64 #1 SMP Debian 4.19.12-1 (2018-12-22) x86_64 GNU/Linux

Being different architecture means that I cannot mount the image, use chroot and the run stuff from the image. The binaries must match the current architecture, so that fails.

The current incarnation of the repo is that we update files only – without using the binaries from the image. This makes it impossible to use ansible or use the password utility to change passwords. Only updating files is possible.

My current plan is to use QEMU to emulate ARM and then update files, run programs and so on – and then save the image as the new one. It might be a workable path – others do it.

Mounting the image

This was not an issue on the laptop. I used guestmount, but loopback mounting (using mount -o loop ...) is also an option. There are some udiskctl ways of doing it.

Moving it to gitlab, means running it in non-privileges docker containers. I had to devise a solution in pure userspace, since guestmount uses some virtualization extensions and loop mounting requires the loop module to be installed.

Both not an option in the docker shared runners.

The solution is to use fuse-ext2, which is a userspace program for mounting ext partitions. It only support single partition files, so I had to extract the relevant partition from the raspbian image, and then merge them back together after running the update script.

Bonus: packer

We are currently working hard on combining packer and gitlab-runners. Using packer to create raspberry images might be possible … stay tuned.


Written by moozing

March 18, 2019 at 12:00

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: