Skip to content

Instantly share code, notes, and snippets.

@aconz2
Last active July 9, 2024 21:27
Show Gist options
  • Save aconz2/62148f6c5a93f2f62be51723c13bb5d8 to your computer and use it in GitHub Desktop.
Save aconz2/62148f6c5a93f2f62be51723c13bb5d8 to your computer and use it in GitHub Desktop.
qemu fedora cloud explicit kernel and initrd learnings
# download fedora cloud qcow2 image
wget https://download.fedoraproject.org/pub/fedora/linux/releases/40/Cloud/x86_64/images/Fedora-Cloud-Base-Generic.x86_64-40-1.14.qcow2
# set root password to hello
virt-customize -a Fedora-Cloud-Base-Generic.x86_64-40-1.14.qcow2 --root-password password:hello
# this extracts the kernel binary and initramfs from the qcow2 image
# this lets you pass custom kernel parameters, qemu requires passing -kernel in order to use -append
# https://www.kernel.org/doc/html/latest/admin-guide/kernel-parameters.html
virt-get-kernel -a Fedora-Cloud-Base-Generic.x86_64-40-1.14.qcow2
file vmlinuz-6.8.5-301.fc40.x86_64
file initramfs-6.8.5-301.fc40.x86_64.img
# look at what the default parameters are. notice that rootflags (which configures the mount for the root= param) has a subvol=root
# this is because this image uses btrfs subvolumes and the one for root is called root
virt-cat -a Fedora-Cloud-Base-Generic.x86_64-40-1.14.qcow2 /etc/default/grub
# GRUB_CMDLINE_LINUX_DEFAULT="no_timer_check net.ifnames=0 console=tty1 console=ttyS0,115200n8 rootflags=subvol=root"
# we can run it like this
# note that the disk is on /dev/vda where the v is for virtualized disk
# and vda4 is the 4th partition of filesystem type btrfs which has three subvolumes, root, home, and var
# when I was playing with this and getting dropped into the emergency shell `cat /proc/mounts` and `blkid` were helpful
qemu-system-x86_64 \
-enable-kvm \
-cpu host -smp 2 \
-m 1G \
-kernel vmlinuz-6.8.5-301.fc40.x86_64 -append "root=/dev/vda4 rootflags=subvol=root" \
-initrd initramfs-6.8.5-301.fc40.x86_64.img \
-device virtio-blk-pci,drive=test \
-drive id=test,file=Fedora-Cloud-Base-Generic.x86_64-40-1.14.qcow2,format=qcow2,if=none
# this is essentially the same as
qemu-system-x86_64 -enable-kvm -cpu host -smp 4 -m 1G -drive file=Fedora-Cloud-Base-Generic.x86_64-40-1.14.qcow2
# there might be some speed difference in having things extracted from qcow2?
qemu-img convert Fedora-Cloud-Base-Generic.x86_64-40-1.14.qcow2 Fedora-Cloud-Base-Generic.x86_64-40-1.14.raw
# and then can run with
# ...
# -drive id=test,file=Fedora-Cloud-Base-Generic.x86_64-40-1.14.raw,format=raw,if=none
# there isn't really a point to this, just writing some notes down
# this gets nographic working where the boot console is stdio
qemu-system-x86_64 \
-enable-kvm \
-cpu host -smp 4 \
-m 1G \
-kernel vmlinuz-6.8.5-301.fc40.x86_64 -append "root=/dev/vda4 console=ttyS0 rootflags=subvol=root" \
-initrd initramfs-6.8.5-301.fc40.x86_64.img \
-device virtio-blk-pci,drive=test \
-drive id=test,file=fedora-cloud-base.raw,format=raw,if=none \
-nodefaults -no-user-config -nographic \
-serial stdio
# this gets microvm machine type working
qemu-system-x86_64 \
-M microvm \
-nodefaults -no-user-config -nographic \
-enable-kvm \
-cpu host -smp 4 -m 1G \
-kernel vmlinuz-6.8.5-301.fc40.x86_64 -append "root=/dev/vda4 console=hvc0 rootflags=subvol=root" \
-initrd initramfs-6.8.5-301.fc40.x86_64.img \
-device virtio-blk-device,drive=test \
-drive id=test,file=fedora-cloud-base.raw,format=raw,if=none \
-chardev stdio,id=virtiocon0 \
-device virtio-serial-device \
-device virtconsole,chardev=virtiocon0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment