You have two options:
- Use a Ubuntu Desktop version with Gnome environment already preinstalled (do you really need all that crap?!)
- Install a brand new Ubuntu server 12.04 x64 LTS, basic, without Gnome or any super fancy packages… just a basic installation with SSH (suggested but not required). And after, just follow the post here to install a “Minimal X server”.If you want to change a bit the look of the login screen, you can have a look to this post.
This is what I’ve done 🙂
Please note that a graphic environment is REQUIRED for this emulator to work.
Compile and install QEMU
Packages:
1 |
sudo apt-get install git zlib1g-dev libsdl1.2-dev libpixman-1-dev |
Working directory:
1 |
mkdir ~/raspidev && cd ~/raspidev/ |
1 |
git clone git://git.qemu-project.org/qemu.git |
It will take a while
Once done:
1 2 |
cd qemu ./configure --help |
Read the output carefully (options of interest highlighted):
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 Usage: configure [options]Options: [defaults in brackets after descriptions]Standard options:--help print this message<span style="color: #0000ff;">--prefix=PREFIX install in PREFIX [/usr/local]</span>--interp-prefix=PREFIX where to find shared libraries, etc.use %M for cpu name [/usr/gnemul/qemu-%M]<span style="color: #0000ff;">--target-list=LIST set target list (default: build everything)</span>Available targets: i386-softmmu x86_64-softmmu<span style="color: #0000ff;">arm-softmmu</span> cris-softmmu lm32-softmmu m68k-softmmumicroblaze-softmmu microblazeel-softmmu mips-softmmumipsel-softmmu mips64-softmmu mips64el-softmmuppc-softmmu ppcemb-softmmu ppc64-softmmu sh4-softmmush4eb-softmmu sparc-softmmu sparc64-softmmus390x-softmmu i386-linux-user x86_64-linux-useralpha-linux-user <span style="color: #0000ff;">arm-linux-user</span> armeb-linux-usercris-linux-user m68k-linux-usermicroblaze-linux-user microblazeel-linux-usermips-linux-user mipsel-linux-user ppc-linux-userppc64-linux-user ppc64abi32-linux-usersh4-linux-user sh4eb-linux-user sparc-linux-usersparc64-linux-user sparc32plus-linux-userunicore32-linux-user s390x-linux-userAdvanced options (experts only):--source-path=PATH path of source code [/home/shift/openembedded/qemu]--cross-prefix=PREFIX use PREFIX for compile tools []--cc=CC use C compiler CC [gcc]--host-cc=CC use C compiler CC [gcc] for code run atbuild time--extra-cflags=CFLAGS append extra C compiler flags QEMU_CFLAGS--extra-ldflags=LDFLAGS append extra linker flags LDFLAGS--make=MAKE use specified make [make]--install=INSTALL use specified install [install]--python=PYTHON use specified python [python]--static enable static build [no]--mandir=PATH install man pages in PATH--datadir=PATH install firmware in PATH--docdir=PATH install documentation in PATH--bindir=PATH install binaries in PATH--sysconfdir=PATH install config in PATH/qemu--enable-debug-tcg enable TCG debugging--disable-debug-tcg disable TCG debugging (default)--enable-debug enable common debug build options--enable-sparse enable sparse checker--disable-sparse disable sparse checker (default)--disable-strip disable stripping binaries--disable-werror disable compilation abort on warning--disable-sdl disable SDL<span style="color: #0000ff;">--enable-sdl enable SDL</span>--disable-vnc disable VNC--enable-vnc enable VNC--enable-cocoa enable COCOA (Mac OS X only)--audio-drv-list=LIST set audio drivers list:Available drivers: oss alsa sdl esd pa fmod--audio-card-list=LIST set list of emulated audio cards [ac97 es1370 sb16 hda]Available cards: ac97 es1370 sb16 cs4231a adlib gus hda--block-drv-whitelist=L set block driver whitelist(affects only QEMU, not qemu-img)--enable-mixemu enable mixer emulation--disable-xen disable xen backend driver support--enable-xen enable xen backend driver support--disable-brlapi disable BrlAPI--enable-brlapi enable BrlAPI--disable-vnc-tls disable TLS encryption for VNC server--enable-vnc-tls enable TLS encryption for VNC server--disable-vnc-sasl disable SASL encryption for VNC server--enable-vnc-sasl enable SASL encryption for VNC server--disable-vnc-jpeg disable JPEG lossy compression for VNC server--enable-vnc-jpeg enable JPEG lossy compression for VNC server--disable-vnc-png disable PNG compression for VNC server (default)--enable-vnc-png enable PNG compression for VNC server--disable-vnc-thread disable threaded VNC server--enable-vnc-thread enable threaded VNC server--disable-curses disable curses output--enable-curses enable curses output--disable-curl disable curl connectivity--enable-curl enable curl connectivity--disable-fdt disable fdt device tree--enable-fdt enable fdt device tree--disable-check-utests disable check unit-tests--enable-check-utests enable check unit-tests--disable-bluez disable bluez stack connectivity--enable-bluez enable bluez stack connectivity--disable-slirp disable SLIRP userspace network connectivity--disable-kvm disable KVM acceleration support--enable-kvm enable KVM acceleration support--disable-nptl disable usermode NPTL support--enable-nptl enable usermode NPTL support--enable-system enable all system emulation targets--disable-system disable all system emulation targets--enable-user enable supported user emulation targets--disable-user disable all user emulation targets--enable-linux-user enable all linux usermode emulation targets--disable-linux-user disable all linux usermode emulation targets--enable-darwin-user enable all darwin usermode emulation targets--disable-darwin-user disable all darwin usermode emulation targets--enable-bsd-user enable all BSD usermode emulation targets--disable-bsd-user disable all BSD usermode emulation targets--enable-guest-base enable GUEST_BASE support for usermodeemulation targets--disable-guest-base disable GUEST_BASE support--enable-user-pie build usermode emulation targets as PIE--disable-user-pie do not build usermode emulation targets as PIE--fmod-lib path to FMOD library--fmod-inc path to FMOD includes--oss-lib path to OSS library--enable-uname-release=R Return R for uname -r in usermode emulation--sparc_cpu=V Build qemu for Sparc architecture v7, v8, v8plus, v8plusa, v9--disable-uuid disable uuid support--enable-uuid enable uuid support--disable-vde disable support for vde network--enable-vde enable support for vde network--disable-linux-aio disable Linux AIO support--enable-linux-aio enable Linux AIO support--disable-attr disables attr and xattr support--enable-attr enable attr and xattr support--enable-io-thread enable IO thread--disable-blobs disable installing provided firmware blobs--enable-docs enable documentation build--disable-docs disable documentation build--disable-vhost-net disable vhost-net acceleration support--enable-vhost-net enable vhost-net acceleration support--enable-trace-backend=B Set trace backendAvailable backends: nop simple stderr ust dtrace--with-trace-file=NAME Full PATH,NAME of file to store tracesDefault:trace-<pid>--disable-spice disable spice--enable-spice enable spice--enable-rbd enable building the rados block device (rbd)--disable-smartcard disable smartcard support--enable-smartcard enable smartcard support--disable-smartcard-nss disable smartcard nss support--enable-smartcard-nss enable smartcard nss support--disable-usb-redir disable usb network redirection support--enable-usb-redir enable usb network redirection support--disable-guest-agent disable building of the QEMU Guest Agent--enable-guest-agent enable building of the QEMU Guest AgentNOTE: The object files are built at the place where configure is launched
Easiest way:
1 |
./configure --help | egrep -i "PREFIX|everything|arm-softmmu|arm-linux-user|SDL" |
Then, compile and install:
1 2 |
make sudo make install |
Check that all is fine:
1 |
qemu-system-arm -cpu ? |
The output should contain ‘arm1176‘. If all is good, go to the next steps. 😉
Create the emulation environment
1 2 |
cd ~ mkdir raspemu && cd raspemu |
Get the linux kernel:
1 |
wget http://xecdesign.com/downloads/linux-qemu/kernel-qemu |
Download a raw image of Raspberry Pi from here and save in the same folder
1 |
wget http://downloads.raspberrypi.org/raspbian_latest |
If you want to play a bit with it, you might need to pre-expand the file size, in order to have some extra space (by default you have only 200 Mb free on the current image).
For this, you can use the following commands, to add 2GB to the image:
1 |
dd if=/dev/zero bs=1M count=2048 >> path/your_image.img |
Then, launch your qemu, and inside the console, try to useraspi-config
script to automatically expand the filesystem.
Otherwise, try the following to do it manually (not tested):
1 2 3 4 5 6 7 8 9 10 11 12 13 |
PART_START=$(parted /dev/sda -ms unit s p |grep “^2? | cut -f 2 -d:) echo $PART_START # (to be sure that it’s not empty). fdisk /dev/sda <<EOF p d 2 n p 2 $PART_START p w EOF |
Then reboot and launch resize2fs /dev/root
Now, you’re ready for the first boot.
Create a script called first_boot.sh with the following:
1 |
qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw init=/bin/bash" -hda <strong>$1</strong> |
Remember to setchmod +x
to this file and do not try to use more than 256 MB of RAM, the value is hard-coded in and QEMU will not work correctly.
After you can easily use this syntax to start your image:
1 |
./first_boot.sh path/your_image.img |
Comment the line/usr/lib/arm-linux-gnueabihf/libcofi_rpi.so
in the file/etc/ld.so.preload
and reboot.
Alternatively create a file/etc/udev/rules.d/90-qemu.rules
with the following content:
1 2 3 |
KERNEL=="sda", SYMLINK+="mmcblk0" KERNEL=="sda?", SYMLINK+="mmcblk0p%n" KERNEL=="sda2", SYMLINK+="root" |
The kernel sees the disk as /dev/sda, while a real pi sees /dev/mmcblk0. This will create symlinks to be more consistent with the real pi.
Once done, you can create a new script called start.sh with the following content:
1 |
qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw" -hda <strong>$1</strong> |
And now, finally, we can run our image of Raspberry Pi running:
1 |
./start.sh path/your_image.img |
NOTE: use first_boot.sh script ONLY with a brand new image. If you’re using a copy of your Pi, maybe made using dd command, just use start.sh script.
Sources:
http://xecdesign.com/compiling-qemu/
http://xecdesign.com/qemu-emulating-raspberry-pi-the-easy-way/