Installing and running Debian armel on an emulated ARM machine on Windows (QEMU)
Autor: Eduardo Mercer | Publicado: 2011-09-21T01:39:00-03:00

Why, you ask me? Well, it all begun with Raspberry Pi... If you don't know the amazing, tiny, soon to be the greatest thing to happen to personal computing since... sliced bread?, please, do yourself a favor and click the link.


If you are feeling a little too TL;DR for that, maybe you should skip this post, but since I'm such a nice guy I'm willing to cut you some slack and give you the skinny: The RasPi is soon-to-be a tiny, sub-$50 full-featured computer. It is possible thanks to mobile technology, specially a System-on-a-Chip (SoC) manufactured by Broadcom for use in smartphones. It has a kick-ass graphics processor (capable of running 1080p video, or Quake 3, without heating much above body temperature. Don't take my word for it, click play and enjoy the show):


This amazing GPU is combined in the same package with a handful of on-board RAM (128 or 256MB, depending on version) and an ARM processor. Which is great, except that most of the software we use on a daily basis is built for Windows running on x86, not Linux on ARM. So people are excited about it, but at the same time they don't know if their favorite piece of software is gonna run on this puppy. And people being people (myself included), they don't want to wait until late November to get their hands on one. Therefore, here we are, trying to emulate it, at least well enough to test if we can compile... well, whatever the heck we may want to compile and run on the RasPi.
Full disclosure: You can emulate an ARM1176 on the latest versions of QEMU, but you cannot simply install a run-off-the-mill Linux distro on it, because no distro nowadays ships with compatible kernels. We could go thru all the trouble of cross-compiling one, and installing Debian using it, but we won't. Why? Because most software that runs on the ARM926 we are going to emulate will compile and run just fine on the ARM1176 core in the RasPi. If the emulated architecture were more advanced, like an ARMv7A, it would probably run software incompatible with the Raspberry Pi, like Adobe Flash 10. But since the ARM1176 is the natural replacement to the ARM926, emulating the earlier platform can have no impact other than performance, and that is already going to be puny thanks to being emulated anyways. Sure, you could also argue I'm just being lazy, and you'd not be far from the truth either.
First and foremost, you need to get yourself a copy of QEMU for Windows. I recommend downloading the latest binary from&nbsp;http://lassauge.free.fr/qemu/&nbsp;(some assembly required, it does not come with required&nbsp;fmod.dll, SDL.dll,&nbsp;mgwz.dll&nbsp;and&nbsp;libusb0.dll, but has links to current versions of the files and/or instructions to roll your own). You can also cut some corners and download your copy from&nbsp;http://homepage3.nifty.com/takeda-toshiya/qemu/&nbsp;(no longer updated, but has a version 0.13.0 of QEMU good enough for what we are trying here). If you're too lazy to bake your own DLLs, I have put together an easy to use ZIP file with QEMU 0.15 and all needed libraries. You can download it here.&nbsp;Just remember to unzip and/or compile all your QEMU files, including DLLs, to the same folder (hat-tip to&nbsp;obarthelemy&nbsp;@ the Raspberry Pi forums).
Edit: the networking section is under scrutiny in the Raspberry Pi forums. I'll be updating as I get new information from other users; if you can't get it to work, give us a call.

Now you'll need to download OpenVPN, in order to create a network tap. You can go straight ahead and click here. During installation it creates a couple of TAP-Win32 Adapters, one of which you can dispose of. Go to Adapter Settings - here's where to find'em on Windows 7:


- and rename your TAP-Win32 Adapter something single-worded, like TAP32.&nbsp;Now you'll need to manually set your TAP adapter. Right-click your it and select Properties. Once there, de-select all protocols, except the&nbsp;Internet Protocol Version 4 (TCP/IP v4).&nbsp;Click it&nbsp;and then Properties:




Tricky part: you'll need to know your gateway IP address, but I guess if you haven't given up on this tutorial already, you know your local network inside out. Set the IP manually to something within your subnet's range, but not used by any of your machines, as well as put your router's IP as gateway and DNS server. Here's a screenshot, just don't copy it, use your local values instead:


Once you hit OK and are back at the Network Connections windows, hold Control, select both the TAP adapter and the one you use to connect to the internet, right click'em and select Add to Bridge:


You'll get a new adapter type, a MAC Bridge Miniport. You don't need to rename it, but you might also need to manually set it's IP address, Gateway and DNS servers (your mileage with Windows' auto-config may vary). Just follow the steps for the TAP-Win32 adapter and you'll be fine. Okeydokey, network ready. Now you'll need to get acquainted with the Command Prompt. It sits here, inside your Accessories folder:


You can always just type&nbsp;CMD&nbsp;on the Start menu and hit Enter, and you'll get one of the little buggers (don't you love Windows 7?). Now navigate to the folder where you put your&nbsp;QEMU installations and run

