ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6085
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: HOWTO: Virtual Raspbian on Qemu in Ubuntu Linux 12.10

Fri Nov 08, 2013 6:00 pm

You mounted the first partition, rather than the second.

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6085
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: HOWTO: Virtual Raspbian on Qemu in Ubuntu Linux 12.10

Sat Nov 09, 2013 4:31 am

Sorry, I was using the phone earlier and I hate typing on the virtual keyboard, so that may have not been a helpful reply. When you run 'file' you should see 'start sector' twice. The first one is for the first partition, the second is for the second. So, follow the steps again, but use the righ startsector.

jaytirth
Posts: 1
Joined: Sat Nov 23, 2013 5:19 pm

Re: HOWTO: Virtual Raspbian on Qemu in Ubuntu Linux 12.10

Sun Dec 29, 2013 3:29 pm

I created a virtual Raspbian environment on Qemu as given here

But I am unable to connect to the Internet from the Raspbian although I am connected on the host machine ( Ubuntu 12.04 )
The host machine is connected to the Internet via a 3G Dongle.

demonx
Posts: 2
Joined: Sun Aug 04, 2013 4:29 pm

Re: HOWTO: Virtual Raspbian on Qemu in Ubuntu Linux 12.10

Wed Jan 01, 2014 12:07 pm

tonyhughes wrote:Task:

Virtualise Raspbian Wheezy 2013-02-09 on Ubuntu Linux 12.10

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.

Thanks so much to user/moderator 'ShiftPlusOne' for devoting some time on IRC to helping me get this going.

NOTE: The command list above is pretty terse, and without comment/explanation per command. It is all self explanatory for people vaguely familiar with the command line, and I wanted to keep that section brief, so it looks less scary for newbies (a short set of clear commands!). If anyone needs an explanation of any of this, ask away... :)

Nod
Posts: 3
Joined: Thu Oct 31, 2013 3:13 pm

Re: HOWTO: Virtual Raspbian on Qemu in Ubuntu Linux 12.10

Tue Jan 14, 2014 4:55 pm

ShiftPlusOne wrote:Sorry, I was using the phone earlier and I hate typing on the virtual keyboard, so that may have not been a helpful reply. When you run 'file' you should see 'start sector' twice. The first one is for the first partition, the second is for the second. So, follow the steps again, but use the righ startsector.

I've succeeded in emulating, but faced issues with my laptop keyboard. Now, few months later I've bought a real raspberry pi.

Thank you for all the responses! :D

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6085
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: HOWTO: Virtual Raspbian on Qemu in Ubuntu Linux 12.10

Tue Jan 14, 2014 5:14 pm

You're welcome, kind sir.

rpiforfun
Posts: 28
Joined: Wed Jan 15, 2014 11:25 pm

Re: HOWTO: Virtual Raspbian on Qemu in Ubuntu Linux 12.10

Mon Jan 20, 2014 7:12 pm

Thanks for this ! great way to try out the OS and plans before you get a RPi. Qemu is fairly fast on my new system.

Need help!

I followed this process and got Qemu working, but my mouse does NOT work.

UPDATE: Oh drat - I didn't follow the process exactly. :( I'm running the latest image for RPi, and using the qemu-system-arm package in Ubuntu 13.10. Any reason to think mouse support was busted somewhere here?

I can activate the buttons, but not move the cursor. Seems like a driver issue? Mouse works without any special in Ubuntu.

Its a standard usb logitech mouse. The keyboard works, but I want to move around the gui. Running Ubuntu 13.10 here. I already tried -show-cursor and it made no difference.
Last edited by rpiforfun on Mon Jan 20, 2014 7:21 pm, edited 1 time in total.

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6085
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: HOWTO: Virtual Raspbian on Qemu in Ubuntu Linux 12.10

Mon Jan 20, 2014 7:18 pm

rpiforfun wrote:Thanks for this ! great way to try out the OS and plans before you get a RPi. Qemu is fairly fast on my new system.

Need help!

I followed this process and got Qemu working, but my mouse does NOT work.

I can activate the buttons, but not move the cursor. Seems like a driver issue? Mouse works without any special in Ubuntu.

Its a standard usb logitech mouse. The keyboard works, but I want to move around the gui. Running Ubuntu 13.10 here. I already tried -show-cursor and it made no difference.
I'd bet it's a qemu issue rather than anything to do with drivers. You're not running qemu inside a VM? Do you have the 'grab mouse' option enabled in qemu?

EDIT: While in qemu, try pressing ctrl+alt+g

rpiforfun
Posts: 28
Joined: Wed Jan 15, 2014 11:25 pm

Re: HOWTO: Virtual Raspbian on Qemu in Ubuntu Linux 12.10

