Running FatdogArm in Qemu

The previous article explains the general process of how to adopt FatdogArm for other platforms. This article will give an example of doing so for Qemu, a generic and open source machine emulator and virtualizer.

This article is similar and is in fact based on the older how to run Puppy ARM in Qemu article, but it is slightly different because of architectural differences between FatdogArm and Puppy Arm (Puppy Arm is a full-install-type distribution, while FatdogArm is a frugal-install-type distribution - which is closer to x86 version of Puppy Linux).

Updated 2014/03/10 for FatdogArm Alpha4 onwards. From Alpha4 onwards, FatdogArm no longer ships with image files; so one needs to make an image files from the SFS for use with Qemu.

Overview

The following table provide a summary of what we will do to make FatdogArm boots on Qemu; it is based on the steps outlined from AdoptingFatdogArm. As you can see most of the steps can be skipped because they are not needed on Qemu.

Adopting FatdogArm for Qemu
Steps from Adopting FatdogArm What we will do
1 Platform-specific bootloader Not needed, Qemu can boot kernel directly.
2 Platform-specific kernel Provided, we will use Vexpress or Realview compatible kernel.
3 Platform-specific kernel-modules Not needed, we will compile all our needed drivers are built-in, but we will use an initrd with all the modules taken away so it is smaller.
4 Modify fd-arm.sfs Not needed, Qemu will boot with fd-arm.sfs for Mele image.

Pre-requisites

  1. Familiarity with terminal operation, most of the commands given are meant to be typed into terminal.
  2. Qemu 1.5.0 or newer (tested with Qemu 1.5.3; in theory it should work with earlier Qemu as well, down to 1.2.2, but I have not tested that and Qemu 1.5.0 is oh so much faster than 1.2.2 ...)
  3. About 500MB of free disk space
  4. A relatively powerful machine, emulation is slow ...

Ingredients

  1. FatdogArm SFS from http://distro.ibiblio.org/fatdog/arm/releases
  2. Qemu initrd image from http://distro.ibiblio.org/fatdog/arm/releases/qemu
  3. Qemu kernels from from http://distro.ibiblio.org/fatdog/arm/releases/qemu
  4. And of course, the qemu-fatdog-arm.sh script, also from http://distro.ibiblio.org/fatdog/arm/releases/qemu . You don't need this script, but it helps to get you started.

Basic steps

  1. Get all the pre-requisites and ingredients. Especially for qemu - get it from your favorite repository, if it is not available there, pester your favorite pet maker to make one for you :)

    Note for pet maker: Building qemu takes a very long time if you build all of its targets, but you don't need all of them. The only target that you need is arm-softmmu.

  2. Install qemu pet.

  3. Move the rest of the ingredients (the startup script, initrd, kernel and the FatdogArm SFS) the into a directory (e.g. /mnt/sdb1/fdarm)

  4. Open terminal within that directory.

  5. Create an image file (fd-arm.img) that will contain the SFS (this will also enable you to save settings)
    head -c 512M /dev/zero > fd-arm.img
    mount -o loop fd-arm.img /mnt/data
    mv fd-arm.sfs /mnt/data
    umount -d /mnt/data
    
    Notes: You can of course change that 512M to any other figure as needed. /mnt/data is a temporary mountpoint, you can use any other. If you want to keep the SFS for something else, use cp instead of mv. You can skip this step and use an alternate step to use the SFS directly, but you will not be able to save your session.

  6. Launch it from terminal like this:

    ./qemu-fatdog-arm.sh vexpress
    
    Launching FatdogArm using vexpress kernel, with 1GB RAM
    or
    ./qemu-fatdog-arm.sh realview
    
    Launching FatdogArm using realview kernel, with 512MB RAM

  7. That's it! FatdogArm will boot straight to desktop. Depending on your machine, however, you may need to be patient, as emulation is slow ...

  8. To turn off, just use the power-off function from inside FatdogArm as usual. At one point the screen will turn black showing the message System Halted; at this stage you can break (Ctrl-C) the script that launches FatdogArm. Sometimes Qemu can finish and exit by itself without the Ctrl-C, sometimes you do need that Ctrl-C.

Saving your changes

When you shutdown your session, FatdogArm will ask you where to keep the changes you made during the session - this includes the additional programs you install, data that you download, etc.

If you don't want to save anything, just click Cancel.

This is only possible if you use an image file. If you don't, it will still ask you but there is nowhere to save.

Networking and sound

  1. To enable network, just type udhcpc -qi eth0 from a terminal inside FatdogArm itself (it should be automatically be started anyway).

  2. If Qemu is compiled to support sound, you can output sound too, for example type one of these:
    aplay /usr/share/sounds/alsa/Front_Left.wav
    speaker-test -t wav -c 2
    
    in terminal (from within Qemu) and you should hear something.

Adjusting the screen size

  1. From the console, you can change the screen size by typing (for example):
    fbset 800x600-60
    
    to get 800x600 resolution. To see the available modes, check out /etc/fb.modes. Not all modes can be used.

  2. If you want to change the screen size for the graphical desktop, create a text file in /etc/X11/xorg.conf.d/ and called it 30-screen-size.conf; and fill that newly created file with the following:

    Section "Screen"
    Identifier "Default Screen"
    SubSection "Display"
    Depth 16
    Modes "800×600" "640×480"
    EndSubSection
    EndSection
    

    For that to take effect, you need to restart the desktop. Change "800x600" to whatever resolution you wish (within reason).

Data transfer to/from FatdogArm

How to transfer data to/from the emulated FatdogArm? There are many ways - here is one of the easier way of doing it.

This instruction will also work on the FatdogArm running on real hardware, not only Qemu. Instead of "localhost" and port "2222", use the real machine's IP address and port "22". Everything else is the same.

Notes: Running directly from fd-arm.sfs

You can run the emulation directly using fd-arm.sfs instead of creating image file first, but you wouldn't be able to save any sessions (since the SFS is read-only). To do this, you would need to "pad" the SFS into a multiple of 256K. The following script will do so:

#!/bin/sh
# $1-path to original sfs
# $2-output (optional: ./fd-arm.sfs)
[ -z $1 ] && exit
INSFS=$1
OUTSFS=${2:-fd-arm.sfs}
ORIGSIZE=$(stat -c %s $INSFS)
BLOCKS256K=$(( ((ORIGSIZE/1024/256)+1) ))
#echo $ORIGSIZE $BLOCKS256K $((BLOCKS256K*256*1024))
cp $INSFS $OUTSFS
dd if=$INSFS of=$OUTSFS bs=256K seek=$BLOCKS256K count=0
Script to pad SFS to 256K boundary

and then launch qemu like this:

IMAGE=fd-arm.sfs ./qemu-fatdog-arm.sh vexpress basesfs=local:/

The modified SFS is still good and can still be used for use in image files or for use in booting real hardware.

References

Running Puppy Arm for Raspberry Pi without Raspberry Pi.