linux-kernelqemuinitrd

Qemu fails to load when my initrd (cpio) is large ~80 mb


I am new to qemu and am trying to learn kernel programming, I create an initrd which has busy box, but when I add a big tarbal ~80Mb in the cpio qemu fails to load.

I wanted to include golang in intrd, so that i could test the new kernel.

This is what is happening:

mfrw@kp ~/os/busybox/test_build
 % ls
bin  linuxrc  sbin  usr
mfrw@kp ~/os/busybox/test_build
 % !find
find . | cpio -o -H newc | gzip > rootfs_bb.gz
cpio: File ./rootfs_bb.gz grew, 1261568 new bytes not copied
7374 blocks
mfrw@kp ~/os/busybox/test_build
 % ls -ltrh
total 2.6M
drwxr-xr-x 2 mfrw mfrw 4.0K Mar 18 01:56 bin
lrwxrwxrwx 1 mfrw mfrw   11 Mar 18 01:56 linuxrc -> bin/busybox
drwxr-xr-x 2 mfrw mfrw 4.0K Mar 18 01:56 sbin
drwxr-xr-x 4 mfrw mfrw 4.0K Mar 18 15:24 usr
-rw-r--r-- 1 mfrw mfrw 2.6M Mar 18 15:31 rootfs_bb.gz
mfrw@kp ~/os/busybox/test_build
 % 

Then I run it using qemu with a freshly made kernel with rootfs = 2.6 M

mfrw@kp ~/os/linux_staging % qemu-system-x86_64 -nographic -no-reboot -kernel arch/x86/boot/bzImage -initrd ./../busybox/test_build/rootfs_bb.gz  -append "panic=1 console=ttyS0 rdinit=/bin/sh"
[    0.000000] Linux version 4.11.0-rc2+ (mfrw@kp) (gcc version 6.3.1 20170109 (GCC) ) #7 SMP Sat Mar 18 02:34:27 IST 2017
[    0.000000] Command line: panic=1 console=ttyS0 rdinit=/bin/sh
[    0.000000] x86/fpu: x87 FPU will use FXSAVE
[    0.000000] e820: BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
...... the kernel boots fine

But When I include the tar.gz for golang in the rootfs, it shoots upto 80M and then fails to boot

mfrw@kp ~/os/busybox/test_build
 % cp ~/go/go1.6.linux-amd64.tar.gz usr 
mfrw@kp ~/os/busybox/test_build
 % !fin
find . | cpio -o -H newc | gzip > rootfs_bb.gz
170406 blocks
mfrw@kp ~/os/busybox/test_build
 % ls -ltrh
total 82M
drwxr-xr-x 2 mfrw mfrw 4.0K Mar 18 01:56 bin
lrwxrwxrwx 1 mfrw mfrw   11 Mar 18 01:56 linuxrc -> bin/busybox
drwxr-xr-x 2 mfrw mfrw 4.0K Mar 18 01:56 sbin
drwxr-xr-x 4 mfrw mfrw 4.0K Mar 18 15:34 usr
-rw-r--r-- 1 mfrw mfrw  82M Mar 18 15:34 rootfs_bb.gz
mfrw@kp ~/os/busybox/test_build
 % 

I try to run it with the same command and it fails to run...

mfrw@kp ~/os/linux_staging % qemu-system-x86_64 -nographic -no-reboot -kernel arch/x86/boot/bzImage -initrd ./../busybox/test_build/rootfs_bb.gz  -append "panic=1 console=ttyS0 rdinit=/bin/sh"
.... no .. output

What am I doing wrong ? Any pointers please :)


Solution

  • I found the solution finally, did not give it enough memory so it was failing. I finally ran it with

    -m size=512

    And it ran well