RootfsFromScratch

Differences between revisions 35 and 37 (spanning 2 versions)
Revision 35 as of 2010-02-19 20:59:58
Size: 7056
Editor: p5B3B2C32
Comment:
Revision 37 as of 2010-02-24 17:40:36
Size: 7134
Editor: p5098ed03
Comment:
Deletions are marked like this. Additions are marked like this.
Line 94: Line 94:
[[ http://people.ubuntu.com/~ogra/arm/qemu/kernel/|qemu kernel ]] [[ http://ports.ubuntu.com/ubuntu-ports/dists/lucid/main/installer-armel/current/images/versatile/netboot/vmlinuz|qemu kernel ]]
Line 99: Line 99:
qemu-system-arm -M versatilepb -kernel ./vmlinuz-2.6.28-versatile -hda arm-rootfs.img -m 256 -append "root=/dev/sda mem=256M ro" qemu-system-arm -M versatilepb -cpu cortex-a8 -kernel ./vmlinuz -hda arm-rootfs.img -m 256 -append "root=/dev/sda mem=256M devtmpfs.mount=0 rw"

This page describes building an armel Debian/Ubuntu root filesystem. It's only from scratch in that you are not starting from installer images, and you don't need target hardware to build it; the code is not rebuilt though, pre-build .deb packages are downloaded and installed instead.

Using rootstock

Simplest and recommended way, use /sudorootstock to create the rootfs.

Rootstock will automate the creation of a rootfs tarball and exposes some config options to tweak the contents/setup.

If you're running Ubuntu 9.10 (karmic) or later, you may install the rootstock package; it will pull the appropriate dependencies.

TODO provide backports of rootstock.

If you install rootstock manually or if you are running it from a bzr checkout, you will also need:

To create an armel rootfs tarball of, for instance, xubuntu-desktop:

    sudo rootstock \
        --fqdn myhostname \
        --login ubuntu \
        --password temppwd \
        --imagesize 2G \
        --seed xubuntu-desktop

Here's another example for ubuntu-desktop:

    sudo rootstock \
        --fqdn ubuntu \
        --login ubuntu \
        --password ubuntu \
        --imagesize 3G \
        --seed ubuntu-desktop

Some typical flags when developing headless (connecting over the network):

    --seed build-essential,openssh-server

Note that you should edit /etc/network/interfaces and set up your network device on first login for this.

If you want a really light desktop (lxde), use:

    --seed lxde,gdm

The options --fqdn (or -f), --login (or -l) and --password (-p) are required for the initial setup. Calling the script with --help shows you all the additional options that can be used to change the setup of the created rootfs.

  • Warning /!\ Change the password on the first login! The above examples use too simple passwords and will expose the password to other users of the machine where rootstock is run.

Building a root filesystem image instead of a tarball

In case you just need a root filesystem for use with qemu and you don't want a rootfs tarball, e.g. for usage with qemu, pass --notarball to rootstock:

    sudo rootstock --fqdn qemu-test \
        --login qemu \
        --password qemupwd \
        --notarball

You can also create a root filesystem from a tarball as follows:

Create the blank image file using dd; this example creates a 1GB image; use seek=3072 for 3GB or seek=2048 for 2GB etc.:

    dd if=/dev/zero of=ubuntu-arm.img bs=1MB count=0 seek=1024

Create linux filesystem on the newly created image:

    mkfs.ext4 -F ubuntu-arm.img

(You might want to pass some extra flags to mkfs to tweak the reserved blocks, labels, or other filesystem options.)

Loop mount the new image:

    sudo mount -o loop ubuntu-arm.img /mnt

Extract the rootfs tarball inside the mounted dir and umount:

    sudo tar -C /mnt -zxf armel-rootfs-200904151837.tgz
    sudo umount /mnt

Now you are set and ready to use the ubuntu-arm.img, see "Using a qemu image" below for the right command

Using a qemu image

If you created your qemu image and want to start a work environment (to compile packages or build applications), grab the kernel from:

qemu kernel

and start qemu with the following command (indeed, you need to adjust the rootfs img name to whatever your image is called)

qemu-system-arm -M versatilepb -cpu cortex-a8 -kernel ./vmlinuz -hda arm-rootfs.img -m 256 -append "root=/dev/sda mem=256M devtmpfs.mount=0 rw"

In the booted image you can then log in with the user and password you defined during image creation.

  • Warning /!\ To be able to copy files from or to the host system it is helpful to install openssh-server on the host and use the scp command inside qemu.

Connect your emulated machine to a real network

When no option is specified QEMU uses a non privileged user mode network stack that gives the emulated machine access to the world. But you probably want to make your emulated machine accessible from the outside. It is possible by using the tap mode and bridging the tap interface with the network interface of the host machine.

The first thing to do is to active a bridge on your host machine. For that you have to modify the /etc/network/interfaces file as follow:

Before:

auto eth0
iface eth0 inet dhcp

After:

auto br0
iface br0 inet dhcp
  bridge_ports eth0
  bridge_maxwait 0

Then you need to install the bridge-utils package and restart your network interface:

# apt-get install bridge-utils
# ifdown eth0
# ifup br0

Create a script call /etc/qemu-ifup that will be executed upon the start of QEMU:

echo "Executing /etc/qemu-ifup"
echo "Bringing up $1 for bridged mode..."
sudo /sbin/ifconfig $1 0.0.0.0 promisc up
echo "Adding $1 to br0..."
sudo /usr/sbin/brctl addif br0 $1
sleep 2

As you probably don't want to execute QEMU as root, you need to create a qemu user group and authorize the brctl and ifconfig commands for users of the qemu via sudo. You need to add the following lines to /etc/sudoers (edit the file using visudo):

...
Cmnd_Alias QEMU = /usr/sbin/brctl, /sbin/ifconfig
%qemu ALL=NOPASSWD: QEMU

Tap networking requires that the tun module is loaded:

$ sudo modprobe tun

To load it automatically on boot, edit /etc/modules and add a line that says "tun" so that the file looks like this:

# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.

lp
tun

Finally you can start your emulated machine using the following command

$ qemu-system-arm -M versatilepb -kernel ./vmlinuz-2.6.28-versatile -hda arm-rootfs.img -m 256 -append "root=/dev/sda mem=256M ro" -net nic,macaddr=00:16:3e:00:00:01 -net tap

You don't need to give a MAC address if you are emulating only one machine, as QEMU will use a default one. However if you have more than one emulated machine (don't forget QEMU can also emulate other architectures than ARM), you will have to specify a unique MAC address for each machine. I advise you to select an address from the range 00:16:3e:xx:xx:xx, which has been assigned to Xen.

Bugs and Problems

If you run into any problems, please contact "ogra" in #ubuntu-arm on irc.freenode.net or send a mail to ogra@ubuntu.com

If you run into an error please keep the log of your failed build

A known issue is that language-pack handling is not implemented yet, please install the packages for your language manually post install.

ARM/RootfsFromScratch (last edited 2011-01-11 20:51:24 by 63)