easy way to write rootfs

Ignore this, please use write-to-usb.py instead

Introduction

I've been playing with different rootfs (root filesystem) images recently on different USB sticks, and it was a pain having to both manually format and extract the rootfs, as well as having to work out each time which device name my USB stick was located at.

So I've come up with some scripts to solve all these problems! :-)

To get this all working you'll need to create 2 partitions on your USB stick - the first (big) ext2 partition that will hold the bifferboard root filesystem as usual, and a second smaller partition to hold my scripts (the reason for this will become clear later).

The second partition only needs to be 1MB, but I find it convenient to have it 20MB, that way I can fit my scripts as well as a few rootfs images in there. It doesn't matter what format the second partition is, but I guess you may as well be consistent and stick with ext2.

Installation

Unmount your USB stick if it's automounted, load up fdisk to edit the partitions on your USB stick e.g. fdisk /dev/sdb, delete any existing partitions, create the first partition with a size of (disk capacity - 20MB), and then create the second partition to use up the remainder of the space.

Format the second partition e.g. mkfs.ext2 /dev/sdb2, mount it, and then copy the 3 scripts attached to this page onto it. Use chmod to make all 3 scripts executable, and you may want to use chown to make write_rootfs.sh only executable by root (since it contains commands that only root can execute anyway).

If you want, you could create a subdirectory and copy a rootfs image into it (e.g. I extracted bifferboard-rootfs.tgz from bb-bin-1.3.tar.bz2, and then copied it to my second partition as rootfs-images/bifferboard-rootfs-1.3.tgz)

Usage

The get_other_partition.sh uses some command-line trickery to work out the device name of the first partition, based on the location and name of the second partition, and means you don't need to work it out yourself (especially handy if you have a couple of other USB drives plugged in at the same time!)

To check that it works on your distro (I've succesfully tested it on Ubuntu and Xandros), cd to the directory where the second partition is mounted (you have to do this or it won't work!), and then run ./get_other_partition.sh which should return something like /dev/sdb1

If it doesn't work, please let me know on the mailing list!

Hopefully it does work ;) in which case you can run (as root) ./write_rootfs.sh <rootfs> e.g. ./write_rootfs.sh rootfs-images/bifferboard-rootfs-1.3.tgz which will ask you for confirmation, and then automatically format the first partition and extract the specified rootfs image to it. I've put lots of error-checking into the script, but again please let me know on the mailing list if it doesn't work. (don't blame me if you end up accidentally formatting yor hard drive!)

You can now unmount the USB stick (both partitions!) from your PC, and plug it into bifferboard and it should boot up. Unless you tell it otherwise, bifferboard completely ignores the second partition.

As you can imagine, you could put multiple different rootfs images onto your second partition, and use my write_rootfs.sh script to easily swap between them :)

Obviously the rootfs image doesn't have to be on the second partition, you could just as easily do ./write_rootfs.sh ~/bifferboard/openwrt/bin/openwrt-bifferboard-rootfs.tgz to write a rootfs that you've built yourself from source. It is important though that you always cd to the directory the second partition is mounted at, because ./get_other_partition.sh relies on the output of the pwd command.