qemu-img create -f raw hda.img imagesize
where&nbsp;imagesize&nbsp;is the size of the disk you wish to create for your emulated device. It accepts the format number+suffix, as in 256M for 256 megabytes or 2G for gigabytes, etc. for some reason, my&nbsp;qemu-img refused to accept 8G as an argument, so I entered 8096M instead. Go figure (it seems crundy @ the RasPi forums had the same problem with 4G. I recommend you always use 1024M instead of 1G when trying to make gigabyte-sized disks). You now have a virtual hard-drive where you're gonna install Debian. To do it, you'll need two things: a kernel&nbsp;and an initrd.&nbsp;The kernel, as the name implies, is the core of the Linux operating system. The initrd&nbsp;is the initial ramdisk, a file containing information the kernel expects to find inside your computer's memory in order to find bootable devices, etc. When doing a networked install, the initrd&nbsp;contains the basic installer software, which will, in turn, download the rest of the Linux distribution from the internet. The latest stable Debian distribution for ARM can be found at&nbsp;http://ftp.debian.org/debian/dists/stable/main/installer-armel/current/images/versatile/netboot/.Just point your browser there get initrd.gz and vmlinuz-2.6.32-5-versatile.&nbsp;Now you have your hard dirk image, kernel and initrd. Time to start having fun! (not). On your Command Prompt window, type


qemu-system-arm -L . -kernel vmlinuz-2.6.32-5-versatile -initrd initrd.gz -hda hda.img -m 256 -M versatilepb -net nic -net tap,ifname=networkname&nbsp;-append "desktop=lxde"

where networkname&nbsp;is the name of your TAP-Win32 adapter (you DO remember it, don't you?) and&nbsp;-append "desktop=lxde"&nbsp;is optional. If you leave it out, you'll get the default Gnome desktop (assuming you install a desktop environment, a part we'll be getting into soon). Adding the desktop&nbsp;boot parameter allows you to choose an alternate desktop environment, in this case LXDE, the Lightweight &nbsp;X11 Desktop Environment, which, the RasPi team informs us, is what we'll probably get with their boot images. It does help tons (pun intended) to replace Gnome with LXDE when everything runs so damn slow&nbsp;(no one said emulation was easy). Once you hit enter, assuming you did everything right (be sure to have all required files in the same folder), you'll be greeted with a new window:


Soon you'll see the Debian installer window. Select your local language, keyboard layout, country etc. according to your geographical location and preferred settings. The options are mostly idiot-proof, so when in doubt, just let the installer guide you. Unless you really do use a Domain on Windows, keep that field blank. Your Workgroup won't work, even if that's what the installer recommends (thanks again, obarthelemy!). Once the software selection screen comes up, be sure to select whatever packets you believe you'll need (including a graphical desktop environment, unless you're&nbsp;comfortable&nbsp;enough with Linux to leave that out). Don't go hitting Enter like I did the first time, the key you use to select packets is the space bar (duh!).


Now sit tight for what will be, depending on your connection, quite a long time. When the installer is finally done, it will warn you that no boot loader was installed. What it means is that you cannot simply reboot the Virtual Machine to load your freshly installed Linux. Wait for it to finish up and restart, then hit Control+Alt+2 to go to the QEMU console. This is where you can issue commands directly to the emulator. Simply type q&nbsp;and hit Enter to close QEMU (or you can just hit the big, red, X-button Your call). Now you'll need a new initrd&nbsp;(remember, the other one contains the installer payload, not the directions to boot your media). If we were running Linux, we could mount our virtual hard disk and copy the initrd from /root. Fortunately for us Windows users, we can also download one from&nbsp;http://people.debian.org/~aurel32/qemu/armel/. Go there, fetch yourself&nbsp;initrd.img-2.6.32-5-versatile and copy it to the QEMU folder. Now I recommend you open Notepad and make this new command into a batch file, otherwise you'll need to type this mouthful every time you want to run your emulated Linux box. Make sure to turn Word Wrap off in the Format menu and type  
 @qemu-system-arm.exe -L . -kernel vmlinuz-2.6.32-5-versatile -initrd initrd.img-2.6.32-5-versatile -hda hda.img -k en-us -m 256 -M versatilepb -net nic -net tap,ifname=networkname -append "root=/dev/sda1"   
where&nbsp;networkname&nbsp;is the name of your TAP-Win32 adapter (repeat myself much?).&nbsp;Now save it to the QEMU folder with the .BAT extension. To run the Virtual Machine, just double click the .BAT file and off we go. The system will boot mostly like the installer, but (depending on whether you installed a desktop environment) will go to a login screen (Gnome shown below). Type the name and password you've set up during installation and voilá! Linux on ARM!
 
 ...now, if you're too damn lazy to go thru the entire installation process, I have a treat for you: downloadable images! All you need is to install a Torrent client, then click here for LXDE or here for Gnome. Alternately, you can download them via RapidShare: click here for LXDE or here for Gnome. Just copy the files to your QEMU folder and double-click the corresponding .BAT file, you remiss indolent!
 
Thanks go to Francisco Benitez's great tutorial for installing Debian on QEMU, which I've adapted for Windows and updated, and to Ken's tutorial on Windows networking for QEMU. This page wouldn't exist if it wasn't for these and other great resources I found online.