This post is about Emulation of Raspberry Pi in windows system. In computers, an emulator is a hardware device or a program that pretends to be another particular device or program that other components expect to interact with. For example, using a 3270 emulator, a program written to be used with the 3270 workstation can communicate with and control a personal computer as though it were a 3270. Typically, an emulator is provided when a popular hardware device becomes outdated and no longer marketed but legacy application s exist that still need to communicate with the older device. The practice of using an emulator to make an older program work with a new end-use device is called terminal emulation .
Getting Started with the procedure:
1) Get an ARM Emulator for Windows
Now the first thing to realise is that the Raspberry Pi (version 1) device runs on an ARM11 processor (ARM1176JZFS) and so the Linux distributions for ARM will not work on virtualisers such as Virtualbox.
The Windows emulator of choice for everyone seems to be open-source processor emulator QEMU, which has support for ARM processor emulator. The QEMU site itself does not have a Windows binary download, but one is available here – provided by a guy called Eric Lassauge.
Download the latest stable version (currently 2.4.0) [direct link to file]
NOTE – Chrome seems to be blocking downloads from this site saying they are malicious files. You might need to switch off the Malware blocking option in Advanced Settings for it to be downloaded in Chrome. I’ve scanned it with my security software and it seems to be fine – but please check the file yourself for your own protection!!
Extract the ZIP file to a folder on your PC. It has no installer so you might want to copy the folder to your Program Files area. Anyway, the magic file here is qemu-system-armw.exe.
You’ll now need to get the QEMU-ready Linux kernel for the ARM11…
2) Get the ARM11 Linux Kernel
A lot of posts I read had differing kernels to use with QEMU and, to be honest, I’m not sure why – and most I tried just wouldn’t work for me – and they didn’t seem to be specifically Raspi friendly. So I found this guide for compiling a kernel specifically for the ARM1176 and the Raspi here. But you’ll probably just want to…
Download the pre-compiled version [direct link to file] (Thanks to XEC Design)
UPDATE: The XEC Design blog site is no longer online for some reason so the link above is to an archived version on Wayback Machine.
Move this file (called kernel-qemu with no extension) to the QEMU folder.
3) Get the Raspian Distro Image
I’m using the Raspian “wheezy” image (this is the image you would put onto your Raspi SD Card). Download this directly from the Raspberry Pi site.
Copy the image file into the QEMU folder.
4) Launch the Emulator with a Minimal Shell
Now we’re ready to launch the emulator from the command line:
qemu-system-armw.exe -M versatilepb -m 256 -cpu arm1176 -no-reboot -serial stdio -kernel kernel-qemu -hda 2015-05-05-wheezy-raspbian.img -append “root=/dev/sda2 panic=1 rootfstype=ext4 rw init=/bin/bash”
You should find it boots in the following minimal shell:
These are additional steps not in my previous version of this article (thanks to an article on Talksharp). We will use the following steps patch the Raspbian image to work with QEMU.
Use nano, to open the following file for edit:
– Comment out the first line by putting a # in front of it:
(Note: I had to press SHIFT + 3 to get a # symbol)
– Save the file and then exit the editor.
6) Symlink the Kernel Disks
We will now create Symlinks for the Kernel’s disks so that they match the names used on the Raspberry Pi.
Using nano create a new file:
Add the following text to the file:
– Save the file and exit nano.
Close QEMU by typing Exit and pressing Enter.
7) Resize the Image for Extra Space
We could boot the image now but we would only have around 200MB of free space, which is not really enough to do anything that useful. So before doing a full boot we’ll resize the image so we have more space. At Windows the command prompt run the following command:
qemu-img.exe resize 2015-05-05-raspbian-wheezy.img +4G
This will add an extra 4GB of space to the image file. However, the space won’t be available inside the Raspbian operating system until we expand it in the next step.
8) Perform a Full Boot and Expand Disk Space
At the command prompt run the following command to fully boot Raspbian:
qemu-system-armw.exe -M versatilepb -m 256 -cpu arm1176 -no-reboot -serial stdio -kernel kernel-qemu -hda 2015-05-05-raspbian-wheezy.img -append “root=/dev/sda2 panic=1 rootfstype=ext4 rw”
On my old laptop it took a while to boot-up in the previous version of this article, but on my shiny new one it is quite a bit quicker (possibly due a later version of Qemu as well). However, it can still take a few minutes to boot to the command line, so go and make a cup of tea.
During the boot, I noticed this:
It hung here for a minute or so, but then the boot continues. I’m not sure what this means, but it continued regardless. If anyone knows what this is all about, please post a comment. It’s possibly because QEMU cannot emulate all of the hardware.
All going well, we will eventually get to the command prompt, and we can log in as normal (default login is pi and password raspberry),
To make the image think it’s got an SD card, we need to create a symlink to/dev/root by entering the following command:
sudo ln -snf mmcblk0p2 /dev/root
To actually expand the file system, we need to go into Raspi-config. After logging in, at the command prompt type:
Select the Expand Filesystem option.
Once it’s finished, we can Quit QEMU and restart the image boot (using the batch command created earlier).
You should then be presented with the desktop (if you have Start Desktop on Boot configured). (Or use the startx command if you are in the Raspian command line), but this can take a very long while to start up!