Skip to content

Commit

Permalink
Add a new QemuRemovable option to allow attaching the image to qemu a…
Browse files Browse the repository at this point in the history
…s removable
  • Loading branch information
pwicks86 committed Oct 9, 2024
1 parent 7b138bc commit e197c57
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
9 changes: 9 additions & 0 deletions mkosi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1736,6 +1736,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]
Expand Down Expand Up @@ -3419,6 +3420,14 @@ def parse_ini(path: Path, only_sections: Collection[str] = ()) -> Iterator[tuple
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",
Expand Down
2 changes: 1 addition & 1 deletion mkosi/qemu.py
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ def add_virtiofs_mount(
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 ''}",
] # fmt: skip

if config.qemu_swtpm == ConfigFeature.enabled or (
Expand Down
5 changes: 5 additions & 0 deletions mkosi/resources/man/mkosi.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,11 @@ 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
Expand Down
1 change: 1 addition & 0 deletions tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,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"),
Expand Down

0 comments on commit e197c57

Please sign in to comment.