Passing boot arguments to the Linux kernel with QEMU
In this article, we will cover how to pass boot arguments to a Linux kernel using QEMU (Quick Emulator). Specifically, we will demonstrate how to boot a Linux kernel image, which has been extracted for a specific hardware target and begins with ARM opcodes, without a header or any other additional information that could interfere with a successful boot.
Overview
QEMU is a popular open-source emulator that allows us to emulate different hardware architectures, including ARM, x86, and PowerPC, among others. It has gained tremendous popularity in the embedded systems and IoT communities due to its ability to emulate a wide variety of boards and systems, allowing developers to test and debug their code on different hardware platforms without the need for physical hardware.
When it comes to booting a Linux kernel using QEMU, it's essential to pass the correct boot arguments to the kernel to ensure a successful boot. These boot arguments can include information such as the root filesystem, console log level, and device tree, among others. Passing the wrong boot arguments or omitting some critical information can result in a failed boot, making it crucial to understand how to pass boot arguments to the Linux kernel using QEMU.
Linux Kernel Image
In order to boot a Linux kernel using QEMU, we need to have a Linux kernel image that has been extracted for a specific hardware target. This image should contain only the ARM opcodes that are required to boot the kernel, without any header or other additional information that could interfere with a successful boot.
To extract the kernel image, we can use the extract-vmlinuz script provided by the Linux kernel source tree. This script takes the vmlinuz file as input and extracts the kernel image to a file named vmlinux.
$ cd linux-source-tree
$ scripts/extract-vmlinuz vmlinuz vmlinuxPassing Boot Arguments
Once we have the Linux kernel image extracted for our target hardware, we can pass boot arguments to the Linux kernel using QEMU's -append option. This option allows us to specify the boot arguments that we want to pass to the kernel as a single string, separated by spaces.
Here are some of the most common boot arguments that are passed to the Linux kernel:
console=ttyAMA0- Specifies the console log level and deviceroot=/dev/vda- Specifies the root filesysteminitrd=initrd.img- Specifies the initial ramdisk imagedevtree=/path/to/device-tree- Specifies the device tree
$ qemu-system-arm -M versatilepb -m 128M -nographic -kernel vmlinux -append "console=ttyAMA0 root=/dev/vda initrd=initrd.img devtree=/path/to/device-tree"In this article, we covered how to pass boot arguments to a Linux kernel image using QEMU. This included an overview of QEMU, the Linux kernel image, and how to pass boot arguments using QEMU's -append option. We also provided some of the most common boot arguments that are passed to the Linux kernel.