Ubuntu, An Arm board, and I Walk Into a Bar...
This post is mostly for me to remember what I was doing when I sit back down to deal with this next weekend. However, since I spent so much time trying to aggregate tons of information from all over the net on how to use these tools, I thought it might make for a good blog post. Also, I'm kind of hoping someone can give me some pointers in making this better.
Earlier this week, I found a purpose for my Beagle Board. Out of my requirements, it satisfied them all, including running Ubuntu. I've been toying with it for a while, and it had Ubuntu on it when I picked it back up this weekend to hack on it. The one thing that I found though was that I wanted a bit more customization than the default Ubuntu install (the keyword here is "wanted").
My ultimate scenario for creating an image is to use Qemu to test my images as I build them, and make sure I have everything available. Testing each image on the actual hardware is a bit time consuming. I want to minimize the size of the image, which means installing only the needed packages, but there are some custom packages I also need to install. Once I had everything set up the way I wanted, I'd create a squashfs partition with my OS and I'd be done.
So this weekend I embarked on the process of making my own Ubuntu image for my Beagle Board. I started off using a tool called rootstock. rootstock makes arm images using debootstrap. It ended up being a huge pain to actually get it working the way I wanted to.
I know debootstrap pretty well, since I do all my Launchpad development in a chroot, and sometimes the Launchpad environment requires me to kill my chroot and start over. Since I was pretty comfortable with it, and I knew it would do exactly what I wanted (and ironically, is used by rootstock), I started down that route. I created a bootstrapped Ubuntu with debootstrap --foreign --arch=armel lucid bootstrap http://ports.ubuntu.com The problem I ran into was that the --foreign part meant that the bootstrap was only the first stage, and I couldn't complete the second stage without ARM hardware or a bootable QEMU ARM instance. Ugh...
After struggling with that (because I'd exhausted all of my knowledge, and the internet is really sparse on my exact needs), I stumbled across an undocumented script called qemu-debootstrap. Documentation is nonexistant, and there's no man page for the script, but qemu-debootstrap --help returns E: I'm just a debootstrap wrapper; please see debootstrap --help. That made sense, but still didn't tell my what it did. Open source is great though, so I just read the source. qemu-debootstrap takes all the debootstrap flags, and adds --foreign, but then also copies in some needed qemu binaries and runs the /debootstrap/debootstrap --second-stage script that completes the debootstrap process.
At this point, my process was this:
-
dd if=/dev/zero of=arm.img count=2000000- Create a 2GB(ish) file -
mkfs.ext3 arm.img- Format the file to ext3. In the end, I'll use squashfs, but ext3 gives me flexibility for now, and means I don't have to build a custom kernel just yet. -
mount -o loop arm.img /mnt- Mount the image at /mnt -
qemu-debootstrap --arch=armel lucid /mnt http://ports.ubuntu.com- Here's the good part. Make a filesystem with the basic Ubuntu installation. -
umount /mnt- Unmount the image.
The file arm.img is now ready to be booted in qemu. So now I run qemu-system-arm -M versatilepb -cpu cortex-a8 -kernel <kernel-of-my-choice> -hda arm.img -m 256 -append "rootwait root=/dev/sda devtmpfs.mount=0 raid=noautodetect rw".
It boots in Qemu. Hooray! Unfortunately, it seems to crap out after finding the image and trying to run it. udev dies, then plymouth dies, and I get no debugging messages either in the Qemu window, or the pty terminal. I'm still not sure what's going on, but I've at least got something booting now. I'm now digging through the Upstart debugging page, and seeing if I can find out what's going on. Regardless, I have an image that I can now work with. It'll be nice when I can boot it into Gnome, but that's for next weekend, right? :)