Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qemu emulation #34

Closed
mcanevet opened this issue Mar 28, 2014 · 40 comments
Closed

Qemu emulation #34

mcanevet opened this issue Mar 28, 2014 · 40 comments

Comments

@mcanevet
Copy link
Contributor

It would be great if we could use qemu to debug the installer but I don't really know how to make it work.

I tried with this command line without any success:

qemu-system-arm -kernel kernel_install.img -initrd installer.cpio -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "consoleblank=0"

The only thing I get is a black screen.

Any idea ?

@mcanevet
Copy link
Contributor Author

OK I have it almost running using the kernel provided here http://xecdesign.com/downloads/linux-qemu/kernel-qemu with this command line:

qemu-system-arm -kernel kernel-qemu -initrd bootfs/installer.cpio -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "consoleblank=0" test.img

It get this installer but it fails because the kernel sees the disk as /dev/sda, while a real pi sees /dev/mmcblk0.

@hifi
Copy link
Contributor

hifi commented Apr 1, 2014

At first I tried to dev with QEMU, but because of the huge differences it wasn't possible to have a single install script. There's also a Pi QEMU fork but it doesn't have networking so while it has proper device support for USB and everything it still was unable to perform a networked installation.

@diederikdehaas
Copy link
Member

Any new progress to report on this @mcanevet ?
I'd like to do this as well, since constantly flashing my SD card will probably wear it down pretty quickly.
Any idea what's so special about 'kernel-qemu'?

@mcanevet
Copy link
Contributor Author

mcanevet commented Jun 2, 2014

@diederikdehaas no. I don't really have time to play with my raspberry this days.

@diederikdehaas
Copy link
Member

Ok, thanks for your response. It was worth a shot ;-)

@dhanar10
Copy link

In case anyone still interested, I actually managed to run raspbian-ua-netinst on qemu-system-arm and generate bootable raspbian image with the hints provided by @mcanevet on Mar 29.

Basically, what I did was I downloaded "raspbian-ua-netinst-v1.0.5.img", take the "installer.cpio", extract it and then edit the "rcS" file with the following.

bootdev=/dev/sda
bootpartition=/dev/sda1
rootdev=/dev/sda
rootpartition=/dev/sda2

After that, rebuild the "installer.cpio" and then boot the "raspbian-ua-netinst-v1.0.5.img" with qemu-system-arm using "kernel-qemu" and the modified "installer.cpio".

In order to boot the resulting raspbian image on a real Raspberry Pi, an adjustment on the config.txt and fstab is required (replace /dev/sda* with /dev/mmcblk0*).

It would be nice if this configuration for booting on qemu-system-arm can be implemented in raspbian-ua-netinst, but I still have no idea how to integrate it elegantly. For now, I execute the above steps manually everytime I need to boot raspbian-ua-netinst on qemu-system-arm.

@goranche
Copy link
Contributor

👍 good to know, and I agree it would be nice to automate this in some manner, but I'm not sure how, have to think about it...
the build process is easy, of course, but the switching, don't see an elegant solution, except for a script that allows you to switch

@diederikdehaas
Copy link
Member

Basically, what I did was I downloaded "raspbian-ua-netinst-v1.0.5.img", take the "installer.cpio", extract it and then edit the "rcS" file with the following.
bootdev=/dev/sda
bootpartition=/dev/sda1
rootdev=/dev/sda
rootpartition=/dev/sda2

I haven't tried it myself, but whtat happens if you specify those 4 params in installer-config.txt?

And thanks for diving into this, I'm definitively interested 👍

@dhanar10
Copy link

If I specify those 4 params in "installer-config.txt", it does not work.

This is because the "installer-config.txt" is only parsed after "Copying boot files... " step. In other words, it is too late.

I have tried to move the parsing of "installer-config.txt" before "Copying boot files... " step, but then it became a chicken and egg problem. We need to read "installer-config.txt" from $bootpartition, but the correct $bootpartition is not yet set and the correct value for $bootpartition is inside "installer-config.txt".

This is a crazy suggestion but to solve the chicken and egg problem, is it possible to move the setting for those 4 params to cmdline.txt then make rcS script to read from /proc/cmdline? I don't know if it can work because I haven't got the time to test it yet.

@goranche
Copy link
Contributor

that might work, but might have serious side effects as well, cmdline is intended for kernel use...
I'd recommend against it

