]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Add a new QemuRemovable option to allow attaching the image to qemu as removable
authorPaul Wicks <pwicks86@gmail.com>
Wed, 9 Oct 2024 23:25:32 +0000 (16:25 -0700)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 10 Oct 2024 20:07:58 +0000 (22:07 +0200)
Add noqa for overlength line

Fix failing test

Rewrap QemuRemovable section on the man page to column 109

mkosi/config.py
mkosi/qemu.py
mkosi/resources/man/mkosi.1.md
tests/test_json.py

index ec827622561354f4e458bc771270a840837f6182..ff420dc490f59c726765e9bcdd66dc2b074f0195 100644 (file)
@@ -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",
index 01d2b5945c515c1c7cebe3ffbcd1bdfb6f5c36a6..00e283531a195525e828855f11883f877790296a 100644 (file)
@@ -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 (
index 41c2ac5a35dc09759dca1f5c390f50a5e94944dc..30f3c4efc1d04edcd3edc0088eea9dca34094049 100644 (file)
@@ -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
index 3b3375576a2c939e25b22e665e0f5276949b3bbd..3b64356d01144e65950be398a7d131bafd10fe17 100644 (file)
@@ -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"),