Setting up development environment using QEMU.
---------- Forwarded message ---------- From: Aft nix <aftnix@gmail.com> Date: Fri, Jun 8, 2012 at 6:07 PM Subject: Setting up development environment using QEMU. To: kernelnewbies@kernelnwebies.org -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi all, I'm trying to set up a development environment for Kernel development. What have done is follows: 1. setarch linux32 make defconfig. 2.make oldconfig O=/mnt/build/linux 3.make menuconfig O=/mnt/build/linux 4.make. After that i'm trying to boot the the new kernel in QEMU with GDB stub as following: $qemu -s -S /dev/zero -kernel /mnt/build/linux/arch/x86/boot/bzImage Then i get the tcp port which qemu listens for an incoming gdb client : $netstat -tap | grep qemu Then i use gdb /mnt/build/linux/vmlinux to load the image. And set the target to the remote port. But when i get a connection, Qemu Starts to boot. But it complains that the kernel needs a 64 bit Cpu. But as i have configured it to be x86 it should not be the case. Where i'm doing something wrong? Cheers - -- - -aft -----BEGIN PGP SIGNATURE----- Version: OpenPGP.js v0.1 Comment: http://openpgpjs.org wsBcBAEBAgAQBQJP0ernCRCJVJ6A/SK8awAAKFIH/islnSkDpngVvblI8saV g5eBZC1rwtaHTgdpNEi6PmlwdIid8jXerKASpeW3KGtW0KGjIR0KBnFbpbW5 O2A/XJUdmwakx6hFxs2eqGUOysCCCY/c6wyEWmnsLeThkS0KId2sQR7jf4HH 9Paa3Qzl6c1cXM96P+VZeDPcY08iQaBbFkqIZtW5RxTA8dmyUoHAzAepjpTS TeI/Lypsd4G4vpbYJ3ecNfiei0zowc0DRcaPmCY7goNVxU7M7rsVUchasQOo IQ+Djc9CRMVWxXc040mQroZMOzvdoG4zgeNRrbYQVWkcxHPXaOPNsUXy2OBV wPql8fe5CMI3FgvcRusTsBI= =5ORx -----END PGP SIGNATURE----- -- -aft
On Fri, Jun 08, 2012 at 06:08:44PM +0600, Aft nix wrote:
But when i get a connection, Qemu Starts to boot. But it complains that the kernel needs a 64 bit Cpu.
But as i have configured it to be x86 it should not be the case.
Sure about this? Check the output of `file vmlinux`
Where i'm doing something wrong?
What's the arch of your host system, and your toolchain? BTW, my kernel developing and debugging environment: https://github.com/adam8157/kernel-studio -- Regards, Adam Lee -------------------------------- E-mail: adam8157@gmail.com Website: http://adam8157.info --------------------------------
On Fri, Jun 8, 2012 at 6:46 PM, Adam Lee <adam8157@gmail.com> wrote:
On Fri, Jun 08, 2012 at 06:08:44PM +0600, Aft nix wrote:
Sure about this? Check the output of `file vmlinux`
You were right then. $file vmlinux $vmlinux: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped
What's the arch of your host system, and your toolchain?
$uname -ar $Linux kernel.vbox 2.6.32-220.el6.x86_64 #1 SMP Tue Dec 6 19:48:22 GMT 2011 x86_64 x86_64 x86_64 GNU/Linux $gcc -v Using built-in specs. Target: x86_64-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux Thread model: posix gcc version 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC)
BTW, my kernel developing and debugging environment: https://github.com/adam8157/kernel-studio
Thanks for the link. I will look into it.
-- Regards, Adam Lee -------------------------------- E-mail: adam8157@gmail.com Website: http://adam8157.info --------------------------------
-- -aft
On Fri, Jun 8, 2012 at 6:46 PM, Adam Lee <adam8157@gmail.com> wrote:
On Fri, Jun 08, 2012 at 06:08:44PM +0600, Aft nix wrote:
Sure about this? Check the output of `file vmlinux`
You were right then.
$file vmlinux $vmlinux: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped
What's the arch of your host system, and your toolchain?
$uname -ar $Linux kernel.vbox 2.6.32-220.el6.x86_64 #1 SMP Tue Dec 6 19:48:22 GMT 2011 x86_64 x86_64 x86_64 GNU/Linux $gcc -v Using built-in specs. Target: x86_64-redhat-linux
So, just add ARCH var when you making, like this: make ARCH=i386 menuconfig make ARCH=i386 bzImage Tested OK. -- Regards, Adam Lee -------------------------------- E-mail: adam8157@gmail.com Website: http://adam8157.info --------------------------------
Hello guys, As I have recently came to know about QEMU which is a quick emulator and support emulation of ARM architecture. I wanted to boot linux onto QEMU, by setting up various nodes and devices from scratch. I want everything to be hand coded or atleast should have an idea of the (what my code does) boot process, setting up of devices, loading the kernel, and finally playing a audio/video file by writing my own codec. can anyone please provide me links for the tutorials and any help will be appreciated.
On Fri, Jun 8, 2012 at 8:20 PM, Adam Lee <adam8157@gmail.com> wrote:
On Fri, Jun 8, 2012 at 6:46 PM, Adam Lee <adam8157@gmail.com> wrote:
On Fri, Jun 08, 2012 at 06:08:44PM +0600, Aft nix wrote:
Sure about this? Check the output of `file vmlinux`
You were right then.
$file vmlinux $vmlinux: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped
What's the arch of your host system, and your toolchain?
$uname -ar $Linux kernel.vbox 2.6.32-220.el6.x86_64 #1 SMP Tue Dec 6 19:48:22 GMT 2011 x86_64 x86_64 x86_64 GNU/Linux $gcc -v Using built-in specs. Target: x86_64-redhat-linux
So, just add ARCH var when you making, like this:
make ARCH=i386 menuconfig make ARCH=i386 bzImage
Tested OK.
Thank you for the tips. qemu is booting the kernel now. But it stops with a kernel panic.
From qemu console,
[ 2.209887] EXT3-fs (sda): mounted filesystem with writeback data mode [ 2.210566] VFS: Mounted root (ext3 filesystem) readonly on device 8:0. [ 2.211393] Freeing unused kernel memory: 456k freed [ 2.242325] Write protecting the kernel text: 6240k [ 2.242614] Write protecting the kernel read-only data: 1820k [ 2.248007] Kernel panic - not syncing: No init found. Try passing init= option to kernel. See Linux Documentation/init.txt for guidance. [ 2.248492] Pid: 1, comm: swapper/0 Not tainted 3.4.0+ #3 [ 2.248596] Call Trace: [ 2.249743] [<c160db4f>] panic+0x81/0x17e [ 2.249843] [<c10012d5>] init_post+0x75/0xb0 [ 2.249942] [<c183a61a>] kernel_init+0x1e0/0x1ea [ 2.250028] [<c183a3df>] ? parse_early_options+0x35/0x35 [ 2.250237] [<c183a43a>] ? repair_env_string+0x5b/0x5b [ 2.250326] [<c1616cd6>] kernel_thread_helper+0x6/0xd I've started reading Documentation/init.txt, But i'm not understanding well. It seems the "init" binary is missing which should be on the root file system. the sell script i'm using to launch qemu is given below : #!/bin/bash # by, uberj KERNEL=/mnt/build/linux-2.6/arch/i386/boot/bzImage usage(){ echo "./startup.sh <group_port> <hdd image>" echo "Kernel image is $KERNEL." } if [ $# != 2 ] then usage exit fi QEMU_BIN=/usr/bin/qemu HDD=$2 SSH_PORT=$((5100+$1)) GDB_PORT=$((5200+$1)) DEV_CONSOLE=stdio VNC_PORT=$1 echo "===SSH Port=== $SSH_PORT" echo "===GDB Port=== $GDB_PORT" echo "===VNC Port=== $VNC_PORT" $QEMU_BIN \ -cpu qemu64 \ -net nic,model=e1000 \ -net user \ -vnc :$VNC_PORT \ -gdb tcp::$GDB_PORT \ -kernel $KERNEL \ -hda $HDD \ -append "root=/dev/sda console=ttyS0" \ -redir tcp:$SSH_PORT::22 \ -serial $DEV_CONSOLE \ I have made my root FS by following method : $losetup /dev/loop0 rootfs.img $mkfs -t ext3 /dev/loop0 My understanding is i have to put the init binary in my root fs. But i'm clueless about how to do that? Cheers.
-- Regards, Adam Lee -------------------------------- E-mail: adam8157@gmail.com Website: http://adam8157.info --------------------------------
-- -aft
On Sat, Jun 09, 2012 at 04:19:15PM +0600, Aft nix wrote:
Thank you for the tips. qemu is booting the kernel now. But it stops with a kernel panic.
From qemu console,
[ 2.209887] EXT3-fs (sda): mounted filesystem with writeback data mode [ 2.210566] VFS: Mounted root (ext3 filesystem) readonly on device 8:0. [ 2.211393] Freeing unused kernel memory: 456k freed [ 2.242325] Write protecting the kernel text: 6240k [ 2.242614] Write protecting the kernel read-only data: 1820k [ 2.248007] Kernel panic - not syncing: No init found. Try passing init= option to kernel. See Linux Documentation/init.txt for guidance. [ 2.248492] Pid: 1, comm: swapper/0 Not tainted 3.4.0+ #3 [ 2.248596] Call Trace: [ 2.249743] [<c160db4f>] panic+0x81/0x17e [ 2.249843] [<c10012d5>] init_post+0x75/0xb0 [ 2.249942] [<c183a61a>] kernel_init+0x1e0/0x1ea [ 2.250028] [<c183a3df>] ? parse_early_options+0x35/0x35 [ 2.250237] [<c183a43a>] ? repair_env_string+0x5b/0x5b [ 2.250326] [<c1616cd6>] kernel_thread_helper+0x6/0xd ... My understanding is i have to put the init binary in my root fs. But i'm clueless about how to do that?
You need a full system, kernel is just the core. I suggest you using Debian stable images for QEMU at http://people.debian.org/~aurel32/qemu (ref: http://wiki.debian.org/QEMU) Or, use busybox to build rootfs like what I am doing: https://github.com/adam8157/kernel-studio -- Regards, Adam Lee -------------------------------- E-mail: adam8157@gmail.com Website: http://adam8157.info --------------------------------
On Sat, Jun 9, 2012 at 8:01 PM, Adam Lee <adam8157@gmail.com> wrote:
On Sat, Jun 09, 2012 at 04:19:15PM +0600, Aft nix wrote:
Thank you for the tips. qemu is booting the kernel now. But it stops with a kernel panic.
From qemu console,
[ 2.209887] EXT3-fs (sda): mounted filesystem with writeback data mode [ 2.210566] VFS: Mounted root (ext3 filesystem) readonly on device 8:0. [ 2.211393] Freeing unused kernel memory: 456k freed [ 2.242325] Write protecting the kernel text: 6240k [ 2.242614] Write protecting the kernel read-only data: 1820k [ 2.248007] Kernel panic - not syncing: No init found. Try passing init= option to kernel. See Linux Documentation/init.txt for guidance. [ 2.248492] Pid: 1, comm: swapper/0 Not tainted 3.4.0+ #3 [ 2.248596] Call Trace: [ 2.249743] [<c160db4f>] panic+0x81/0x17e [ 2.249843] [<c10012d5>] init_post+0x75/0xb0 [ 2.249942] [<c183a61a>] kernel_init+0x1e0/0x1ea [ 2.250028] [<c183a3df>] ? parse_early_options+0x35/0x35 [ 2.250237] [<c183a43a>] ? repair_env_string+0x5b/0x5b [ 2.250326] [<c1616cd6>] kernel_thread_helper+0x6/0xd ... My understanding is i have to put the init binary in my root fs. But i'm clueless about how to do that?
You need a full system, kernel is just the core.
I suggest you using Debian stable images for QEMU at http://people.debian.org/~aurel32/qemu (ref: http://wiki.debian.org/QEMU)
Or, use busybox to build rootfs like what I am doing: https://github.com/adam8157/kernel-studio
Hi Adam Thanks for the reply. Googling revealed other ways of debugging. I was not aware that KGDB was merged with linux in 2.6.26. I was under the impression that Linux does not allow kernel debugger in kernel source tree. If i compile a kernel with KGDB , and if i'm not developing for "other" archs like ppc/arm then there is little gain in qemu's gdb stub. Instead i can fire up a full distro in Virtualbox, configure a virtual serial console and "socat" from the host. This link : http://www.linuxforu.com/2011/03/kgdb-with-virtualbox-debug-live-kernel/ I'm trying to follow this link instead. I'm not experienced in this field, so my reasoning might be wrong. If it is, please comment on my approach. Cheers.
-- Regards, Adam Lee -------------------------------- E-mail: adam8157@gmail.com Website: http://adam8157.info --------------------------------
-- -aft
participants (3)
-
Adam Lee -
Aft nix -
Ritesh Harjani