lknox
Posts: 3
Joined: Sun May 26, 2013 5:36 pm

Can QEMU boot from my RPi SD Card?

Sun May 26, 2013 6:34 pm

I'm trying to get a Pi set up for general software/hardware development (a certain web server, dev environment, etc - lots of fiddly bits) and I'd really love to be pop out my SD Card from the Pi, pop it into my Windows OS laptop and QEMU-boot into the SD Card - but I'm running into problems. Is this even possible to do?

In my Qemu-windows-1.3.1 folder in Windows I have my "kernel-qemu" file and my "2012-08-08-wheezy-armel.img" file (I need the Soft Float version because I'm using Mono). Using this batch file I can get Rasbian to boot up great in QEMU from the img file:

Code: Select all

qemu-system-armw.exe -M versatilepb -cpu arm1176 -hda 2012-08-08-wheezy-armel.img -kernel kernel-qemu -m 256 -append "root=/dev/sda2"
So, next I use my "win32diskimager-v0.7" tool to write the "2012-08-08-wheezy-armel.img" file to my SD Card and I can boot the RPi just fine from this SD Card. But now if I want to turn off the RPi, remove the SD Card and put it back into my computer... how can I boot from this SD Card with QEMU?

I'm trying this (in Windows my G: drive is the SD Card):

Code: Select all

qemu-system-armw.exe -M versatilepb -cpu arm1176 -kernel kernel-qemu -m 256 -hda g:\kernel.img -append "root=/dev/sda"
...and getting complaints about a bad root= parameter value. I've been googling for a solution for almost a day and I'm thinking I don't know the right terms to search on. I'm not (totally) new to linux, but I'm very new to QEMU, RaspberryPI and ARM processors. Any assistance or direction you have for this head scratching monkey I would sincerely appreciate!

Thanks,

L

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

Re: Can QEMU boot from my RPi SD Card?

Sun May 26, 2013 7:54 pm

You can read the sdcard into an image and boot that like you would boot plain 2012-08-08-wheezy-armel.img. Instead of using the 'write' button on win32diskimage, use 'read'. Then use the new image like you used the old one.

I'll tell you what you're doing wrong though. The -hda parameter passes a disk image to use as a drive. This works fine for 2012-08-08-wheezy-armel.img, but in the second example you're using kernel.img. kernel.img is not a disk image, it's the kernel; you cannot boot from it.

You can try using the sdcard and a physical drive, but I don't think it will work on windows. http://wiki.qemu.org/download/qemu-doc. ... 005fdrives

DirkS
Posts: 10416
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Can QEMU boot from my RPi SD Card?

Sun May 26, 2013 7:57 pm

...and getting complaints about a bad root= parameter value
Understandable. You use /dev/sda for the root parameter. There should always be a number indicating the partition number (so that's sda1, sda2, etc). See also the first qemu command line in your post.

Gr.
Dirk.

lknox
Posts: 3
Joined: Sun May 26, 2013 5:36 pm

Re: Can QEMU boot from my RPi SD Card?

Sun May 26, 2013 8:16 pm

Thank you for you information! Ok, so I again went to http://wiki.qemu.org/download/qemu-doc. ... 005fdrives (I've been there a lot lately) and re-read it again and I thought this should work. This is because the interface defined below is supposed to be interpreted as -hda per the wiki:

Code: Select all

qemu-system-armw.exe -M versatilepb -cpu arm1176 -kernel kernel-qemu -m 256 -drive if=sd,index=0,media=disk -append "root=/dev/hda0"
But I get this panic error:

Code: Select all

Cannot open root device "hda0" or unknown-block(0,0): error 6
Please append a correct "root=" boot option; here are the available partitions:
0b00 1048575 sr0 driver: sr
1f00 65536 mtdblock0 (driver?)
Kernel panic - not synching: VFS: Unable to mount root fs on unknown-block(0,0)
I've tried using /dev/sr and /dev/sr0 and /dev/hda0 and /dev/hda1 for root= parameter values but no go. Any ideas?

I apologize for my ignorance, I'm still learning about linux file systems / organization.

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

Re: Can QEMU boot from my RPi SD Card?

Sun May 26, 2013 8:36 pm

Can you explain what you're trying to do with this and why?

Code: Select all

-drive if=sd,index=0,media=disk
Edit: Which part of that do you think tells qemu to use the sdcard or the sdcard image as the drive?

lknox
Posts: 3
Joined: Sun May 26, 2013 5:36 pm

Re: Can QEMU boot from my RPi SD Card?

Sun May 26, 2013 8:59 pm

Can you explain what you're trying to do with this and why?
Sure!
I'm trying to get a Pi set up for general software/hardware development (a certain web server, dev environment, etc - lots of fiddly bits) and I'd really love to be pop out my SD Card from the Pi, pop it into my Windows OS laptop and QEMU-boot into the SD Card - but I'm running into problems. Is this even possible to do?
Edit: Which part of that do you think tells qemu to use the sdcard or the sdcard image as the drive?
For this command: -drive if=sd,index=0,media=disk
http://wiki.qemu.org/download/qemu-doc.html wrote:‘if=interface’
This option defines on which type on interface the drive is connected. Available types are: ide, scsi, sd, mtd, floppy, pflash, virtio.
So I think the "if=sd" part might mean use an SD card interface, but the documentation is lacking. That's why I'm seeking assistance.

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

Re: Can QEMU boot from my RPi SD Card?

Sun May 26, 2013 9:30 pm

That's not what I meant, but that's alright, I was being too vague. QEMU has a lot of limitations, the windows adds on its own set of limitations, which make it difficult to accomplish what you're trying to do directly.

I am not 100% sure, but I think in that case, sd means SATA disk, but even if it was SD card, it would not make a difference, since you don't specify any file, you're not attaching anything at all. That parameter does not make sense on its own.

I am currently unable to look further into alternative methods, since I don't have much free time, but reading the sdcard back into an image is the simplest way to get this to work.

MoJo1760
Posts: 1
Joined: Fri Aug 02, 2013 9:39 pm

Re: Can QEMU boot from my RPi SD Card?

Fri Aug 02, 2013 9:47 pm

I believe that this is possible - (I'm writing my image out to SD card now and will know for sure shortly) ...

This is from the QEMU docs
[Physical] Hard disks can be used with the syntax: ‘\\.\PhysicalDriveN’ where N is the drive number (0 is the first hard disk).
So the trick is to know for sure what drive number your SD card is mounted on...from an elevated command line:

Code: Select all

diskpart
list disk
It should look something like this:

Code: Select all

Microsoft DiskPart version 6.1.7601
Copyright (C) 1999-2008 Microsoft Corporation.
On computer: <computername>

DISKPART> list disk

  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
  Disk 0    Online          931 GB      0 B
  Disk 1    Online         3780 MB  1933 MB
  Disk 2    No Media           0 B      0 B
  Disk 3    No Media           0 B      0 B
  Disk 4    No Media           0 B      0 B

DISKPART>
In this case the SD card is PhysicalDisk1 so I will reference it in the command line thus :

Code: Select all

qemu-system-armw.exe -M versatilepb -cpu arm1176 -hda \\.\PhysicalDisk1 -kernel kernel-qemu -m 512 -append "root=/dev/sda2" -net nic -net tap,ifname=Tap32

mnunesvsc
Posts: 2
Joined: Tue Aug 19, 2014 4:16 pm

Re: Can QEMU boot from my RPi SD Card?

Wed Dec 03, 2014 5:56 pm

It Worked ?, very interested.

dogcatfee
Posts: 1
Joined: Mon Aug 22, 2016 9:34 pm

Re: Can QEMU boot from my RPi SD Card?

Mon Aug 22, 2016 9:36 pm

As reference - For those of us running windows 10 replace PhysicalDisk# with PhysicalDrive#

nargetdev
Posts: 1
Joined: Fri Oct 21, 2016 3:57 am

Re: Can QEMU boot from my RPi SD Card?

Fri Oct 21, 2016 4:21 am

[SOLVED]

Believe it or not I actually got this working on mac OS X and also Ubuntu booting directly from SD card.. Almost an entire day of head banging to show for it

Here be ext4 filesystem dragons...
If on Jessie make changes to following files on the guest file system according to the following link.
1) /etc/ld.so.preload
2) /etc/fstab
https://github.com/dhruvvyas90/qemu-rpi ... .xx-kernel

Ultimately I made these changes using Ubuntu 16.04 virtual machine by mounting the SD card which automagically enumerated as 2 partitions, boot and the other one (linux). I went in and made the changes directly. In most cases you'll have to jump through some hoops to get at that ext4 filesystem.. If you don't have a VM at your disposal OSXFUSE project is also an option (https://osxfuse.github.io/)

Determine the disk number of your SD via a quick

Code: Select all

diskutil list
Then you will have to unmount the disk..

Code: Select all

diskutil unmountDisk /dev/disk[b]your disk number from last step[/b]
Then all you need to do is run the following command:

Code: Select all

sudo qemu-system-arm -kernel kernel-qemu-4.4.13-jessie -cpu arm1176 -m 256 -M versatilepb -serial stdio -append "root=/dev/sda2 rootfstype=ext4 rw" -hda /dev/rdisk[b]yourdisknumberhere[/b] -net nic -net user,hostfwd=tcp::2222-:22,hostfwd=tcp::22280-:80
If you'd like to ssh from host to guest do so as follows:

Code: Select all

ssh pi@localhost -p2222
If you're on linux the command is very similar.. just swap out the "/dev/path" as such...

Code: Select all

sudo qemu-system-arm -kernel kernel-qemu-4.4.13-jessie -cpu arm1176 -m 256 -M versatilepb -serial stdio -append "root=/dev/sda2 rootfstype=ext4 rw" -hda /dev/sd[b]yourdiskletter[/b] -net nic -net user,hostfwd=tcp::2222-:22,hostfwd=tcp::22280-:80
Enjoi the sweet sweet taste of virtual raspberry pi...

amilino
Posts: 98
Joined: Fri Feb 05, 2016 6:01 pm

Re: Can QEMU boot from my RPi SD Card?

Sun Dec 11, 2016 1:09 pm

How to make it working with img file created with win32diskimager from SD Card on Windows environment. Image is made on latest Jessie.

Also as I can see with default 2012-07-15-wheezy-raspbian.img image, audio doesn't work and resolution is very small.

francegue
Posts: 9
Joined: Tue Sep 27, 2016 10:33 am

Re: Can QEMU boot from my RPi SD Card?

Wed Mar 15, 2017 11:47 am

nargetdev wrote: If you'd like to ssh from host to guest do so as follows:

Code: Select all

ssh pi@localhost -p2222
Hi all,
I did everything explained in this super useful post, but I am not able to connect via ssh to my emulated raspberry.
I guess it is because the ssh is not enabled, but if I launch raspi-config it says me that the tool cannot be run because the configuration is not the default one (I guess because I changed manually the 2 files 1) /etc/ld.so.preload and 2) /etc/fstab).
Do you know how can I fix it?
Thanks!

Return to “Beginners”