I was thinking in the line of building (and naming the files appropriately) 2 different cmdline.cpio files (like I said, it's not elegant, but the differences are large enough for this to be an option to consider... IMHO, of course)

@diederikdehaas
Copy link
Member

I'm also against abusing cmdline.txt for this.

I have to give this some more thought, but I was thinking of having a build-qemu.sh alongside build.sh and buildroot.sh

@dhanar10
Copy link

I am not sure if cmdline is intended only for kernel use. This is because in Debian (squeeze, wheezy) I remember that by appending "text" to the cmdline on boot, the X server won't be started because it detects "text" in /proc/cmdline. But, I don't know.

Anyway, I have written a script which will generate "installer-qemu.cpio" and prepare "raspbian-ua-netinst-v1.0.5.img" for running on qemu-system-arm. It is here: http://pastebin.com/sqtQ19Ci

@diederikdehaas
Copy link
Member

Thanks a LOT for sharing your findings and code 👍

@dhanar10
Copy link

You are welcome. But the heavy lifting is to somehow integrate that to raspbian-ua-netinst. I will leave that to the project owner and collaborators to decide what is the best way to do that.

@goranche
Copy link
Contributor

I was thinking of including a setting option (boolean flag) like "build-quemu-image" (well, probably something shorter 👼 ), and rebuild the image with -qemu attached to the filename...

now that becomes almost as easy as directly copy-pasting the code from @dhanar10 👍
but that's just a quick thought, please, other ideas and comments welcome

@diederikdehaas
Copy link
Member

including a setting option (boolean flag) like "build-quemu-image"

I thought about sth like that too, only to realize that we don't have a configuration file for the build process, only for the to be installed system. Doesn't mean we can't create one 😉

@goranche
Copy link
Contributor

command line parameters FTW!!! (ok, it's not exactly cmdline, but close 👼 )

also, who says the build script can't actually read the same config file, just respond to different options

@JedMeister
Copy link

It's be great if the raspian netinstall could run easily on QEMU so +1 for some sort of option that can be run OOTB.

But in the meantime I too have been having issues. I was hoping that this thread may help me...

I am running QEMU 2.1.2 (from wheezy-backports) on a headless Debian Wheezy server. I am trying to launch with this command:

qemu-system-arm -kernel ~/qemu_vms/kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -append "root=/dev/sda1 rw  vga=normal console=ttyAMA0" -hda ~/qemu_vms/netinst-fix/raspbian-ua-netinst-v1.0.5.img -nographic

I have essentially used the same command to successfully launch the full Raspian image but the netinstaller quits with: Kernel panic - not syncing: No init found. Try passing init= option to kernel. See Linux Documentation/init.txt for guidance.

@dhanar10 I was hoping that your script might solve my issue but I'm not quite sure what to do with the resulting installer-qemu.cpio!? After running your script:
I retried the raspbian-ua-netinst-v1.0.5.img again - same result.
I tried adding installer-qemu.cpio to the image - same result.
I also tried replacing installer.cpio with installer-qemu.cpio (i.e. deleted installer.cpio and renamed installer-qemu.cpio) - same result

What am I doing wrong...?

@dhanar10
Copy link

@JedMeister Basically, the script generates "installer-qemu.cpio" and modifies "raspbian-ua-netinst-v1.0.5.img" for booting on qemu. I assume you have read the script and understand this, yes?

After that, to boot raspbian-ua-netinst on qemu, you need to use the "installer-qemu.cpio" and the modified "raspbian-ua-netinst-v1.0.5.img". I use the following command.

qemu-system-arm -kernel "kernel-qemu" -initrd "installer-qemu.cpio" -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "consoleblank=0" "raspbian-ua-netinst-v1.0.5.img"

It seems that you missed the -initrd "installer-qemu.cpio" option.

@JedMeister
Copy link

@dhanar10 Thanks champ! :) That did it... I got the theory of what your script did, but just wasn't clear on the exact usage. As usual I was overcomplicating it! I just had to run the script...Doh! :) Also the fundamental bit I was missing was -initrd installer-qemu.cpio

For the info of other newbish types it was this simple (on Wheezy headless server with QEMU installed from backports)

#install deps
apt-get update && apt-get install xz-utils kpartx

#download and extract image
wget https://github.com/debian-pi/raspbian-ua-netinst/releases/download/v1.0.5/raspbian-ua-netinst-v1.0.5.img.xz
xzcat raspbian-ua-netinst-v1.0.5.img.xz > raspbian-ua-netinst-v1.0.5.img

#download and run dhanar10's script
curl http://pastebin.com/download.php?i=sqtQ19Ci | tr -d '\r' > raspbian-ua-netinst-qemu-prep.sh
chmod +x raspbian-ua-netinst-qemu-prep.sh
./raspbian-ua-netinst-qemu-prep.sh raspbian-ua-netinst-v1.0.5.img

#launch QEMU (if you're not on a headless server you can probably simplify this...)
qemu-system-arm -kernel kernel-qemu -initrd installer-qemu.cpio -cpu arm1176 -m 256 -M versatilepb -no-reboot -append "root=/dev/sda1 rw vga=normal console=ttyAMA0" -hda raspbian-ua-netinst-v1.0.5.img -nographic

@diederikdehaas
Copy link
Member

Awesome guys 👍

@JedMeister
Copy link

Sorry guys... New problem... The created image hangs during boot (local console hangs just after starting SSH) although I can log in via SSH ok. Full details in #149 (I thought it best to start a new 'issue').

@hadess
Copy link

hadess commented Mar 8, 2015

I'll go back to one of the original comments about "abusing the kernel command-line". It's not only the kernel's. You're more than welcome to add more parameters you might need, just make sure to namespace them. So "raspbian-ua-netinst.boot=/dev/sda" is a fine solution.

@goranche
Copy link
Contributor

goranche commented Mar 9, 2015

It's not only the kernel's

I personally don't agree with that... it is the kernels command line (even the name says so 😉 ) and shouldn't be used for other things (unless there really is no other way, and even then you should be able to find another way)

@hadess
Copy link

hadess commented Mar 9, 2015

Do you want a list of things that aren't the kernel and that use the kernel command-line? Installers, init systems, boot splashes, and usually, hardware detection override (there's a couple of them in GNOME for that purpose).

