Using QEMU to test big-endian code on Intel-powered OS XEdit

I tried to do this the other day. My first attempt progressed fairly well, although with a lot of yak shaving, but ultimately didn’t work. I began a second attempt but ended up aborting it because somebody else did the big-endian testing for me, obviating the need.

Here are the scattered notes that I made along the way.

Resources

Installing qemu

$ brew install qemu

Setting up a PowerPC Debian installation: first attempt

For my first attempt I used the latest "qcow2" disk image format, which turned out to be a bad choice because I couldn’t mount it on my OS X machine to get the necessary init ramdisk and kernel files:

$ qemu-img create -f qcow2 /tmp/disk.img 8G

Installing the latest Debian (7.6.0 at the time of writing):

$ sudo qemu-system-ppc \
  -m 1024 \
  -hda /tmp/disk.img \
  -cdrom ~/Downloads/debian-7.6.0-powerpc-CD-1.iso \
  -boot d

Note that installing the bootloader fails, so "Continue without boot loader", and observe that the installer advises:

You will need to boot manually with the /vmlinux kernel on partition /dev/sda2 and root=/dev/sda3 passed as a kernel argument

Mounting the disk

After installation, in order to boot the system you need the initrd and kernel files from the disk image.

I tried to attach the disk image on OS X in order to get the initrd and kernel files:

$ hdiutil attach -imagekey diskimage-class=CRawDiskImage -nomount filename
$ hdiutil mount /dev/disk2

Alas, this doesn’t work:

mount failed - no mountable file system

So, time to create a Linux VM and mount the image on that. Relevant resources:

Set up a shared folder, make sure you set up to automount or it probably won’t be writable. "diskimages" is the name chosen in the VirtualBox shared folder settings dialog:

$ mkdir ~/r
$ sudo mount -t vboxsf diskimages ~/r
$ cd ~/r
$ ls # observe we can see the disk QEMU image

Mounting the raw image

I tried converting the image from "qcow2" to "raw" format in order to mount it directly, but that didn’t work:

$ fdisk -l r/disk.img
$ sudo touch /mnt/loop
$ sudo mount -o ro,loop,offset=32256 r/disk.dmg /mnt/loop -t ext4

So instead I tried this:

$ sudo modprobe nbd max_part=8
$ sudo apt-get install kvm
$ sudo qemu-nbd --conect /dev/nbd0 r/disk.img
$ mkdir m
$ sudo mount /dev/nbd0p2 m
$ cd m
$ cp initrd.img-3.2.0-4-powerpc vmlinux-3.2.0-4-powerpc r/

That last step failed because the VirtualBox shared folder had mounted in read-only mode. I rebooted the Linux VM with the shared folder set to automount after first doing this:

$ sudo usermod -aG vboxsf $(whoami)

For more on permissions issues, see:

After all that, I could try to boot into the new system:

$ sudo qemu-system-ppc \
  -m 1024 \
  -hda /tmp/tmp/disk.img \
  -kernel ./vmlinux-3.2.0-4-powerpc \
  -initrd ./initrd.img-3.2.0-4-powerpc \
  -append "root=/dev/hda3"

Attempt two

$ qemu-img create -f raw /tmp/disk.img 8G # ie. raw format this time
$ sudo qemu-system-ppc \
  -m 1024 \
  -hda /tmp/disk.img \
  -cdrom ~/Downloads/debian-7.6.0-powerpc-CD-1.iso \
  -boot d

Note: the screen can be very dark on booting, but there is a prompt that is waiting for you to press enter.