dhruvvyas90
Posts: 25
Joined: Thu Nov 21, 2013 2:36 pm

Emulating raspbian with QEMU

Wed Jun 03, 2015 5:02 am

Hello,

I'm trying to emulate raspbian on QEMU and there're plenty of guides available on internet. However, every guide points to download qemu-linux kernel from link https://xecdesign.com/downloads/linux-qemu/kernel-qemu however, this link is dead and I was unable to find an alternative link. Is there any alternative link to the kernel or guide how to compile kernel from source ?

Thanks.

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

Re: Emulating raspbian with QEMU

Wed Jun 03, 2015 2:26 pm

I plan to bring the site back up over the weekend.

dhruvvyas90
Posts: 25
Joined: Thu Nov 21, 2013 2:36 pm

Re: Emulating raspbian with QEMU

Sun Jun 07, 2015 5:50 am

ShiftPlusOne wrote:I plan to bring the site back up over the weekend.
Thanks a lot. I really appreciate it. However, out of curiosity, if someone were to compile his own kernel for rpi for qemu, is there any technical difference ? In other words, can I just take a working pi and use its kernel zImage to emulate rpi in qemu ? It might sound silly but I'm just kicking off with rpi and linux in general.

Thanks in advance. :)

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

Re: Emulating raspbian with QEMU

Sun Jun 07, 2015 6:39 am

Sorry, didn't get around to it.
dhruvvyas90 wrote:However, out of curiosity, if someone were to compile his own kernel for rpi for qemu, is there any technical difference ? In other words, can I just take a working pi and use its kernel zImage to emulate rpi in qemu ? It might sound silly but I'm just kicking off with rpi and linux in general.
One of the tutorials I had was how to compile such a kernel, it should be cached somewhere. You can't just take the normal pi kernel, because it doesn't support the hardware emulated by qemu.

If you look around, you should be able to find plenty of kernels which will work under qemu. For example, google spits this page out https://people.debian.org/~aurel32/qemu/armhf/ , but I haven't tried it.


dhruvvyas90
Posts: 25
Joined: Thu Nov 21, 2013 2:36 pm

Re: Emulating raspbian with QEMU

Mon Jun 08, 2015 7:14 am

Meanwhile, I have made it available on this link. https://github.com/dhruvvyas90/qemu-rpi-kernel Hope it helps someone who stumbles across this thread. (Thanks to the Sandor Megyari for his answer [and link :) ] on http://raspberrypi.stackexchange.com/qu ... -with-qemu)

jjletho67
Posts: 1
Joined: Tue May 19, 2015 6:59 am

Re: Emulating raspbian with QEMU

Tue Jun 16, 2015 5:45 pm

Thank you very much!!!
I was going crazy in finding the right kernel image. Your image is working fine!
I followed this guide:
http://www.linux-mitterteich.de/fileadm ... p_2013.pdf
(but there are a lot of usefull guides on this theme)

I think it would be very usefull to have a sticky thread with an "official" guide to running raspbian inside qemu.

polaco1782
Posts: 4
Joined: Mon Oct 12, 2015 7:06 pm

Re: Emulating raspbian with QEMU

Wed Oct 21, 2015 12:00 pm

I have built a custom qemu kernel for raspbian Jessie. You can get a sources and a precompiled version on my github page:

https://github.com/polaco1782/raspberry-qemu

Thanks

User avatar
DougieLawson
Posts: 36528
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Emulating raspbian with QEMU

Wed Oct 21, 2015 6:30 pm

polaco1782 wrote:I have built a custom qemu kernel for raspbian Jessie. You can get a sources and a precompiled version on my github page:

https://github.com/polaco1782/raspberry-qemu

Thanks
Is there any way to get Qemu running with more than 256MB of RAM or multiple cores?
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

polaco1782
Posts: 4
Joined: Mon Oct 12, 2015 7:06 pm

Re: Emulating raspbian with QEMU

Wed Oct 21, 2015 10:25 pm

DougieLawson wrote:
polaco1782 wrote:I have built a custom qemu kernel for raspbian Jessie. You can get a sources and a precompiled version on my github page:

https://github.com/polaco1782/raspberry-qemu

Thanks
Is there any way to get Qemu running with more than 256MB of RAM or multiple cores?
Not really sure about, but its hardcoded 256 on versatilepb kernel source file. Also not sure if just increasing it would work, because of memory mappings.

Thanks

dhruvvyas90
Posts: 25
Joined: Thu Nov 21, 2013 2:36 pm

Re: Emulating raspbian with QEMU

Tue Nov 17, 2015 11:43 am

DougieLawson wrote:
polaco1782 wrote:I have built a custom qemu kernel for raspbian Jessie. You can get a sources and a precompiled version on my github page:

https://github.com/polaco1782/raspberry-qemu

Thanks
Is there any way to get Qemu running with more than 256MB of RAM or multiple cores?
I heard that torlus' qemu allows you to emulate original rpi kernel (without versatilepb patch and separate compilation) and without RAM limited to 256 MB. I've not tested it myself but it sounds promising. Here is the link : https://github.com/Torlus/qemu/tree/rpi