Mon Jan 20, 2014 7:23 pm

ShiftPlusOne wrote: I'd bet it's a qemu issue rather than anything to do with drivers. You're not running qemu inside a VM? Do you have the 'grab mouse' option enabled in qemu?

EDIT: While in qemu, try pressing ctrl+alt+g
Woohoo! You sir solved my boboism! Is that normal mouse behavior? I'll lookup the grab mouse option.

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6085
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: HOWTO: Virtual Raspbian on Qemu in Ubuntu Linux 12.10

Mon Jan 20, 2014 7:26 pm

Yeah, it's normal. I remember qemu grabbing the mouse automatically when you clicked the window, but that seems to have changed.

rpiforfun
Posts: 28
Joined: Wed Jan 15, 2014 11:25 pm

Re: HOWTO: Virtual Raspbian on Qemu in Ubuntu Linux 12.10

Mon Jan 20, 2014 7:45 pm

ShiftPlusOne wrote:Yeah, it's normal. I remember qemu grabbing the mouse automatically when you clicked the window, but that seems to have changed.
Duh! I just realized there is a options menu for Qemu, and in there - "Grab on hover". It does not seem to work...

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6085
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: HOWTO: Virtual Raspbian on Qemu in Ubuntu Linux 12.10

Mon Jan 20, 2014 7:55 pm

Don't select grab on hover. there should be just 'grab input' next to it.

rpiforfun
Posts: 28
Joined: Wed Jan 15, 2014 11:25 pm

Re: HOWTO: Virtual Raspbian on Qemu in Ubuntu Linux 12.10

Mon Jan 20, 2014 10:39 pm

lol, sorry for the runaround. Yes I understand that the "grab input" option activates the mouse inside the Raspbian session. It works as needed to grab and ungrab input. Thanks for that!

I was hoping to find a feature like VMWare where the real mouse's presence over the window caused it to be grabbed, but alas it does not seem so.

I am having loads of mouse "sync" issues it seems. The displayed mouse seems to drift from my actual mouse cursor and if my mouse hits the side of my screen (logically) it is also unable to move in the VM... this is kinda of odd and it is making mouse movement quite annoying. All of the sudden the mouse can't move to the right past a certain randomly chosen vertical line. But if I move the mouse really far in the opposite direction and back, it will let me. Clearly there is a mouse coordinate math issue IMO.

Is this mouse sync issue common also?

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6085
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: HOWTO: Virtual Raspbian on Qemu in Ubuntu Linux 12.10

Mon Jan 20, 2014 10:47 pm

Ah, fair enough.

Qemu is a little rough around the edges. It's fine for testing things out, but it it a pain to do much else with. If I have to use it for longer periods of time, I use ssh and vnc instead of what it provides. I never managed to get incoming connections working, so I use SSH to forward the relevant ports first.

ionutg13
Posts: 1
Joined: Fri Feb 07, 2014 9:33 am

Re: HOWTO: Virtual Raspbian on Qemu in Ubuntu Linux 12.10

Fri Feb 07, 2014 9:39 am

Hi,

I have followed your Howto, but it didn't work:
xxxxxxxxxxxx:~/qemu_vms# mount ~/qemu_vms/2014-01-07-wheezy-raspbian.img -o offset=62914560 /mnt/qemu
xxxxxxxxxxxx:~/qemu_vms# cd /mnt/
image/ qemu/
xxxxxxxxxxxx:~/qemu_vms# cd /mnt/qemu/
bin/ home/ mnt/ run/ sys/
boot/ lib/ opt/ sbin/ tmp/
dev/ lost+found/ proc/ selinux/ usr/
etc/ media/ root/ srv/ var/
xxxxxxxxxxxx:~/qemu_vms# cd /mnt/qemu/
xxxxxxxxxxxx:/mnt/qemu# find . -name ld.so.preload
./etc/ld.so.preload
xxxxxxxxxxxx:/mnt/qemu# vi /mnt/qemu/etc/ld.so.conf
xxxxxxxxxxxx:~# umount /mnt/qemu
xxxxxxxxxxxx:~# cd qemu_vms/
xxxxxxxxxxxx:~/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/2014-01-07-wheezy-raspbian.img -redir tcp:5022::22
Uncompressing Linux... done, booting the kernel.

Any ideas? QEMU window screenshots attached.

thanks,
IG

herrmeier
Posts: 7
Joined: Sat Jan 26, 2013 12:53 pm

Re: HOWTO: Virtual Raspbian on Qemu in Ubuntu Linux 12.10

Thu Mar 13, 2014 1:44 pm

