[HOWTO] Run Porteus-ARM in an emulator (Qemu)

Ahau's work on porting Porteus to ARM devices
User avatar
Ahau
King of Docs
King of Docs
Posts: 1331
Joined: 28 Dec 2010, 15:18
Distribution: LXDE & Xfce 32/64-bit
Location: USA

[HOWTO] Run Porteus-ARM in an emulator (Qemu)

Post#1 by Ahau » 12 Mar 2013, 19:50

Qemu is a free and open source emulator that has built-in support for several arm boards. When you're starting to work with ARM hardware, it's useful to use an emulator until you get your hardware up and running, so you can play around a little bit and really put things together.

There are some excellent guides out there for running qemu, and I'll point in particular to the Slackwarearm HOWTO for those who are interested in installing a full slackwarearm system in qemu:

ftp://ftp.arm.slackware.com/slackwarear ... L_QEMU.TXT

Note that I haven't enabled networking access between the host and target, and I didn't use the qcow image format to create disk images -- I went a little more quick and dirty to get things running to the point where I could move to a real ARM board for more development.

Running inside qemu is very slow, so be patient. The system is faster on real hardware (specs depending).


Ok, let's get started: First, you'll want to install qemu. I've compiled version 1.4 for Slackware (32 and 64-bit) and built Porteus xzm modules, you can get them here:

32-bit: http://porteus-arm.googlecode.com/files ... -1Ahau.xzm
64-bit: http://porteus-arm.googlecode.com/files ... -1Ahau.xzm

Download qemu module for your architecture and activate it, or put it in /porteus/modules (so it's activated on every boot) and reboot.

Next, download the vexpress-express kernel tarball and the Porteus-ARM userland from here:

kernel: http://porteus-arm.googlecode.com/files ... -12.tar.gz
Userland: http://porteus-arm.googlecode.com/files ... -11.tar.gz

I'm using the versatile express board for a couple of reasons. First, it has better specs than the versatilepb board that ships standard with slackwarearm. I don't know what kind of performance increase this translates into (because qemu seems to be the bottleneck, not the virtual specs), but having 1G of ram is quite helpful when you're running in live mode and need room inside aufs. Second, I have to recompile the kernel to add aufs anyway, so it was good practice to get this up and running.

Ok, now that you have the tarballs, move them to a clean directory and extract both of them:

Code: Select all

tar -xvf vexpress_kernel-3-12.tar.gz 
tar -xvf Porteus-ARM-userland-3-11.tar.gz
Copy the kernel and initrd into your clean directory:

Code: Select all

cp vexpress_kernel/initrd.xz vexpress_kernel/zImage .
Copy the xzm module (000) with the kernel drivers/firmware into the extracted porteus/base folder:

Code: Select all

cp vexpress_kernel/000-vexpress-kernel.xzm porteus/base/
Next, we need to build a hard disk image file. This is a "sparse" file, meaning that it's full of zeros but occupies a lot of space ;) I'm building a small one here just to get porteus loaded (315MB), but you could make it larger if you want -- just increase the "count" value by 256 for every megabyte of space you want to add.

Here's the command to create the sparse file. As you can see, we're just lobbing zeros into a new file.

Code: Select all

dd if=/dev/zero of=porteus.img bs=4096 count=76800
Now format your image file -- for now you'll want to use ext2 for this, as I probably haven't even compiled other FS support into the versatile-express kernel yet.

Code: Select all

mkfs.ext2 porteus.img
click y to proceed with the operation

Mount your image on a loop so that you can access it like a mounted physical drive:

Code: Select all

mloop porteus.img
(mloop is a porteus script, so it won't be present if you're doing this in another distro, you'll want to mount -o loop it instead)

Copy the porteus files into your image:

Code: Select all

cp -ar porteus /mnt/loop
sync 
You can verify your data is in there, with 'ls /mnt/loop/porteus/base'. You should see modules such as '000-kernel-vexpress-3-11.xzm', '001-base-3-11.xzm', etc. -- remember the '000-kernel*' module came with the versatile express kernel -- in ARM (for the time being, at least), each board requires it's own kernel, and the drivers and firmware in the '000' kernel need to match up with that kernel.

Now unmount your image:

Code: Select all

uloop
You can now remove everything but the kernel, initrd and porteus.img file if you like. The kernel and initrd need to be visible to qemu, and the rest of the data will be used from inside the img file (save the tarballs somewhere in case you mess up later).

Now you can start qemu. I use a script that I adapted and shortened from a slackwarearm qemu startup script from:

Code: Select all

#!/bin/bash

qemu-system-arm \
   -M vexpress-a9 \
   -cpu cortex-a9 \
   -m 1024 \
   -kernel zImage \
   -usb \
   -sd porteus.img \
   -no-reboot \
   -serial stdio \
   -initrd initrd.xz \
   -append ' excheat mem=1024M raid=noautodetect console=ttyAMA0,38400n8 rootwait vmalloc=256MB devtmpfs.mount=0'
It's really one long line of script, with breaks using '\' so it's easier to read. Note that '-sd' means that we're emulating an sd card, not a hard drive. The Versatile Express board doesn't support SCSI/IDE drives, the only block device it will accept is sd. So, once you boot up, you'll be able to find the porteus data inside /mnt/mmcblk0/porteus

you can save that script as "start_qemu" and make it executable with "chmod +x start_qemu", and then start it all up with "./start_qemu".

This should open the qemu window and start porteus. Remember to be patient. You should get some kernel messages scrolling (inside the terminal in which you ran the script) within a few seconds, but it will take a few minutes for porteus to boot into the GUI.

Note that as of right now, LXDE is the default desktop. Xfce is also present, and you can boot into xfce by adding the 'xfce' cheatcode to the 'excheat' file inside the porteus.img, at /porteus/excheat. This is a little crutch I've implemented to allow passing cheatcodes to Porteus, because it can be difficult to modify boot parameters on some devices. On my tablet, for example, I'd have to recompile the kernel in order to change cheatcodes. 'excheat' works just like the 'append' line on an x86 system's bootloader config, but it can't modify kernel parameters, just the porteus-specific cheatcodes.

Please give Porteus-ARM a shot and let me know how it goes!

Thanks for reading!
Please take a look at our online documentation, here. Suggestions are welcome!

User avatar
fanthom
Moderator Team
Moderator Team
Posts: 5667
Joined: 28 Dec 2010, 02:42
Distribution: Porteus Kiosk
Location: Poland
Contact:

Re: [HOWTO] Run Porteus-ARM in an emulator (Qemu)

Post#2 by fanthom » 18 Mar 2013, 16:05

nice work Ahau!

followed your HOWTO and had no problems whatsoever with launching Porteus in Qemu:
http://oi45.tinypic.com/2rm9v8j.jpg

unfortunately it was a bit slow to work with :(
Please add [Solved] to your thread title if the solution was found.

Post Reply