1 Title: Teaching vmdebootstrap to create Raspberry Pi SD card images
2 Tags: english, debian, freedombox, mesh network
6 <a href="http://packages.qa.debian.org/v/vmdebootstrap.html">vmdebootstrap</a>
7 program is a a very nice system to create virtual machine images. It
8 create a image file, add a partition table, mount it and run
9 debootstrap in the mounted directory to create a Debian system on a
10 stick. Yesterday, I decided to try to teach it how to make images for
11 <a href="https://wiki.debian.org/RaspberryPi">Raspberry Pi</a>, as part
12 of a plan to simplify the build system for
13 <a href="https://wiki.debian.org/FreedomBox">the FreedomBox
14 project</a>. The FreedomBox project already uses vmdebootstrap for
15 the virtualbox images, but its current build system made multistrap
16 based system for Dreamplug images, and it is lacking support for
19 <p>Armed with the knowledge on how to build "foreign" (aka non-native
20 architecture) chroots for Raspberry Pi, I dived into the vmdebootstrap
21 code and adjusted it to be able to build armel images on my amd64
22 Debian laptop. I ended up giving vmdebootstrap five new options,
23 allowing me to replicate the image creation process I use to make
24 <a href="http://www.hungry.com/~pere/blog/A_Raspberry_Pi_based_batman_adv_Mesh_network_node.html">Debian
25 Jessie based mesh node images for the Raspberry Pi</a>. First, the
26 <tt>--foreign /path/to/binfm_handler</tt> option tell vmdebootstrap to
27 call debootstrap with --foreign and to copy the handler into the
28 generated chroot before running the second stage. This allow
29 vmdebootstrap to create armel images on an amd64 host. Next I added
30 two new options <tt>--bootsize size</tt> and <tt>--boottype
31 fstype</tt> to teach it to create a separate /boot/ partition with the
32 given file system type, allowing me to create an image with a vfat
33 partition for the /boot/ stuff. I also added a <tt>--variant
34 variant</tt> option to allow me to create smaller images without the
35 Debian base system packages installed. Finally, I added an option
36 <tt>--no-extlinux</tt> to tell vmdebootstrap to not install extlinux
37 as a boot loader. It is not needed on the Raspberry Pi and probably
38 most other non-x86 architectures. The changes were accepted by the
39 upstream author of vmdebootstrap yesterday and today, and is now
41 <a href="http://git.liw.fi/cgi-bin/cgit/cgit.cgi/vmdebootstrap/">the
42 upstream project page</a>.</p>
44 <p>To use it to build a Raspberry Pi image using Debian Jessie, first
45 create a small script (the customize script) to add the non-free
46 binary blob needed to boot the Raspberry Pi and the APT source
51 set -e # Exit on first error
54 cat <<EOF > etc/apt/sources.list
55 deb http://http.debian.net/debian/ jessie main contrib non-free
57 # Install non-free binary blob needed to boot Raspberry Pi. This
58 # install a kernel somewhere too.
59 wget https://raw.github.com/Hexxeh/rpi-update/master/rpi-update \
60 -O $rootdir/usr/bin/rpi-update
61 chmod a+x $rootdir/usr/bin/rpi-update
62 mkdir -p $rootdir/lib/modules
63 touch $rootdir/boot/start.elf
64 chroot $rootdir rpi-update
67 <p>Next, fetch the latest vmdebootstrap script and call it like this
68 to build the image:</p>
71 sudo ./vmdebootstrap \
74 --distribution jessie \
75 --mirror http://http.debian.net/debian \
84 --root-password raspberry \
85 --hostname raspberrypi \
86 --foreign /usr/bin/qemu-arm-static \
87 --customize `pwd`/customize \
91 --package ca-certificates \
96 <p>The list of packages being installed are the ones needed by
97 rpi-update to make the image bootable on the Raspberry Pi, with the
98 exception of netbase, which is needed by debootstrap to find
99 /etc/hosts with the minbase variant. I really wish there was a way to
100 set up an Raspberry Pi using only packages in the Debian archive, but
101 that is not possible as far as I know, because it boots from the GPU
102 using a non-free binary blob.</p>
104 <p>The build host need debootstrap, kpartx and qemu-user-static and
105 probably a few others installed. I have not checked the complete
106 build dependency list.</p>
108 <p>The resulting image will not use the hardware floating point unit
109 on the Raspberry PI, because the armel architecture in Debian is not
110 optimized for that use. So the images created will be a bit slower
111 than <a href="http://www.raspbian.org/">Raspbian</a> based images.</p>