1

I am new to Raspberry PI development. I am building my custom boot image. I am taking image file, mounting it on linux, adding/removing somefiles, unmounting, plugging sd card to cardreader, dd-ing image to card, unplugging it, then plugging it to raspberry pi, then boot it.

A lot of manual operations. Is it normal?

Is it possible to automate this process? May be write some integration tests, which will boot image file, issue some commands etc?

Dims
  • 129
  • 6
  • If you want to boot the image in a normal computer you'll need an emulator; as far as I am aware the only one that boots a stock (?) Pi image is QEMU. – goldilocks Sep 21 '20 at 18:19

2 Answers2

2

As far as I understand you frequently want to modify an image to boot it with different conditions.

I would use LVM (Logical Volume Manager). With it you can have the master installation that you boot to create a snapshot of it. Then you can mount the snapshot and modify it as needed. Just by changing /boot/cmdline.txt and /etc/fstab (on the snapshot) to point to the root system on the snapshot you can boot into the snapshot. If you like you can do it with a script. Reverting settings in that files let you boot into the master installation again to create a new snapshot to modify. I use LVM for my tests and development. How I install it you can look at Easy backups and snapshots of a running system with LVM.

Another way is to use netbooting but this is restricted to a wired network. Then you can have multiple rootfs on the NetBoot server that you can select and modify before booting it. To get an idea how this could work, look at Netbooting multiple “workers” RPi from a “master” RPi.

Ingo
  • 40,606
  • 15
  • 76
  • 189
1

That is sadly enough very normal, at first.

If you are writing a bare bone kernel for RaspberryPi 1 or 2 then I wrote a little bootloader called raspbootin that will fetch the kernel image over serial at boot. I plan to update it to support RPi3 and RPI4 in 32bit and 64bit at some time. This is a good solution for real low-level work.

The RPi4 can also use uboot as bootloader I believe and uboot can then boot from serial, USB or network normally. I assume the RPi4 port will allow that too. So during developement you could swap an USB stick around, which would be easier than the SD card at least. Or boot over network skipping the device swapping altogether.

If you are modifying a linux distribution then make sure the network comes up and sshd starts. Once you got that far you can log into the system over the network and modify the files directly on the system. Or use scp or rsync to copy the files from your dev system to the test system. There really is no need to write the whole image every time.