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 the FreedomBox project.
13 The FreedomBox project already uses vmdebootstrap for the virtualbox
14 images, but its home made multistrap based system for Dreamplug
15 images, and it is lacking support for Raspberry Pi.</p>
17 <p>Armed with the knowledge on how to build "foreign" (aka non-native
18 architecture) chroots for Raspberry Pi, I dived into the vmdebootstrap
19 code and adjusted it to be able to build armel images on my amd64
20 Debian laptop. I ended up giving vmdebootstrap five new options,
21 allowing me to replicate the image creation process I use to make
22 <a href=http://people.skolelinux.org/pere/blog/A_Raspberry_Pi_based_batman_adv_Mesh_network_node.html"">Debian
23 Jessie based mesh node images for the Raspberry Pi</a>. First, the
24 <tt>--foreign /path/to/binfm_handler</tt> option tell vmdebootstrap to
25 call debootstrap with --foreign and to copy the handler into the
26 generated chroot before running the second stage. This allow
27 vmdebootstrap to create armel images on an amd64 host. Next I added
28 two new options <tt>--bootsize size</tt> and <tt>--boottype
29 fstype</tt> to teach it to create a separate /boot/ partition with the
30 given file system type, allowing me to create an image with a vfat
31 partition for the /boot/ stuff. I also added a <tt>--variant
32 variant</tt> option to allow me to create smaller images without the
33 Debian base system packages installed. Finally, I added an option
34 <tt>--no-extlinux</tt> to tell vmdebootstrap to not install extlinux
35 as a boot loader. It is not needed on the Raspberry Pi and probably
36 most other non-x86 architectures. The changes were accepted by the
37 upstream author of vmdebootstrap yesterday and today, and is now
39 <a href="http://git.liw.fi/cgi-bin/cgit/cgit.cgi/vmdebootstrap/">the
40 upstream project page</a>.</p>
42 <p>To use it to build a Raspberry Pi image using Debian Jessie, first
43 create a small script (the customize script) to add the non-free
44 binary blob needed to boot the Raspberry Pi and the APT source
49 set -e # Exit on first error
52 cat <<EOF > etc/apt/sources.list
53 deb http://http.debian.net/debian/ jessie main contrib non-free
55 # Install non-free binary blob needed to boot Raspberry Pi. This
56 # install a kernel somewhere too.
57 wget https://raw.github.com/Hexxeh/rpi-update/master/rpi-update \
58 -O $rootdir/usr/bin/rpi-update
59 chmod a+x $rootdir/usr/bin/rpi-update
60 mkdir -p $rootdir/lib/modules
61 touch $rootdir/boot/start.elf
62 chroot $rootdir rpi-update
65 <p>Next, fetch the latest vmdebootstrap script and call it like this
66 to build the image:</p>
69 sudo ./vmdebootstrap \
72 --distribution jessie \
73 --mirror http://http.debian.net/debian \
82 --root-password raspberry \
83 --hostname raspberrypi \
84 --foreign /usr/bin/qemu-arm-static \
85 --customize `pwd`/customize \
89 --package ca-certificates \
94 <p>The list of packages being installed are the ones needed by
95 rpi-update to make the image bootable on the Raspberry Pi, with the
96 exception of netbase, which is needed by debootstrap to find
97 /etc/hosts with the minbase variant. I really wish there was a way to
98 set up an Raspberry Pi using only packages in the Debian archive, but
99 that is not possible as far as I know, because it boots from the GPU
100 using a non-free binary blob.</p>
102 <p>The build host need debootstrap, kpartx and qemu-user-static and
103 probably a few others installed. I have not checked the complete
104 build dependency list.</p>
106 <p>The resulting image will not use the hardware floating point unit
107 on the Raspberry PI, because the armel architecture in Debian is not
108 optimized for that use. So the images created will be a bit slower
109 than <a href="http://www.raspbian.org/">Raspbian</a> based images.</p>