Skip to content

Instantly share code, notes, and snippets.

@FFY00
Last active January 9, 2020 23:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FFY00/8aaa05f01c16f88bf6bee85748824c25 to your computer and use it in GitHub Desktop.
Save FFY00/8aaa05f01c16f88bf6bee85748824c25 to your computer and use it in GitHub Desktop.
Kernel Development Setup
  1. Create the disk

Let's create a raw disk (you can use other tools like dd too)

qemu-img create -f raw kernel-dev.img 20G

Now install the system

qemu-system-x86_64 -drive format=raw,file=kernel-dev.img -enable-kvm -boot d -cdrom your.iso
  1. Create the initrd

We will use dracut to create a custom initrd with our kenel parameters

dracut --no-compress --no-kernel --kernel-cmdline 'root=/dev/sda rw' -f initramfs.img

Qemu allows you to boot the system without a initrd but I have found it to be very hard to setup

  1. Done!

Now you should be able to run it

qemu-system-x86_64 -kernel path/to/your/kernel/linux/arch/x86/boot/bzImage -drive format=raw,file=kernel-dev.img -initrd initramfs.img -enable-kvm

Some extra options to add:

  • -append console=ttyS0: redirects the console to the serial port
  • -m 4G: sets the RAM to use (in this case 4GB)
  • -smp 2: sets the number of cores to use (in this case 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment