If you are playing around with qemu, sometimes it is useful to have a kernel and initrd easily available to play with. Cirros provides kernel and initramfs that can be used for this purpose.
This init
script here provides a initramfs /init
that will do nothing
but write the kernel command line and then power the system off. You can
adjust it to your needs.
The get-krd
script will:
- download cirros kernel to 'kernel' and initramfs to 'initramfs.dist'
- create 'initramfs' with
init
as the/init
by appending to the cpio archive.
You can use this basically like below, the kernel and initramfs boot,
the provided init
which executes echo o >/proc/sysrq-trigger
and powers off the system.
$ ./get-krd .
using cached ./kernel
using cached ./initramfs.dist
created ./initramfs with 'init' from /tmp/testing
$ ls -l kernel initramfs
-rw-rw-r-- 1 smoser smoser 6581017 Mar 14 15:12 initramfs
-rw-rw-r-- 1 smoser smoser 9144704 Dec 7 02:53 kernel
$ time qemu-system-x86_64 -enable-kvm -m 1024 -nographic \
-kernel ./kernel -initrd ./initramfs \
-append "console=ttyS0 this is my cmdline"
Booting from ROM...
[ 0.000000] Linux version 5.3.0-26-generic (buildd@lgw01-amd64-039) (gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1)) #28~18.04.1-Ubuntu SMP Wed Dec 18 16:40:14 UTC 2019 (Ubuntu 5.3.0-26.28~18.04.1-generic 5.3.13)
[ 0.000000] Command line: console=ttyS0 this is my cmdline
[ 0.000000] KERNEL supported cpus:
[ 0.000000] Intel GenuineIntel
[ 0.000000] AMD AuthenticAMD
[ 0.000000] Hygon HygonGenuine
[ 0.000000] Centaur CentaurHauls
[ 0.000000] zhaoxin Shanghai
[ 0.000000] x86/fpu: x87 FPU will use FXSAVE
...
[ 0.000000] BIOS-provided physical RAM map:
[ 0.987858] x86/mm: Checked W+X mappings: passed, no W+X pages found.
[ 0.988673] Run /init as init process
==== MINI INITRAMFS INIT ====
KERNEL COMMAND LINE: console=ttyS0 this is my cmdline
[ 0.993539] sysrq: Power Off
[ 0.994119] reboot: Power down
real 0m1.339s
user 0m0.685s
sys 0m0.472s