From: Paul Wicks Date: Wed, 9 Oct 2024 23:25:32 +0000 (-0700) Subject: Add a new QemuRemovable option to allow attaching the image to qemu as removable X-Git-Tag: v25~221 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=13756ac3abc23b85c21bfdf9134a57a22ef6f6bd;p=thirdparty%2Fmkosi.git Add a new QemuRemovable option to allow attaching the image to qemu as removable Add noqa for overlength line Fix failing test Rewrap QemuRemovable section on the man page to column 109 --- diff --git a/mkosi/config.py b/mkosi/config.py index ec8276225..ff420dc49 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -1741,6 +1741,7 @@ class Config: qemu_vsock_cid: int qemu_swtpm: ConfigFeature qemu_cdrom: bool + qemu_removable: bool qemu_firmware: QemuFirmware qemu_firmware_variables: Optional[Path] qemu_kernel: Optional[Path] @@ -3428,6 +3429,14 @@ SETTINGS = ( parse=config_parse_boolean, help="Attach the image as a CD-ROM to the virtual machine", ), + ConfigSetting( + dest="qemu_removable", + metavar="BOOLEAN", + nargs="?", + section="Host", + parse=config_parse_boolean, + help="Attach the image as a removable drive to the virtual machine", + ), ConfigSetting( dest="qemu_firmware", section="Host", diff --git a/mkosi/qemu.py b/mkosi/qemu.py index 01d2b5945..00e283531 100644 --- a/mkosi/qemu.py +++ b/mkosi/qemu.py @@ -1282,7 +1282,7 @@ def run_qemu(args: Args, config: Config) -> None: cache = f"cache.writeback=on,cache.direct={yes_no(direct)},cache.no-flush={yes_no(ephemeral)},aio=io_uring" # noqa: E501 cmdline += [ "-drive", f"if=none,id=mkosi,file={fname},format=raw,discard=on,{cache}", - "-device", f"scsi-{'cd' if config.qemu_cdrom else 'hd'},drive=mkosi,bootindex=1", + "-device", f"scsi-{'cd' if config.qemu_cdrom else 'hd'},drive=mkosi,bootindex=1{',removable=on' if config.qemu_removable else ''}", # noqa: E501 ] # fmt: skip if config.qemu_swtpm == ConfigFeature.enabled or ( diff --git a/mkosi/resources/man/mkosi.1.md b/mkosi/resources/man/mkosi.1.md index 41c2ac5a3..30f3c4efc 100644 --- a/mkosi/resources/man/mkosi.1.md +++ b/mkosi/resources/man/mkosi.1.md @@ -1586,6 +1586,10 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`, attach the image to the virtual machine as a CD-ROM device. Takes a boolean. Defaults to `no`. +`QemuRemovable=`, `--qemu-removable=` +: When used with the `qemu` verb, this option specifies whether to attach the image to the virtual machine + as a removable device. Takes a boolean. Defaults to `no`. + `QemuFirmware=`, `--qemu-firmware=` : When used with the `qemu` verb, this option specifies which firmware to use. Takes one of `uefi`, `uefi-secure-boot`, `bios`, `linux`, or diff --git a/tests/test_json.py b/tests/test_json.py index 3b3375576..3b64356d0 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -260,6 +260,7 @@ def test_config() -> None: "QemuKernel": null, "QemuKvm": "auto", "QemuMem": 123, + "QemuRemovable": false, "QemuSmp": 2, "QemuSwtpm": "auto", "QemuVsock": "enabled", @@ -481,6 +482,7 @@ def test_config() -> None: proxy_url="https://my/proxy", qemu_args=[], qemu_cdrom=False, + qemu_removable=False, qemu_drives=[ QemuDrive("abc", 200, Path("/foo/bar"), "abc,qed", "red"), QemuDrive("abc", 200, None, "", "wcd"),