Friday 27 April 2018

HOWTO: Virtual Raspbian on Qemu in Ubuntu Linux

Virtualise Raspbian Wheezy 2013-02-09 on Ubuntu Linux
Why?/What do I get?

It's a pretend Raspberry Pi, running completely in software, on your desktop, that you can use as if it is a real one (minus the ports and GPIO obviously). LXDE (Desktop) runs, and the internet/network is connected. You can SSH into it, make copies of it, trash it, start a new one from a previous saved copy, and generally do pretty much anything software-wise with it that you would do with a real one.

Drawbacks:

Using X (the desktop) may be a bit slow depending on your hardware. I ran this on an Intel d525mw dual core Atom board with 4GB of RAM and a fresh install of Ubuntu 12.10, and the desktop was sluggish at best, and sometimes unresponsive. The console was very quick, and was like using the real thing.

Qemu is a typical old-school Linux console app - it's pretty terse with error messages, and has esoteric command line switches. I'm going to check out some Qemu managers in the Ubuntu Software Store.

Needed:

Ubuntu 12.10 Desktop installed and running with up-to-date packages/list
- http://www.ubuntu.com/download/desktop

Raspbian Wheezy 2013-02-09
- http://www.raspberrypi.org/downloads

Linux kernel for Qemu
- http://xecdesign.com/downloads/linux-qemu/kernel-qemu

Internet connection

(Note that a Raspberry Pi is not required for this)

Notes:

These instructions may very well work with Ubuntu 12.04 LTS and earlier, as well as Debian, Mint, and other Linux's/Linuxi/Linuxes. If you have a non-Debian distribution, you will need to use your package managers commands instead of apt-get.

Thanks:

http://xecdesign.com/qemu-emulating-ras ... -easy-way/
http://xecdesign.com/working-with-qemu/
http://www.soslug.org/wiki/raspberry_pi_emulation
http://www.raspberrypi.org/phpBB3/membe ... file&u=356 (ShiftPlusOne)

Steps:

$ mkdir ~/qemu_vms/
Download/copy Raspbian Wheezy to ~/qemu_vms/
Download kernel-qemu to ~/qemu_vms/
$ sudo apt-get install qemu-system
$ file ~/qemu_vms/2013-02-09-wheezy-raspbian.img
From the output of the file command, take the partition 2 'startsector' value an multiply by 512, and use this figure as the offset value in the mount command below.
$ sudo mount ~/qemu_vms/2013-02-09-wheezy-raspbian.img -o offset=62914560 /mnt
$ sudo nano /mnt/etc/ld.so.preload
Comment out the line in the file (use a # as the first character of the line) and save the file (CTRL+X, then "Y" for yes).
$ sudo umount ~/qemu_vms/2013-02-09-wheezy-raspbian.img /mnt
$ cd ~/qemu_vms/
$ qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1" -hda ~/qemu_vms/2013-02-09-wheezy-raspbian.img -redir tcp:5022::22
Qemu gives you a root shell, run:
$ fsck /dev/sda2
$ shutdown -r now
Login as pi
Password raspberry

Done.