dhruvvyas90
Posts: 25
Joined: Thu Nov 21, 2013 2:36 pm

Re: Emulating raspbian with QEMU

Tue Nov 17, 2015 11:47 am

polaco1782 wrote:I have built a custom qemu kernel for raspbian Jessie. You can get a sources and a precompiled version on my github page:

https://github.com/polaco1782/raspberry-qemu

Thanks
@polaco1782: I tried to emulate but it enters into emergency mode giving me `[email protected]` prompt every time I try to boot.

I've made changes as you suggested on your readme file, ie, commented lines in `/etc/ld.so.preload`, changed `mmcblk0p` to `sda` in /etc/fstab`. Can you describe step by step what you did to make it work right ? It could be useful to other users as well.

Thanks.

Attached is the snapshot : (link: http://i.imgur.com/va8l51Z.png)

Image

Update :

I was able to make it work by, commenting all the mmcblk entries in `/etc/fstab`. I was doing it wrong.

It works perfectly fine. :)

In order to make fresh jessie image to work, this needs to be done.

1. Mount .img file.
2. Comment any lines present in `/etc/ld.so.preload`. Save file.
3. Comment mmcblk entries from `/etc/fstab`. Save file.
4. Unmount.
5. Use that image to emulate qemu by `qemu-system-arm -kernel kernel-name -cpu arm1176 -m 256 -M versatilepb -serial stdio -append "root=/dev/sda2 rootfstype=ext4" -hda image-file-name.img`

vortexvortex
Posts: 2
Joined: Sun Nov 22, 2015 7:56 pm

Re: Emulating raspbian with QEMU

Sun Nov 22, 2015 8:11 pm

@dhruvvyas90

Hi. Watching this thread, I've been getting the same result as yourself. su - pi and startx seems to work relatively well from that point, but I still don't seem to get a clean boot ...

Mounting the image and checking issues:

Code: Select all

mount -t auto -o loop,offset=$((122880*512)) 2015-09-24-raspbian-jessie.img /mnt/rpi

cat /mnt/rpi/etc/ld.so.preload 
#/usr/lib/arm-linux-gnueabihf/libarmmem.so

# cat /mnt/rpi/etc/fstab 
proc            /proc           proc    defaults          0       0
#/dev/mmcblk0p1  /boot           vfat    defaults          0       2
#/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
/dev/sda1  /boot           vfat    defaults          0       2
/dev/sda2  /               ext4    defaults,noatime  0       1

I also got warnings from my distro version of qemu (Fedora 22) stating I should explicitly configure raw format for the img file mount. I've tried qemu invocation as you have suggested, as well as

Code: Select all

qemu-system-arm -kernel kernel-qemu-4.1.7-jessie -cpu arm1176 -m 256 -M versatilepb -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw" -drive format=raw,file=2015-09-24-raspbian-jessie.img
I've also tried both your github kernel image as well as @polaco1782's, with the same result.

Any pointers/tips appreciated.

dhruvvyas90
Posts: 25
Joined: Thu Nov 21, 2013 2:36 pm

Re: Emulating raspbian with QEMU

Mon Nov 23, 2015 6:22 am

vortexvortex wrote:@dhruvvyas90

Hi. Watching this thread, I've been getting the same result as yourself. su - pi and startx seems to work relatively well from that point, but I still don't seem to get a clean boot ...

Mounting the image and checking issues:

Code: Select all

mount -t auto -o loop,offset=$((122880*512)) 2015-09-24-raspbian-jessie.img /mnt/rpi

cat /mnt/rpi/etc/ld.so.preload 
#/usr/lib/arm-linux-gnueabihf/libarmmem.so

# cat /mnt/rpi/etc/fstab 
proc            /proc           proc    defaults          0       0
#/dev/mmcblk0p1  /boot           vfat    defaults          0       2
#/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
/dev/sda1  /boot           vfat    defaults          0       2
/dev/sda2  /               ext4    defaults,noatime  0       1

I also got warnings from my distro version of qemu (Fedora 22) stating I should explicitly configure raw format for the img file mount. I've tried qemu invocation as you have suggested, as well as

Code: Select all

qemu-system-arm -kernel kernel-qemu-4.1.7-jessie -cpu arm1176 -m 256 -M versatilepb -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw" -drive format=raw,file=2015-09-24-raspbian-jessie.img
I've also tried both your github kernel image as well as @polaco1782's, with the same result.

Any pointers/tips appreciated.
@vortexvortex

DO NOT ADD `/dev/sda` entries in fstab. Just comment `mmcblk` entries and you're good to go. Ie, your fstab should look like this,

Code: Select all

proc            /proc           proc    defaults          0       0
#/dev/mmcblk0p1  /boot           vfat    defaults          0       2
#/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
It should boot right into desktop without any hassles. Also, ignore that raw image warnings. At first I also thought, that it has something to do with not booting it properly.

You should be able to emulate it with,

Code: Select all

