Raspberry Pi emulation

Taking a quick break from my PiPod project, which is essentially done, bar photos and videos of it actually working!

I’ve decided that having a “virtual Pi” would be handy so that I can mess about with the OS without worrying too much! Plus, it means I don’t have to carry my Pi around with me all the time if I just want to try some Python etc out.

Important note:
For Windows users, it seems that the recommended solution for emulating the Pi is to use qEmu on Windows. Take a look at this Sourceforge project: Raspberry Pi Emulation in Windows.

Virtual Box

Just so you know what you’re installing on your main computer… VirtualBox is a wonderful, free, virtual computer creator and viewer. There are a variety of platforms it works on. I’m actually using a version I already have on my Windows 7, 64-bit machine.

Emulating the Pi

I’m referencing this guide from the Southend Linux User Group to a certain extent. I know, random, but that’s what Google came up with!
I should say before we begin that I’ve tried both the ‘Lenny’ and ‘Sarge’ Debian installs available from virtualboxes.org and neither of them worked (Lenny stopped at “Select and install software”, Sarge gave a rather horrid “Kernel panic”) hence I now use the official Debian site download instead!
  1. Download VirtualBox for your platform.
  2. Download a net install ISO image from debian.org itself.I’ve chosen the i386 small CD in the top-left area. 191MB to download…
  3. Create a new machine on VirtualBox, take the defaults, choose to create a new disk for it.
  4. Start the machine up.
    1. You get the first-time start-up dialogue.
    2. Choose to boot from the ISO image you downloaded.
    3. Choose your language/country etc. Let it run for a bit.
    4. Now, this installer looks very similar to the one that stopped on the Select and Install Software dialog, so hopefully it’ll work better than that one!
    5. Take the defaults all the way through, no need to be picky unless you want to. Set the root password, create a new account, set that password…
    6. Use the guided partitioning mode at the top.
    7. Choose to put all the files on one partition and write the changes to the disks.
  5. Off it goes, partitioning away, installing the ‘base system’. This is where it starts extracting the downloaded packages and going off to download and install the rest of the OS.
  6. This is going to take a while, I can tell!
  7. Now we’re onto ‘Select and Install Software’… Holding my breath…Ooooh. It’s gone to 12% and still running… This could be good. Yep, “Retrieving file” counter still running… Goooood.
  8. Choose the options you like. I just left it as a ‘GUI’ and the recommended/default options.
  9. Some time later…
    Yes, I think I will install the GRUB boot loader. If only because I saw that the absence of this affected installation attempt number 2.
  10. Yay! Installation is complete. I’ll believe it when I see it 😉
  11. Now it’s running clean-up… Oh, I hope it moves on from 65% soon, otherwise… Ah. There we go.
  12. Rebooting automatically.
  13. Hmmm. Get the boot choice again… does that mean it’s going to start the install again? God, I hope not!
  14. I have a black screen… some kind of progress swirly…. Ah! Desktop!
  15. Go ahead and login. Don’t use root, use the ‘other’ account you created.
  16. Love the retro rocket-and-planet motif. Taking a while for anything to happen… Probably just a first-login thing.
  17. Hmmm. Okay… That’s a crappy GUI… no start bar or icon dock or anything… I can soon install something new of course. Oh, I see… there’s a menu bar at the top. Kind of merges into the VirtualBox menu. Some kind of message about Guest Additions came up but I missed it.
  18. Right, let’s see what we’ve got and if we can carry on with the emulation stuff…

Terminal Time

  1. From the Applications->Accessories menu, start up a terminal.
  2. You should get a shell prompt with your ‘other’ username attached to it.
  3. Right, install the qEmu stuff.
    1. su root (use the password you specified during install)I’m doing this because I can’t sudo… because I’m not in that group of users, which is unhelpful.
    2. apt-get update(i.e. update the package database).
    3. apt-get install qemu
      (Go and get and install the qemu package)
    4. Now, qemu is installed. That page I am referencing as a guide (the Southend one) makes it a lot more complicated than it needs to be!
  4. Now, you need to cd ~<other username> to go into the home folder of your ‘other’ user. We need to create a folder to mess around in and store kernels and disk images.
  5. mkdir pi_emu
  6. cd pi_emu
  7. wget xecdesign.com/downloads/linux-qemu/kernel-qemu
  8. This will get the qEmu kernel, which makes everything run. I hope.
  9. You now need to get the current Linux image for the Pi that is recommended by the RPi foundation. The one I am using is the first release of Raspbian Wheezy. But, always check for the latest one at their downloads page. Get the URL of the release and do:
  10. wget <url>
  11. This is NOT a small file – it’s about 440M, so go and get a cup of coffee.
This takes around 10 minutes to install at work, and we’re on a T1 connection. The reason it’s so slow is probably because of where the file is coming from rather than the connection itself.
And we’re back…
  1. Unzip the file your downloaded (you will have to change this filename to whatever is now in your folder.
    1. To get a list of files, the Linux command is ‘ls’.
    2. unzip yyyy-mm-dd-whatever.zip
      (to unzip it)
    3. This takes a while as well as it needs to expand the 440M file to a roughly 2GB file. Gawd bless file compression.
    4. Now, if you are logged in as root (and I was, so you should be!), you will need to make sure that the files in that folder are ‘owned’ by your other user, which will shall call ‘otheruser’. If you don’t do this, the .img file (and therefore the Virtual Raspberry Pi) will be ‘readonly’ when you run it using your otheruser account.
      1. chown otheruser *
      2. chown otheruser *.*
      3. exit
    5. You should now be back at a prompt that looks like
  2. Now, going to use a modified version of the command from the Southend site to start it up. Here goes:
    1. qemu-system-arm -kernel kernel-qemu -cpu arm1136-r2 -M versatilepb -no-reboot -append “root=/dev/sda2 panic=1” -hda 2012-07-15-wheezy-raspbian.img
    2. The last argument there is the .img file that you decompressed just now.
    3. Apparently, you can give it more memory by adding the “-m 512” argument to the end, but I just want it started up for now.
    4. I’m getting a few ‘readonly file system errors’, so it’s possible I might have to change permissions on the .img file before it works, but let’s just see…
    5. Not bad so far. Oooh! The usual Raspberry Pi first start-up screen! Yay!
    6. Choose the ‘update raspi-config’ option at the bottom just so you are up-to-date.
    7. Now re-run that utility:
      sudo raspi-config
    8. Choose the SSH server option and enable it. This will let you open a remote terminal to the Pi if you need to. Choose OK afterwards. Then choose ‘Finish’.
    9. Now we do ‘startx’
It’s interesting… the desktop comes up (although it’s blue, rather than raspberry-coloured… Odd). It’s a problem others have come up against.

For Windows users, it seems that the recommended solution is now: Raspberry Pi Emulation in Windows.

Never mind, it was an interesting practical experiment, which sort-of works apart from the colour issue. Non-Windows users may find these instructions still useful, so I will publish this post anyway!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.