@goranche
Copy link
Contributor

goranche commented Mar 9, 2015

do you think that such a list would change my opinion about the kernel command line being a kernel thing? 😉
I would call that list an example of how not to do things 👼

@diederikdehaas
Copy link
Member

I think it's much better to build for QEMU then add 'run-time detection' for QEMU in rcS.
This is a diff from a local branch I've used to add QEMU support:

diff --git a/build.sh b/build.sh
index 661cc03..830a44f 100755
--- a/build.sh
+++ b/build.sh
@@ -2,6 +2,8 @@

 set -e

+QEMU="true"
+
 KERNEL_VERSION=3.12-1-rpi
 INSTALL_MODULES="kernel/fs/f2fs/f2fs.ko"
 INSTALL_MODULES="$INSTALL_MODULES kernel/fs/btrfs/btrfs.ko"
@@ -213,6 +215,17 @@ cp tmp/lib/*/libz.so.1  rootfs/lib/libz.so.1
 cd rootfs && find . | cpio -H newc -ov > ../installer.cpio
 cd ..

+if [ "$QEMU" = "true" ] ; then 
+    # let's also make an installer.cpio suitable for qemu
+    sed -i '/^bootdev=/s|/dev/mmcblk0|/dev/sda|' "rootfs/etc/init.d/rcS"
+    sed -i '/^bootpartition=/s|/dev/mmcblk0p1|/dev/sda1|' "rootfs/etc/init.d/rcS"
+    sed -i '/^rootdev=/s|/dev/mmcblk0|/dev/sda|' "rootfs/etc/init.d/rcS"
+    sed -i '/^rootpartition=/s|$|/dev/sda2|' "rootfs/etc/init.d/rcS"
+    cd rootfs && find . | cpio -H newc -ov > ../installer-qemu.cpio
+    cd ..
+    # end qemu part
+fi
+
 rm -rf tmp
 rm -rf rootfs

@@ -235,7 +248,21 @@ if [ -d config ] ; then
     cp -r config/* bootfs/config
 fi

-ZIPFILE=raspbian-ua-netinst-`date +%Y%m%d`-git`git rev-parse --short @{0}`.zip
+ZIPFILE_BASE=raspbian-ua-netinst-`date +%Y%m%d`-git`git rev-parse --short @{0}`
+ZIPFILE=${ZIPFILE_BASE}.zip
 rm -f $ZIPFILE

 cd bootfs && zip -r -9 ../$ZIPFILE *; cd ..
+
+if [ "$QEMU" = "true" ] ; then 
+    # replace installer.cpio with the qemu variant
+    rm bootfs/installer.cpio
+    cp installer-qemu.cpio bootfs/installer.cpio
+    ZIPFILE_QEMU=${ZIPFILE_BASE}-qemu.zip
+    rm -f $ZIPFILE_QEMU
+    cd bootfs && zip -r -9 ../$ZIPFILE_QEMU *; cd ..
+    # restore the original installer.cpio
+    rm bootfs/installer.cpio
+    cp installer.cpio bootfs/
+fi
+

This was before the RPi2 support code was there and it's probably easier to do now.

@hadess
Copy link

hadess commented Mar 9, 2015

The problem I see with this is that you're modifying the rootfs files, so the changes are not undone when you create a non-QEmu images, and it makes it impossible to create an installer that go through the image creation on QEmu but targetted at physical Raspberry Pis.

@diederikdehaas
Copy link
Member

The idea is to create either an image for use with QEMU or an image for the RPi.
When you first create an image for QEMU and then you want to create one for the RPi, you'd run ./clean.sh first.

@hadess
Copy link

hadess commented Mar 9, 2015

Fair enough.

@HackTechDev
Copy link

Hi,

I have these errors:
[~/QEMU] ➔ ./raspbian-ua-netinst-qemu-prep.sh raspbian-ua-netinst-20150309-gitf31b204.img
Image resized.
./raspbian-ua-netinst-qemu-prep.sh: ligne 39: ../disk-image/boot/installer.cpio: Aucun fichier ou dossier de ce type
sed: impossible de lire etc/init.d/rcS: Aucun fichier ou dossier de ce type
sed: impossible de lire etc/init.d/rcS: Aucun fichier ou dossier de ce type
sed: impossible de lire etc/init.d/rcS: Aucun fichier ou dossier de ce type
sed: impossible de lire etc/init.d/rcS: Aucun fichier ou dossier de ce type

How to resolve them ?

Thx.

@HackTechDev
Copy link

I resolved my problem, see my tuto : http://framboisepi.fr/lancement-de-raspbian-a-partir-de-qemu/

hadess added a commit to hadess/raspbian-ua-netinst that referenced this issue Mar 11, 2015
@diederikdehaas
Copy link
Member

Anyone has any tips as to how to get networking working with QEMU?
I can't even get pinging based on IP address working :-(

@JedMeister
Copy link

Not sure @diederikdehaas.

I'm using QEMU from Wheezy backports and my guest was built with v1.0.6 of the UA-netinstall. I'm running a 3.10 kernel I compiled myself and it all just works OOTB...

Although FWIW by default QEMU uses NATed network AFAIK. So outgoing should be fine. I use redirection to allow incoming SSH connections: i.e. I use -redir tcp:5022::22 then connect to the RPi guest (from the host) via ssh -p 5022 root@localhost

@diederikdehaas
Copy link
Member

Looks like it was false alarm 😄
I was working with a development image and in that dns didn't work. My first step in troubleshooting network issues is doing a ping, but according to the documentation that's expected:
ICMP traffic does not work (so you cannot use ping within a guest)
But now that I've fixed the dns issue, it is working properly.
This is how I use QEMU (on Debian Sid) atm:

$ stty intr ^]
$ qemu-system-arm -kernel "kernel-3.12.9-1+rpi2-qemu" -initrd "installer-qemu.cpio" \
 -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio \
-append "consoleblank=0 console=ttyAMA0 console=ttyS0" \
"raspbian-ua-netinst-20150325-git17e4c6d.img"

The first command is to remap quitting QEMU to Ctrl-] (instead of Ctrl-C) and then it starts QEMU and I get a serial console to interact with it, which works great.
I'm (also) using a custom compiled kernel and the image I'm using is a freshly build installer which then gets put through @dhanar10's excellent script, which also produces the initrd file.

I finally got around to (trying to) develop using QEMU and I have to say it's quite nice 😄

@diederikdehaas
Copy link
Member

Since we're doing runtime detection now to distinguish between RPi 1 and 2, doing so for QEMU might not be such a bad idea. The following commands look useful in my situation:

grep Hardware /proc/cpuinfo | cut -d " " -f 2-3
if [ $(dmesg | grep QEMU | wc -l) -gt 0 ] ; then
   QEMU=true
fi

@diederikdehaas diederikdehaas added this to the v1.1.0 milestone Oct 9, 2015
@bbinet
Copy link
Contributor

bbinet commented Nov 19, 2015

+1 it would be great to be able to run the same image on both rpi and Qemu

@goranche
Copy link
Contributor

I'm removing this from the v1.1.0 milestone, as there doesn't seem to be too much interest in working on this one... not closing it though, as it is still an interesting one

@Mausy5043
Copy link
Contributor

Closing this issue as there hasn't been any activity here for more than a year. If you feel the closure was in error please feel free to re-open with your comment and/or new info.

@Mausy5043
Copy link
Contributor

hoehnp pushed a commit to hoehnp/raspbian-ua-netinst that referenced this issue Jul 14, 2019
This sets F2FS instead of EXT4 as default root file system which is better for usage with SD cards and flash storage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants