Improve qemu cmdline#5540
Conversation
From the qemu docs we know that the old arguments are not encouraged: "Older options like -hda are essentially macros which expand into -drive options for various drive interfaces. The original forms bake in a lot of assumptions from the days when QEMU was emulating a legacy PC, they are not recommended for modern configurations." Also by not specifying the format we get warnings like: WARNING: Image format was not specified for 'seed.img' and probing guessed raw. These warnings might one day get more aggressive and so might be the use of -hda. Instead let us avoid the current and the potential future by using the new format which is a bit more verbose, but also more correct.
The default acceleration is still tcg, which is slower than kvm. We can ask qemu to try kvm and only fall back to tcg - allowing many users to get this example done faster. By default /dev/kvm is only for root or group kvm, to make the example not more complex by adding group management we could instead increase the chance that kvm works by prepending sudo. Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
We do not want to focus on performance too much, rather on compatibility. Hence: - remove sudo as not all might be able to do that even if it increases the chance to use kvm - remove -cpu host as it would not work on TCG emulation from other architectures - drop machine ubuntu to work on non ubuntu systems Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
We discussed and decided to keep the examples rather compatible. But at the same time that means on non x86 it might work, but be a bit slower. To help people on other architectures we now hint how they could execute natively. Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
| .. note:: | ||
| Please be aware, the example is written for x86. It works on non-x86 but | ||
| is slower as it will need to be emulated. You can change the image type and | ||
| qemu-system-<arch> command name to match your architecture to make it again |
There was a problem hiding this comment.
| qemu-system-<arch> command name to match your architecture to make it again | |
| qemu-system-<arch> command name to match your architecture to make it |
|
|
||
| wget https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img | ||
|
|
||
| .. note:: |
There was a problem hiding this comment.
Since this is already in a note, the "Please be aware" seems redundant.
is written for x86.
Correct, but this seems like unnecessary information.
Perhaps:
This example uses emulated CPU instructions on non-x86 hosts, so it may be slow. To make it faster on non-x86 architectures, one can change the image type and qemu-system- command name to match the architecture of your host machine.
There was a problem hiding this comment.
pulled in a laid down this note suggestion for inclusion prior to merge.
| $ wget https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img | ||
|
|
||
| .. note:: | ||
| Please be aware, the example is written for x86. It works on non-x86 but |
There was a problem hiding this comment.
Same comments as above, however the this is a tutorial, not an example, so suggest a one-word change over the previous suggestion:
This tutorial uses emulated CPU instructions on non-x86 hosts, so it may be slow. To make it faster on non-x86 architectures, one can change the image type and qemu-system- command name to match the architecture of your host machine.
|
|
||
| wget https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img | ||
|
|
||
| .. note:: |
| orndorffgrant | ||
| Oursin | ||
| outscale-mdr | ||
| cpaelzer |
There was a problem hiding this comment.
WAIT WHAT NO WAY THIS IS YOUR FIRST PR
There was a problem hiding this comment.
Nope just wasn't pulled into our tools/.github-cla-signers.
First commit eeabe2e
| -hdb seed.img | ||
| -drive file=jammy-server-cloudimg-amd64.img,index=0,format=qcow2,media=disk \ | ||
| -drive file=seed.img,index=1,media=cdrom \ | ||
| -machine accel=kvm:tcg |
There was a problem hiding this comment.
is there any benefit to explaining what each of the various args passed are?
i feel like that might be out of scope for this since this is just cloud-init specific docs.
There was a problem hiding this comment.
such as:
Explanation
qemu-system-x86_64
- Emulates a 64-bit x86 machine.
-m 1024
- Allocates 1024 MB of RAM to the VM.
-net nic
- Adds a network interface card to the VM.
-net user
- Uses QEMU's user mode networking for basic network connectivity.
-hda jammy-server-cloudimg-amd64.img
- Sets the primary hard disk using the specified image.
-hdb seed.img
- Sets the secondary hard disk using the specified image, often for cloud-init data.
-drive file=jammy-server-cloudimg-amd64.img,index=0,format=qcow2,media=disk
- Specifies the primary drive in detail:
file: Image file to use.index: Drive index (0 for primary).format: Image format (QCOW2).media: Type of drive (disk).
-drive file=seed.img,index=1,media=cdrom
- Specifies the secondary drive in detail:
file: Image file to use.index: Drive index (1 for secondary).media: Type of drive (CD-ROM).
-machine accel=kvm:tcg
- Uses KVM for hardware acceleration if available, otherwise TCG for software emulation.
There was a problem hiding this comment.
Yes, I think this is probably out of scope for this tutorial to tell folks how to use QEMU command line and it probably should be left as an exercise to the user to RTFM to better understand the implications of qemu commandline in this example.
064759e to
42292c8
Compare
blackboxsw
left a comment
There was a problem hiding this comment.
Minor spelling hint to avoid tox -e doc-spelling bailing on a word we don't need in our dictionary.
| .. note:: | ||
| Please be aware, the example is written for x86. It works on non-x86 but | ||
| is slower as it will need to be emulated. You can change the image type and | ||
| qemu-system-<arch> command name to match your architecture to make it again |
There was a problem hiding this comment.
spelling issues on qemu-system not being seen, we need the following in both places:
| qemu-system-<arch> command name to match your architecture to make it again | |
| :spelling:ignore:`qemu-system-<arch>` command name to match your architecture to make it again |
|
|
||
| wget https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img | ||
|
|
||
| .. note:: |
There was a problem hiding this comment.
pulled in a laid down this note suggestion for inclusion prior to merge.
4c58f45 to
2406de5
Compare
Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
2406de5 to
3352e66
Compare
The suggested qemu command line in our local execution example is rather old. Change the discouraged -hd* options to the new -device instead. Further add a chance to use KVM acceleration to speed up the example. Finally we had several occasions to be working on x86 only. We dropped arguments that can not work on cross-arch and furthermore added a hint at how one could again native performance on these platforms. Fixes canonicalGH-5050
The suggested qemu command line in our local execution example is rather old. Change the discouraged -hd* options to the new -device instead. Further add a chance to use KVM acceleration to speed up the example. Finally we had several occasions to be working on x86 only. We dropped arguments that can not work on cross-arch and furthermore added a hint at how one could again native performance on these platforms. Fixes GH-5050
tools/.github-cla-signerstests/unittests/Proposed Commit Message
Additional Context
n/a
Test Steps
Use the "How to run cloud-init locally" example
Merge type