Great Howto tonyhughes!!!, worked for me just fine with slight changes with ubuntu-server 32bit - 13.10 with lubuntu-desktop, qemu with 2014-01-07-wheezy-raspbian.img in a virtualbox. At first I calculated the offset for the first partition as well, perhaps you can highlight or set that part of the text in bold letters.

I backuped the vdi-file, 15GB and can now change and test before going "productive" on my pi.
But some things bother me...And I was wondering if I am the only one...

1. I cannot copy and paste from the qemu-host to raspberry pi

2. My IP-Adress is of the emulated pi is 10.0.2.15...the virtualized ubuntu-host has 192.168.1.48.
As far as I have read, I would need to configure a bridge in the qemu host.
Has anyone figured out how that is possible?https://wiki.debian.org/QEMU

3. I cannot connect via ssh to 10.0.2.15, even not with -p5022, I can't even ping that adress..

Thank you already

Cheers Hans

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6085
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: HOWTO: Virtual Raspbian on Qemu in Ubuntu Linux 12.10

Thu Mar 13, 2014 2:20 pm

Hello Hans,

Check out this comment http://xecdesign.com/qemu-emulating-ras ... ment-43324

If all you need is ssh, then you can redirect ports using -redir tcp:2222::22. This will allow you to ssh to localhost:2222 in order to connect to qemu guest's port 22.

However, sharing the clipboard does not seem to be a current feature of qemu (although I found some work being done on it). For now, it might be sensible to use SSH and VNC to get around that. VNC is also nice since it lets you get around the low resolution.

giaur500
Posts: 36
Joined: Sat Sep 08, 2012 11:07 pm

Re: HOWTO: Virtual Raspbian on Qemu in Ubuntu Linux 12.10

Sun Apr 27, 2014 1:35 pm

Can I set higher cpu speed in config.txt when use qemu? Theoretically, I can set much larger freq values than on real pi and it should work? Or not?

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6085
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: HOWTO: Virtual Raspbian on Qemu in Ubuntu Linux 12.10

Sun Apr 27, 2014 1:50 pm

giaur500 wrote:Can I set higher cpu speed in config.txt when use qemu? Theoretically, I can set much larger freq values than on real pi and it should work? Or not?
Nope, config.txt has no effect in qemu and clock speeds don't mean much there anyway. It already works as fast as your computer allows (which is usually only a little faster than an actual pi).

giaur500
Posts: 36
Joined: Sat Sep 08, 2012 11:07 pm

Re: HOWTO: Virtual Raspbian on Qemu in Ubuntu Linux 12.10

Sun Apr 27, 2014 1:54 pm

Is there really no way to run it faster?

dipesh_panchal
Posts: 1
Joined: Mon Jul 14, 2014 6:24 am

Re: HOWTO: Virtual Raspbian on Qemu in Ubuntu Linux 12.10

Mon Jul 14, 2014 6:28 am

when i type in command : file 2014-06-20-wheezy-raspbian.img
it gives output like this : 2014-06-20-wheezy-raspbian.img: x86 boot sector

it does not show partition information or startsector info for multipication

tuxpm
Posts: 2
Joined: Sun Jul 20, 2014 3:59 am

Re: HOWTO: Virtual Raspbian on Qemu in Ubuntu Linux 12.10

Sun Jul 20, 2014 4:19 am

fdisk -l 2014-06-20-wheezy-raspbian.img

ColonelPhantom
Posts: 1
Joined: Tue Sep 30, 2014 2:53 pm

Re: HOWTO: Virtual Raspbian on Qemu in Ubuntu Linux 12.10

Tue Sep 30, 2014 2:59 pm

dipesh_panchal wrote:when i type in command : file 2014-06-20-wheezy-raspbian.img
it gives output like this : 2014-06-20-wheezy-raspbian.img: x86 boot sector

it does not show partition information or startsector info for multipication
You can solve this by typing in the command: file -k 2014-06-20-wheezy-raspbian.img ;)

dhsc19
Posts: 2
Joined: Mon Jan 12, 2015 1:00 am

Re: HOWTO: Virtual Raspbian on Qemu in Ubuntu Linux 12.10

Mon Jan 12, 2015 1:05 am

I'm able to boot my image, but when I try to log in it is as if there is no shell. I get the welcome message, but no command prompt. Just automatically brings me back to the login prompt. Anyone have a suggestions for this? Thanks!

cmickc
Posts: 3
Joined: Thu May 29, 2014 11:49 pm

Re: HOWTO: Virtual Raspbian on Qemu in Ubuntu Linux 12.10

Tue Apr 14, 2015 4:52 pm

Hi there,

Sorry for what may be a stupid question, but after i setup Qemu and have an rpi vm running in it, how do i then deploy this built VM onto an SD card to run on an actual rpi?

Return to “Advanced users”