stewey
Posts: 1
Joined: Tue Apr 09, 2013 3:35 am

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

Tue Apr 09, 2013 3:38 am

apologies for the novice question,... will I be able to reboot again to my normal Ubuntu O/S, or do the above instructions fry my existing setup?

TheQuestor
Posts: 80
Joined: Wed Nov 28, 2012 9:15 am

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

Tue Apr 09, 2013 5:36 am

stewey wrote:apologies for the novice question,... will I be able to reboot again to my normal Ubuntu O/S, or do the above instructions fry my existing setup?
No worries, you do not need to reboot at all, you mount it and it is in chroot and you unmount it and you're back to your existing setup.

I run byobu [an enhanced screen] to let me access both.

if [using my scripts above] you run byobu then run the ./mountpi then it stays in the chrooted rpi environment and you can just close your ssh window then connect without byobu and you're in your standard ubuntu and to get back to the chroot just run byobu again

even without you can just run the ./umountpi and you're back in your normal ubuntu :)

I hope that made sense.

eshornock
Posts: 4
Joined: Wed May 15, 2013 9:25 pm

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

Wed May 15, 2013 9:30 pm

I don't have a Pi (yet) but I'm tinkering with Raspbian in qemu.

Linux users that have guestfish can fix up the ld.so.preload file with the following

Code: Select all

#!/usr/bin/guestfish -f
add 2013-02-09-wheezy-raspbian.img 
run
mount /dev/vda2 /
# Torlus qemu users can uncomment the next two lines to fetch the kernel from the sd card image
#mount /dev/vda1 /boot
#download /boot/kernel.img kernel-qemu
download /etc/ld.so.preload tmp-preload
! sed -i 's/^[^#].*/#&/g' tmp-preload
upload tmp-preload /etc/ld.so.preload

eshornock
Posts: 4
Joined: Wed May 15, 2013 9:25 pm

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

Fri May 17, 2013 5:10 pm

Alright, my RPi is on order and should hopefully arrive soon.

Here's an updated script that might be useful for someone else. Requires guestfish.

Basically it
1) Downloads the kernel from http://xecdesign.com/downloads/linux-qemu/kernel-qemu if it's not found.
2) Mounts the disk image using guestfish in order to
2a) Comment out the line in /etc/ld.so.preload
2b) Rewrite /etc/fstab and /usr/bin/raspi-config to use /dev/sda instead of /dev/mmcblk0. (This is to get rid of a warning during boot and to allow the "Expand root partition to fill SD card" to work).
3) Creates a 'start-up script' to run qemu-system-arm with the necessary parameters.

You can make the virtual disk image larger with qemu-img (e.g. qemu-img resize IMAGEFILE +5GB). Example session:

Code: Select all

$ qemu-img info 2013-02-09-wheezy-raspbian.img 
image: 2013-02-09-wheezy-raspbian.img
file format: raw
virtual size: 1.8G (1939865600 bytes)
disk size: 1.8G
$ qemu-img resize 2013-02-09-wheezy-raspbian.img +5G
Image resized.
$ qemu-img info 2013-02-09-wheezy-raspbian.img 
image: 2013-02-09-wheezy-raspbian.img
file format: raw
virtual size: 6.8G (7308574720 bytes)
disk size: 1.8G
After using qemu-img (and the script below), Expand root fs within raspi-config will work within qemu.

And here's the script. Perhaps it'll be useful for someone else.

Code: Select all

#!/bin/sh

if [ $# -ne 1 ]; then
    echo "usage: $0 [raspbian image]"
    exit 1
elif [ ! -f $1 ]; then
    echo "Error: File $1 not found." >&2
    exit 1
fi

DISKIMAGE="$1"

create_start_script() {
    cat > raspbian-start << EOF
#!/bin/sh
qemu-system-arm -cpu arm1176 -M versatilepb -m 256 -hda $DISKIMAGE -append 'root=/dev/sda2 panic=1' -no-reboot -kernel kernel-qemu -redir tcp:2222::22
EOF
    chmod +x raspbian-start
    echo "Raspbian can be booted using ./raspbian-start"
}

guestfish -a $DISKIMAGE << EOF
run
mount /dev/vda2 /
#mount /dev/vda1 /boot
#download /boot/kernel.img kernel-raspberry
download /etc/fstab tmp-fstab
download /usr/bin/raspi-config tmp-raspi-config
#sed -e 's:mmcblk0p2:sda2:g' -e 's:mmcblk0:sda:g'
! sed -i -e 's:mmcblk0p\([0-9]\):sda\1:g' -e 's:mmcblk0:sda:g' tmp-fstab tmp-raspi-config
upload tmp-fstab /etc/fstab
upload tmp-raspi-config /usr/bin/raspi-config
download /etc/ld.so.preload tmp-preload
! sed -i 's/^[^#].*/#&/g' tmp-preload
upload tmp-preload /etc/ld.so.preload
EOF

if [ ! -f  kernel-qemu ]; then
    if wget http://xecdesign.com/downloads/linux-qemu/kernel-qemu ; then : else
        echo "Error downloading qemu kernel" >&2
        exit 1
    fi
fi

if [ -f raspbian-start ]; then
    echo -n "Do you want to overwite 'raspbian-start' (y/n) "
    read answer
    case $answer in
        Y*|y*|T*|t*)
            create_start_script ;;
        *)
            exit 0 ;;
    esac
else
    create_start_script
fi

eshornock
Posts: 4
Joined: Wed May 15, 2013 9:25 pm

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

Fri May 17, 2013 6:16 pm

tulumbas wrote:tonyhughes, what version of qemu is used in your Ubuntu?... because in Debian wheezy qemu is just 0.9 and doesn't know 1176 cpu...
qemu version 0.9? It doesn't look like that was ever in Debian (http://ftp-master.metadata.debian.org/c ... _changelog) and qemu v1.0 was added to Wheezy in January 2012, 1.1.2 (the current version) was added three months before the first post in this thread.

For anyone reading this: The arm1176 cpu type definitely works in the version Wheezy. If you're using Squeeze you can use backports.debian.org to get a suitable qemu...or you can build it from source.

d4n13
Posts: 4
Joined: Mon May 20, 2013 7:36 pm

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

Mon May 20, 2013 8:14 pm

Here's another way to modify the image from Windows

1) Grab the Windows RPi Emulator (http://sourceforge.net/projects/rpiqemuwindows/)
2) Grab latest Wheezy distro (http://www.raspberrypi.org/downloads)
3) Place the IMG grabbed in (2) in the same dir as the IMG from (1)
4) Edit the run.bat file that came with (1)
5) Add the following switch to the QEMU args: -hdb What_ever_that_image_file_is_called.img
6) Execute run.bat and an older RPi Emulator
7) Once the emulator is up, the "New" image is at /dev/sdb
8) Mount /dev/sdb and fix the /etc/ld.so.prefetch file
9) Shutdown and close the QEMU session.
10) Edit run.bat and change the QEMU args to make hda point to the "NEW" image, and just remove hdb

JxPond
Posts: 29
Joined: Wed May 22, 2013 9:32 pm

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

Wed May 22, 2013 10:51 pm

Hi all,

I'm on Ubuntu 12.04 and I followed the steps Tony laid out.

On Raspbian 2013-02-09:
NOTICE: the software on this Raspberry Pi has not been fully configured. Please run 'sudo raspi-config'
Debian GNU/Linux 7.0 (none) ttyAMA0
(none) login:

If I login it just loops several times telling me to "sudo raspi-config" and kicks me back to a login prompt.

Using the Armel (soft-float) 2012-08-08 img:
Debian GNU/Linux wheezy/sid raspberrypi ttyAMA0
raspberrypi login:

Boots fine to the Desktop in a separate window.

Any ideas on what I'm doing incorrectly?

John

eshornock
Posts: 4
Joined: Wed May 15, 2013 9:25 pm

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

Thu May 23, 2013 12:33 am

JxPond wrote:Hi all,

I'm on Ubuntu 12.04 and I followed the steps Tony laid out.

On Raspbian 2013-02-09:
NOTICE: the software on this Raspberry Pi has not been fully configured. Please run 'sudo raspi-config'
Debian GNU/Linux 7.0 (none) ttyAMA0
(none) login:

If I login it just loops several times telling me to "sudo raspi-config" and kicks me back to a login prompt.
[....]
Any ideas on what I'm doing incorrectly?

John
Yes. You didn't comment out the line in /etc/ld.so.preload

$ 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).

JxPond
Posts: 29
Joined: Wed May 22, 2013 9:32 pm

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

Thu May 23, 2013 3:33 am

Thank-you, that did the trick, I must have forgotten to save it the first time around.
# /usr/lib/arm-linux-gnueabihf/libcofi_rpi.so


John

krautbert
Posts: 31
Joined: Sat May 18, 2013 3:55 pm

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

Wed Jul 03, 2013 7:10 am

Hi guys,

i just wanted to build my own Raspi emulator. First, thank you very much for this HowTo. As i wanted to download the Qemu Kernel, i have seen, that the download link is dead. Does anyone know where i also can download it?

Thank you very much and sorry for my bad english.

Krautbert

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6239
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

Wed Jul 03, 2013 7:33 am

krautbert wrote:Hi guys,

i just wanted to build my own Raspi emulator. First, thank you very much for this HowTo. As i wanted to download the Qemu Kernel, i have seen, that the download link is dead. Does anyone know where i also can download it?

Thank you very much and sorry for my bad english.

Krautbert
I have just checked and the download link on http://xecdesign.com/downloads/linux-qemu/kernel-qemu is not dead.

krautbert
Posts: 31
Joined: Sat May 18, 2013 3:55 pm

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

Wed Jul 03, 2013 9:15 am

ShiftPlusOne wrote:
krautbert wrote:Hi guys,

i just wanted to build my own Raspi emulator. First, thank you very much for this HowTo. As i wanted to download the Qemu Kernel, i have seen, that the download link is dead. Does anyone know where i also can download it?

Thank you very much and sorry for my bad english.

Krautbert
I have just checked and the download link on http://xecdesign.com/downloads/linux-qemu/kernel-qemu is not dead.

Well, i have tried it with a wget. Is this kernel 3mb small?! i'm confused!

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6239
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

Wed Jul 03, 2013 4:25 pm

krautbert wrote:
ShiftPlusOne wrote:
krautbert wrote:Hi guys,

i just wanted to build my own Raspi emulator. First, thank you very much for this HowTo. As i wanted to download the Qemu Kernel, i have seen, that the download link is dead. Does anyone know where i also can download it?

Thank you very much and sorry for my bad english.

Krautbert
I have just checked and the download link on http://xecdesign.com/downloads/linux-qemu/kernel-qemu is not dead.

Well, i have tried it with a wget. Is this kernel 3mb small?! i'm confused!
Yup, 3.3MB. What are you confused about?

krautbert
Posts: 31
Joined: Sat May 18, 2013 3:55 pm

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

Thu Jul 04, 2013 5:41 am

ShiftPlusOne wrote:Yup, 3.3MB. What are you confused about?
Because of that

Code: Select all

pulseaudio: set_sink_input_volume() failed
pulseaudio: Reason: Invalid argument
pulseaudio: set_sink_input_mute() failed
pulseaudio: Reason: Invalid argument
qemu: fatal: Trying to execute code outside RAM or ROM at 0xfecef868

R00=00000000 R01=00000183 R02=00000100 R03=00000000
R04=00000000 R05=00000000 R06=00000000 R07=00000000
R08=00000000 R09=00000000 R10=00000000 R11=00000000
R12=00000000 R13=00000000 R14=00010014 R15=fecef868
PSR=400001d3 -Z-- A svc32
s00=00000000 s01=00000000 d00=0000000000000000
s02=00000000 s03=00000000 d01=0000000000000000
s04=00000000 s05=00000000 d02=0000000000000000
s06=00000000 s07=00000000 d03=0000000000000000
s08=00000000 s09=00000000 d04=0000000000000000
s10=00000000 s11=00000000 d05=0000000000000000
s12=00000000 s13=00000000 d06=0000000000000000
s14=00000000 s15=00000000 d07=0000000000000000
s16=00000000 s17=00000000 d08=0000000000000000
s18=00000000 s19=00000000 d09=0000000000000000
s20=00000000 s21=00000000 d10=0000000000000000
s22=00000000 s23=00000000 d11=0000000000000000
s24=00000000 s25=00000000 d12=0000000000000000
s26=00000000 s27=00000000 d13=0000000000000000
s28=00000000 s29=00000000 d14=0000000000000000
s30=00000000 s31=00000000 d15=0000000000000000
FPSCR: 00000000 
I get this error when i force

Code: Select all

sudo 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-05-25-wheezy-raspbian.img -redir tcp:5022::22 
I have done all like in the howto... :(

Krautbert

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6239
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 Jul 04, 2013 5:47 am

krautbert wrote: I have done all like in the howto... :(
Krautbert
Hmm, not sure what went wrong there. =/

mpapis
Posts: 1
Joined: Fri Jul 05, 2013 4:13 am

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

Fri Jul 05, 2013 4:16 am

Partially based on this tutorial I have created a Linux tool to create and manage multiple virtual machines https://github.com/mpapis/myarm#readme – thanks a lot for the instructions!

ChrisAbela
Posts: 7
Joined: Tue Jul 09, 2013 8:10 pm

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

Tue Jul 09, 2013 8:38 pm

This is just to report that these instructions were very helpful also on Slackware 14.0.

I had fallen to the temptation of increasing the memory to 512M ( qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 512 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1" -hda ~/qemu_vms/2013-05-25-wheezy-raspbian.img -redir tcp:5022::22) and I was left with a blank qemu window. I reverted to 256MB and then it worked.

Thank you for the easy instructions

Johntron
Posts: 1
Joined: Sun Sep 08, 2013 5:18 pm

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

Sun Sep 08, 2013 5:21 pm

I tried launching Raspbian Wheezy with QEMU 1.6 (installed via Homebrew), and I don't get any errors, but I also don't get a prompt. QEMU just shows a blank white screen with no output in the terminal, and SSH connections timeout. If anyone has this working, I'd love to know the steps you followed.

FWIW - I wasn't able to mount the image with OS X, so I copied it to an Ubuntu 13 VM for the conversion then copied back.

kiparsky
Posts: 1
Joined: Fri Oct 04, 2013 4:47 am

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

Fri Oct 04, 2013 6:09 am

This may be a noobish question, so apologies if this is something I should know already. I am in fact a noob when it comes to RPi.

I've followed the instructions in this guide and also here: http://xecdesign.com/qemu-emulating-ras ... -easy-way/ (very similar). When I launch qemu, it starts up and gives me a login prompt, so I use the pi/raspberry login combo. The login is apparently accepted - it gives the usual disclaimers - but then prints out a warning that "the software on this Raspberry Pi has not been fully configured" and returns me to the login prompt.

I've pulled the previous raspbian image (2013-9-10) and got the same result.

Note:
Qemu gives you a root shell, run:
This does not happen in my case - I go straight to the ordinary login

Note #2: when I comment out the line in ld.so.preload, the emulator never gets past "... done, booting the kernel." If I leave that line in, I get to the login prompt and the issues described above.

If anyone can suggest where I might be going wrong, that would be lovely.

SacredRose
Posts: 25
Joined: Mon Sep 02, 2013 8:39 am

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

Tue Oct 08, 2013 9:52 am

i have a little question.

for the purpose of making an easy guide to doing some stuff on the pi i wanted to virtualize it so i can make screenshots directly on my main workingstation. i installed an ubuntu 12.04 VM and followed your steps here to get the RPi virtualized and have it working but would it be possible to get internet acces on it ? (the VM does have internet).

sorry if it is a stupid question but this is the first time working with qemu.

thither
Posts: 4
Joined: Wed Dec 19, 2012 6:17 pm

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

Fri Oct 18, 2013 4:23 pm

kiparsky wrote:This may be a noobish question, so apologies if this is something I should know already. I am in fact a noob when it comes to RPi.

I've followed the instructions in this guide and also here: http://xecdesign.com/qemu-emulating-ras ... -easy-way/ (very similar). When I launch qemu, it starts up and gives me a login prompt, so I use the pi/raspberry login combo. The login is apparently accepted - it gives the usual disclaimers - but then prints out a warning that "the software on this Raspberry Pi has not been fully configured" and returns me to the login prompt.

I've pulled the previous raspbian image (2013-9-10) and got the same result.

Note:
Qemu gives you a root shell, run:
This does not happen in my case - I go straight to the ordinary login

Note #2: when I comment out the line in ld.so.preload, the emulator never gets past "... done, booting the kernel." If I leave that line in, I get to the login prompt and the issues described above.

If anyone can suggest where I might be going wrong, that would be lovely.
I've been running into the same problems on OS/X 10.8.5 with qemu 1.6.0 installed from homebrew. I couldn't figure out any way to modify /etc/ld.so.preload on OS/X (there are no convenient tools for mounting the linux filesystem) so I haven't tried that yet. Here's the command-line I'm using:
qemu-system-arm -cpu arm1136-r2 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1 console=ttyAMA0" -hda 2013-09-25-wheezy-raspbian.img -kernel kernel-qemu
The system boots but just winds up with a login screen, and logging in as pi kicks me back out to the login screen again.

I got a little farther by appending "-s" to the -append command-line option in order to get the kernel to boot into single-user mode. Unfortunately, when it does this it mounts the root filesystem as read-only, so I can't actually do anything useful (like commenting out the line in ld.so.preload).

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6239
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 Oct 18, 2013 10:26 pm

You should be able to remount it as rw. Or, boot with init=/bin/bash rw in the kernel options instead and that should give you all the access you need to modify things.

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

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

Thu Oct 31, 2013 3:32 pm

Greetings to everyone!
Excuse me for dumb question, but I'm running out of ideas.
I'm using 2013-09-25-wheezy-raspbian.zip, downloaded from link in the manual:
http://www.raspberrypi.org/downloads
My sequence of actions:
1) Unpacked zip to 2013-09-25-wheezy-raspbian.img
2) Followed the manual up to point with

Code: Select all

$ sudo nano /mnt/etc/ld.so.preload
The problem is, that there is no such file, either as the folder. Does this method work with newer distributives?

Anyway, without commenting string in ld.so.preload, I'm facing the login-loop problem, as described by users earlier
http://www.raspberrypi.org/phpBB3/viewt ... 66#p354866
What should I do?

I'm using Ubuntu 13.04. Can this be the reason?

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6239
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 Oct 31, 2013 6:56 pm

Nod, I've just used the steps in the tutorial with the newest image and it works fine. I can only suggest trying again, but being more careful.

I have also updated my tutorial http://xecdesign.com/qemu-emulating-ras ... -easy-way/ to use a new method, so if all else fails, you could try the steps outlined there.

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

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

Fri Nov 08, 2013 12:53 pm

Here's my output of ls on /mnt after mounting the img. No directories at all.

Explain, please, where can I find the ld.so.preload? Or maybe there is any other way to comment the line?
Attachments
screen.png
screen.png (29.95 KiB) Viewed 11255 times

Return to “Advanced users”