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.
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.
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!
- Download VirtualBox for your platform.
- 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…
- Create a new machine on VirtualBox, take the defaults, choose to create a new disk for it.
- Start the machine up.
- You get the first-time start-up dialogue.
- Choose to boot from the ISO image you downloaded.
- Choose your language/country etc. Let it run for a bit.
- 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!
- 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…
- Use the guided partitioning mode at the top.
- Choose to put all the files on one partition and write the changes to the disks.
- 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.
- This is going to take a while, I can tell!
- 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.
- Choose the options you like. I just left it as a ‘GUI’ and the recommended/default options.
- 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.
- Yay! Installation is complete. I’ll believe it when I see it 😉
- Now it’s running clean-up… Oh, I hope it moves on from 65% soon, otherwise… Ah. There we go.
- Rebooting automatically.
- Hmmm. Get the boot choice again… does that mean it’s going to start the install again? God, I hope not!
- I have a black screen… some kind of progress swirly…. Ah! Desktop!
- Go ahead and login. Don’t use root, use the ‘other’ account you created.
- Love the retro rocket-and-planet motif. Taking a while for anything to happen… Probably just a first-login thing.
- 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.
- Right, let’s see what we’ve got and if we can carry on with the emulation stuff…
- From the Applications->Accessories menu, start up a terminal.
- You should get a shell prompt with your ‘other’ username attached to it.
- Right, install the qEmu stuff.
- 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.
- apt-get update(i.e. update the package database).
- apt-get install qemu
(Go and get and install the qemu package)
- 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!
- 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.
- mkdir pi_emu
- cd pi_emu
- wget xecdesign.com/downloads/linux-qemu/kernel-qemu
- This will get the qEmu kernel, which makes everything run. I hope.
- 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:
- wget <url>
- 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…
- Unzip the file your downloaded (you will have to change this filename to whatever is now in your folder.
- To get a list of files, the Linux command is ‘ls’.
- unzip yyyy-mm-dd-whatever.zip
(to unzip it)
- This takes a while as well as it needs to expand the 440M file to a roughly 2GB file. Gawd bless file compression.
- 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.
- chown otheruser *
- chown otheruser *.*
- You should now be back at a prompt that looks like
- Now, going to use a modified version of the command from the Southend site to start it up. Here goes:
- 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
- The last argument there is the .img file that you decompressed just now.
- 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.
- 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…
- Not bad so far. Oooh! The usual Raspberry Pi first start-up screen! Yay!
- Choose the ‘update raspi-config’ option at the bottom just so you are up-to-date.
- Now re-run that utility:
- 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’.
- Now we do ‘startx’
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!
Here we enter the murky world known colloquially, by me, as “Oh, Bluetooth, why do you mock me?”
This has been the biggest pain in the butt to get working, but hey, no-one ever said that the RPi was going to be easy.
Nice logo, isn’t it. Took me all of 30 seconds to search for it on Google images.
Installing the Bluetooth stack
Let’s remember, folks, Bluez is the official bluetooth stack for Linux! So it should work on everything, yes? Yeah, right. Here we go with the steps…
- Start the Pi, login as root.
- apt-get install bluetooth bluez-utils blueman
- From left to right, that’s:
- The stack. (A very large thing indeed)
- Command line utils. (A very useful thing indeed)
- X-windows interface. (A very slow thing indeed).
- Go and make yourself a coffee. This takes ages, especially over wi-fi. In fact, you could probably go and cook dinner.
Scanning and connecting
Onto the good bit. Getting your bluetooth device connected. In my case, I have a Rii bluetooth keyboard/touchpad.
My one came with a nano USB bluetooth dongle. In other words, it’s very small. Which is good.
- Okay, so you have the stack installed.
- Turn your Rii on and put it in discoverable mode.
- On your Pi, type “hcitool scan” to see if you can find your device.
- You should get a list of devices back in your area. The Rii comes up as “Macro Keyboard”. A stunning name, to be sure.
- Make a careful note of the string of numbers, colons and letters.
- Do the following to create a connection script:
- cd ~
- mkdir bin
- cd bin
- Create a file called auto_connect_bluetooth.sh and open it in your editor. Add the following lines. Put the string of numbers, colons and letters that you noted down before instead of XX:XX etc.
#!/bin/sh/usr/bin/bluez-test-device trusted XX:XX:XX:XX:XX:XX yes/usr/bin/bluez-test-input connect XX:XX:XX:XX:XX:XX
- Save the file and exit from the editor.
- chmod +x auto_connect_bluetooth.sh
- (This makes the file executable so you can do the next bit).
- Open /etc/rc.local in the editor. Add the following command before the exit command at the end of the file.
- sudo -u root /root/bin/auto_connect_bluetooth.sh
- This should run your connection script before the login prompt comes up.
- Before you do a reboot, make sure your bluetooth device is still in discoverable mode.
- Reboot and see if your device connects!
- Well… it doesn’t.
- You need to go into X windows (startx) and use the blueman-manager applet to pair up the device, trust it and connect to the input service.
- Once you’ve done that, and reboot, and it should connect this time.
If you find those last few steps unfollowable, comment on this post and I’ll try and flesh it out a bit.
Install VNC and Auto Start
First of all, make sure you expand the SD card – you don’t want to run out of space!
- apt-get install tightvncserver
- Yes, you want it to install, so accept the space it tells you it’s going to use!
- It’ll go through the usual install procedure and eventually put you back at the shell prompt.
- tightvncserver :1
- (This will create a few files it needs to run)
- Set a password when it asks. Don’t bother with a view password unless you really want one – it’s just a pain.
- Edit the /etc/rc.local file and add the following before the ‘exit’ command at the bottom.
- sudo -u root /usr/bin/vncserver :1 -geometry 1024×768 -depth 16 -pixelformat rgb565 -fp /usr/share/fonts/X11/misc/,/usr/share/fonts/X11/Type1/,/usr/share/fonts/X11/75dpi/,/usr/
- Save the file, back to the prompt you go.
- This will mean that your VNC server starts up before you need to login on port 1 and a screen size of 1024×768.
- Reboot. Watch that magic happen. Dude. S’up.
The reason you do sudo is that it needs to know who to run the server as – remember, you’re not logged in before the login prompt comes up!
Now, you should be able to reboot and connect to the VNC server from your laptop, for instance.
I know of no better way than getting WiFi to connect automatically than using the wonderful wicd-curses package. So, here’s how to do it:
- Plug your wifi dongle in. I cannot impress on you enough how important this is 😉
- If you’ve not done it already, login as root and install wicd-curses:
- apt-get install wicd-curses
- Run it. Just type
- You’re given the wicd interface. You probably haven’t got anything showing yet, so do Shift-R to refresh the network scan.
- Use the arrow keys to highlight your router and press –>
- Go down and hit space when you reach the Automatic connection checkbox.
- Then, go down to the password field and put your wifi router password in.
- Hit F10 to save the settings and you’ll go back to the first screen.
- Highlight your router if it’s not already and hit shift-C to connect.
- Hopefully, this will connect you. If not, check your password!
- Do shift-Q to come out of wicd.
- Type ifconfig -a and you should see your wlan0 connected to your router and your ip address displayed.
The beauty of doing it like this rather than via the command line is that wicd runs as a daemon when your Pi starts up and will automatically connect to the network without you doing anything else.
NB: You may have to wait a minute or so for it to connect.
Oh, the trials and tribulations (or Tribbleations) of installing an operating system on the Pi. I tried about 5 operating systems before succeeding in my goals including Debian Wheezy, Fedora, Arch, Risc OS… They all failed in some way, mostly to do with a) WiFi and/or b) Bluetooth.
Eventually, I found an image that did work: Debian 6 19-04-12. And, yes, I do realise that this was the recommended one at the time… That’ll teach me to go cutting-edge! With this distro, I got everything working. Since then, the recommended distro has changed to the Raspian version of Debian Wheezy. Here’s the original RPi foundation post.
So, into the wonderful world of Raspian we go! Now, may aim here is to install everything without getting up from the sofa. i.e. No LAN connection
Here are the steps I took to get the Pi up-and-running. I might change tenses throughout, but hopefully I haven’t missed any steps! I’m on Windows 7, 64 bit, so any problems I have running apps on Windows may not affect you.
Installing the Operating System before the Pi starts up
- Download the Raspian image from the Raspberry Pi foundation.
- Get the SD card out of your Pi and put it into your laptop.
- The following steps are only if you have a current SD card OS for the Pi:
- Download Winimage. This is far better than the Win32diskimager, in that it starts up more reliably each time. I do, however, think that it’s a bit of a rip-off at $30. You may find other packages that can backup and restore images, and most of them are fine.
- Backup your card with Winimage (or whatever you have).
- Carrying on, we’re going to install Raspian onto the card.
- Using Winimage/Win32DiskImager, restore the image you downloaded onto the SD card. !!! Make sure you are restoring to the card and not your hard drive 😉
- If your SD card is larger than 2GB, you’re going to want to expand the card so that the OS has more room to breathe.
- Insert a USB stick, preferably one that is 2GB or more.
- Download the gparted Linux ISO.
- Using either Winimage, Win32DiskImager, unetbootin or the LinuxLive USB Creator (my preferred method), install the ISO you downloaded to the USB stick.
- Reboot your laptop with the USB stick in and have the laptop boot from the USB stick. You can do this in a variety of ways, depending on your laptop. Sometimes, you have to go into the Bios to make this work.
- Once the gParted OS is up, just follow the instructions and steps until you get the desktop.
- At this point, a window will open showing the partitions on your SD card. You should have a FAT format bit at the beginning, then a Linux partition and then an unused part at the end.
- Right-click the Linux partition and choose to Move/Resize. Click and drag the extent of the partition size bar until you have used ALL the disk EXCEPT about 1-2 GB at the end. Click OK or Continue.
- Now right click on the smaller unused space and make a new partition. Just use ext2 for now. This will eventually be our swap space (I hope!).
- Make sure you apply the changes and wait for it to finish.
- Shutdown the gParted OS desktop. This should turn your laptop off.
- Remove the USB stick. Your SD card should stay in for now.
- Start up your laptop again to Windows.
- Download the Linux firmware for the USB WiFi dongle you are going to use.
- My dongle runs on the ZD1211 firmware so I downloaded it from Sourceforge.
- Unzip/untar the firmware into a folder on Windows.
- Copy the folder onto the SD card.
- Remove the SD card safely.
First Pi start-up
- Put the SD card carefully into the Pi.
- Insert your dongle (oo-er, Mrs) into the Pi, and plug in a keyboard and a monitor. You will not get anywhere unless you can see what the Pi is doing and can type stuff in!
- Put the power lead in, try not to get motion-sick from the Linux start-up scrawl.
- When the prompt comes up, use the ‘root’ username. There won’t be a password at the moment.
- This should give you the shell/command line prompt.
- Now, you need to mount the SD card, despite it actually being what you’re running off. This is because you want access to the FAT partition where the firmware is.
- First of all, you want the number one partition on the SD card. I can’t remember what that is at the moment, but it’s the one in /dev/ that begins with mmc and has a ‘1’ in it.
- ls /dev – get the name of the mmc device to put into the mmc*** space below.
- mkdir /mnt/sd
- mount /dev/mmc*** /mnt/sd
- mkdir /lib/firmware/zd1211
- cp /mnt/sd/zd1211/* /lib/firmware/zd1211/
- You should now have your firmware in the right place.
- At the prompt, type ‘reboot’. This will, surprisingly enough, reboot the Pi. Hopefully. If it fails to come back up, pull the power, wait a few seconds and re-insert.
- When the Pi comes back up, your firmware should have loaded and your dongle should now be active.
- Fortunately, the library necessary for connecting to my WPA-secured router is included in this distribution. If it wasn’t, I’d have to plug it into the LAN and do:
- apt-get install wpa-supplicant
- But it is, so I don’t have to.
- You now need to know the ID of your router (the SSID to be more exact) and the connection password.
- Now, you will need to edit the file /etc/wpa_supplicant.conf
- I use vi, you don’t have to. I’m going to assume you’re using ‘nano’ which is easier to use.
- nano /etc/wpa_supplicant.conf
- This will create a new file.
- Add the following to the file:
ssid=”your router SSID”
psk=”your router connection password”
- Save the file & exit.
- Type the following at the prompt:
- wpa_supplicant -B -iwlan0 -c/etc/wpa_supplicant.conf -Dwext &
- (The & means it is a background process – if you don’t do this, you end up stuck in the command).
- Once it comes up with text that makes it sound like you’ve successfully connected, type:
- dhclient wlan0
- (This gets your IP address)
- Type ‘ifconfig -a’ at the prompt. The bottom one should be your wifi adapter and you should be able to see an ip address. If you don’t, well, you probably got the ssid/password wrong in the conf file.
- You should now be on the Internet.
Update the operating system and get a decent WiFi interface
- At the prompt, type:
- apt-get update
- This will update the package database so you can update your operating system.
- Once that’s done, do:
- apt-get upgrade
- This will upgrade any module that needs it. It will take some time.
- Once that’s done, do:
- apt-get install wicd-curses
- Say yes to it using up the space on the disk. Thanks to the steps with gparted you will have lots of space to play with.
- wicd-curses is an interface to wireless networking that you can use to see what other WiFi networks there are in the area and gives you a handy interface to enter passwords, automatically connect etc.
- Do another ‘reboot’ and when the Pi comes back up, login as root again and do:
- shutdown -h 0
- This will shut down your Pi. Wait until it says “System Halted” and then pull the power. (It may just switch off by itself, but once you see that message, it’s safe to pull the plug.
We will add the wpa_supplicant commands to rc.local to automatically start-up when we boot. And we will look at getting the Bluetooth keyboard/mouse all working nicely!