qemu-system-arm -kernel kernel-qemu-4.1.7-jessie -cpu arm1176 -m 256 -M versatilepb -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw" -hda 2015-09-24-raspbian-jessie.img
Hope it helps.

vortexvortex
Posts: 2
Joined: Sun Nov 22, 2015 7:56 pm

Re: Emulating raspbian with QEMU

Mon Nov 23, 2015 1:47 pm

dhruvvyas90 wrote:
vortexvortex wrote:@dhruvvyas90

Hi. Watching this thread, I've been getting the same result as yourself. su - pi and startx seems to work relatively well from that point, but I still don't seem to get a clean boot ...

Mounting the image and checking issues:

Code: Select all

mount -t auto -o loop,offset=$((122880*512)) 2015-09-24-raspbian-jessie.img /mnt/rpi

cat /mnt/rpi/etc/ld.so.preload 
#/usr/lib/arm-linux-gnueabihf/libarmmem.so

# cat /mnt/rpi/etc/fstab 
proc            /proc           proc    defaults          0       0
#/dev/mmcblk0p1  /boot           vfat    defaults          0       2
#/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
/dev/sda1  /boot           vfat    defaults          0       2
/dev/sda2  /               ext4    defaults,noatime  0       1

I also got warnings from my distro version of qemu (Fedora 22) stating I should explicitly configure raw format for the img file mount. I've tried qemu invocation as you have suggested, as well as

Code: Select all

qemu-system-arm -kernel kernel-qemu-4.1.7-jessie -cpu arm1176 -m 256 -M versatilepb -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw" -drive format=raw,file=2015-09-24-raspbian-jessie.img
I've also tried both your github kernel image as well as @polaco1782's, with the same result.

Any pointers/tips appreciated.
@vortexvortex

DO NOT ADD `/dev/sda` entries in fstab. Just comment `mmcblk` entries and you're good to go. Ie, your fstab should look like this,

Code: Select all

proc            /proc           proc    defaults          0       0
#/dev/mmcblk0p1  /boot           vfat    defaults          0       2
#/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
It should boot right into desktop without any hassles. Also, ignore that raw image warnings. At first I also thought, that it has something to do with not booting it properly.

You should be able to emulate it with,

Code: Select all

qemu-system-arm -kernel kernel-qemu-4.1.7-jessie -cpu arm1176 -m 256 -M versatilepb -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw" -hda 2015-09-24-raspbian-jessie.img
Hope it helps.
:D Thanks! Works like a charm. Now to see how far I can push with getting 1Mb memory working & maybe KVM/libvirt ... :twisted:

User avatar
trojanspike
Posts: 3
Joined: Mon Oct 19, 2015 8:41 am

Re: Emulating raspbian with QEMU

Mon Nov 23, 2015 4:16 pm

I created a qemu cli to help me created minibian images ::

https://github.com/trojanspike/qbian
Support me in No-Shave November :: https://www.no-shave.org/member/trojanspike

leighma
Posts: 1
Joined: Wed Dec 09, 2015 12:44 pm

Re: Emulating raspbian with QEMU

Wed Dec 09, 2015 12:49 pm

polaco1782 wrote:I have built a custom qemu kernel for raspbian Jessie. You can get a sources and a precompiled version on my github page:

https://github.com/polaco1782/raspberry-qemu

Thanks
sorry to interrupt . i am following your github. to clone the git and checkout , but seems check out failed.
fatal check out failed and need to run " git checkout -f HEAD"

i am not even programmer, i am a hardware guy. so still trying to get the Raspberry Pi jessie qemu working.
could you please be more specific ?

Many thanks in advanced!

leigh

cil8
Posts: 179
Joined: Tue Feb 14, 2012 10:47 am

Re: Emulating raspbian with QEMU

Sat Mar 12, 2016 2:32 pm

I followed all your instructions and tried all your kernels, but I invariably get a kernel panic as in the screenshot attached.

I'm running Ubuntu 15.04 and qemu 2.2.0.

Any hints?

Thanks!
Attachments
qemu_raspbian_kernel_panic.png
qemu_raspbian_kernel_panic.png (27.37 KiB) Viewed 19517 times

User avatar
furansa
Posts: 6
Joined: Thu Nov 05, 2015 6:28 pm
Location: Rio de Janeiro
Contact: Website

Re: Emulating raspbian with QEMU

Wed Apr 06, 2016 12:42 pm

Hi everyone.

Some of you already tried to run Raspberry Pi with QEmu using the virt manager interface (www.virt-manager.org)?

I've search on the Internet but just found old information.

My virt-manager (running on Debian 8) have the arm option with some boards like cubieboard but no RPi board.

I'll appreciate with someone could share some experience.

Thanks in advance, best regards.
--
Fernando França
http://desconstruindo.eng.br

Linux user #263682

User avatar
mc007ibi
Posts: 66
Joined: Wed Dec 16, 2015 7:36 pm
Location: barcelona

Re: Emulating raspbian with QEMU

Tue Sep 20, 2016 5:14 pm

someone has a more updated article? I tried now 4-5 articles from the internet but they all fail.

Return to “Beginners”