Skip to content

run_qemu.sh: fix --rw option just broken by switch to -blockdev #213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion parser_generator.m4
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ exit 11 #)Created by argbash-init v2.9.0
# ARG_OPTIONAL_BOOLEAN([gdb], , [Wait for gdb to connect for kernel debug (port 10000)], )
# ARG_OPTIONAL_BOOLEAN([gdb-qemu], , [Start qemu with gdb], )
# ARG_OPTIONAL_BOOLEAN([qmp], , [Invokes QEMU with -qmp which opens a QMP control socket at unix:/tmp/run_qemu_qmp. Using that socket requires the 'qmp-shell' script.\nWhen needed, run_qemu.sh can find qmp-shell either in the PATH, or in scripts/qmp/ in the qemu source when using --git-qemu.\nThe official qemu.qmp package is available on PyPI.], )
# ARG_OPTIONAL_BOOLEAN([rw], , [Make guest image writeable (remove -snapshot)\n (Note that an image rebuild will lose any changes made via --rw)], )
# ARG_OPTIONAL_BOOLEAN([rw], , [Persist run-time image changes for the next cold boot.\nA reboot does not lose changes; for persistency a reboot is a non-event.\nNote that an image rebuild will always reset any changes made via --rw]\n, )
# ARG_OPTIONAL_BOOLEAN([curses], , [Default display is -nographic. switch to -curses instead with this option.\n Use Esc+1, Esc+2, etc. to switch between the different screens.\n 'q' in the monitor screen to quit], )
# ARG_OPTIONAL_BOOLEAN([git-qemu], [g], [Use a qemu tree at '~/git/qemu/' for qemu binaries.\n This overrides any qemu=<foo> setting from the env.], )
# ARG_OPTIONAL_BOOLEAN([nfit-test], , [Setup an environment for unit tests\n - include libnvdimm 'extra' modules\n - add some memmap reserved memory\n Note: --rebuild=img or higher required when switching either to or away from nfit-test.\n This overrides any supplied 'preset' or topology options and forces preset=med], )
Expand Down
14 changes: 13 additions & 1 deletion run_qemu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1862,7 +1862,18 @@ prepare_qcmd()
;;
esac

qcmd+=("-blockdev" "driver=file,node-name=maindisk,filename=$_arg_rootfs")
if [[ $_arg_rw == 'on' ]]; then
qcmd+=("-blockdev" "driver=file,node-name=maindisk,filename=${_arg_rootfs}")
else
local _overlay=${_arg_rootfs}-overlay.qcow2
rm -f "${_overlay}"
qemu-img create -F raw -b "${_arg_rootfs}" -f qcow2 "${_overlay}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity, is there a way to 'apply' the overlay onto the raw image?

A workflow I've used in the past is to create an image using run_qemu with my kernel and anything else I need, and then use that raw image elsewhere, say an emulator or even dd it to a drive and use it on a real system. I'm not sure if something like this is frequently used/needed by others, but these changes (starting with -blockdev) would preclude doing this..

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way to 'apply' the overlay onto the raw image?

You can "apply" and many other things using qemu-img but I think that's out of scope for run_qemu.sh. I mean, run_qemu.sh is already a wrapper of many other tools, I don't think we should add qemu-img to that long list.

The overlay is left behind (until the next run) so anyone is free to change their mind and apply it outside run_qemu.sh.

but these changes (starting with -blockdev) would preclude doing this..

This PR is designed to fix --rw which I just broke and bring it back exactly where it was. I don't see what it would preclude, can you elaborate? If nothing else I feel like it's opening more possibilities, including... becoming a qemu-img wrapper, which I think is not a good idea.

Copy link
Member

@stellarhopper stellarhopper Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes I was not suggesting run_qemu should grow to provide this apply overlay functionality. More that if we ever wanted to do this kind of an "export a customized image" workflow, there was still /some/ way to accomplish that with the overlay. No issues merging this by me!

# "Finding your way through the QEMU parameter jungle"
# -- Thomas Huth
qcmd+=("-blockdev" "file,node-name=mainoverlay,filename=${_overlay}")
qcmd+=("-blockdev" "qcow2,node-name=maindisk,file=mainoverlay")
fi

qcmd+=("-device" "virtio-blk,bus=pcie.0,drive=maindisk")

if [ $_arg_direct_kernel = "on" ] && [ -n "$vmlinuz" ] && [ -n "$initrd" ]; then
Expand Down Expand Up @@ -1903,6 +1914,7 @@ prepare_qcmd()
fi

if [[ $_arg_rw == "off" ]]; then
# Note this is only for the (deprecated) -drive and ignored by -blockdev
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to just remove this block - considering we've fully moved away from -drive..

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still use -drive in a couple other places.

qcmd+=("-snapshot")
fi

Expand Down