Commands that just work
To make absolutely sure that it will work, we can make Buildroot build QEMU for us, and use the exact QEMU CLI provided by Buildroot at: https://github.com/buildroot/buildroot/blob/2019.05/board/qemu/x86_64/readme.txt
git clone https://github.com/buildroot/buildroot
cd buildroot
git checkout 2019.05
make qemu_x86_64_defconfig
printf '
BR2_CCACHE=y
BR2_PACKAGE_HOST_QEMU=y
BR2_PACKAGE_HOST_QEMU_LINUX_USER_MODE=n
BR2_PACKAGE_HOST_QEMU_SYSTEM_MODE=y
BR2_PACKAGE_HOST_QEMU_VDE2=y
' >> .config
make olddefconfig
time make BR2_JLEVEL="$(nproc)" HOST_QEMU_OPTS='--enable-sdl --with-sdlabi=2.0'
./output/host/bin/qemu-system-x86_64 \
-M pc \
-kernel output/images/bzImage \
-drive file=output/images/rootfs.ext2,if=virtio,format=raw \
-append "rootwait root=/dev/vda" \
-net nic,model=virtio \
-net user \
;
You are now left on a shell and you can login with username root
(no password).

Note however that the default Buildroot build does not have an interesting GUI like X11 by default, as that is not the most common use case for this project. I have covered that at: How to install X11 on my own Linux Buildroot system?
But because Buildroot does not focus enough on the run part to my needs (more automation, more boot types, GDB step debug), I extended it with some extra scripts on this project: https://github.com/cirosantilli/linux-kernel-module-cheat
Other ISAs mentioned at: https://cirosantilli.com/linux-kernel-module-cheat/#buildroot-hello-world
Buildroot 2019.08 QEMU build failed because QEMU 3.1.1 release has a broken x86_64 build... QEMU 3.1.1 failed to build
Tested in Ubuntu 19.04.
-append
as an option to qemu if your kernel has no default parameters, e.g. you should at least specify the root partition. – Ulrich Dangel Jul 26 '12 at 19:42rootfs.ext2
is the image from filesystem while you are passing it as a disk image. (it does not contain partition table and MBR). The correct command must be something like:qemu-system-i386 -kernel vmlinux file=rootfs.ext2,format=raw -m 256
– sorush-r Jul 31 '21 at 18:06