Add drive support.

This commit is contained in:
Michael Lipp 2023-06-08 18:21:39 +02:00
parent 46c7e8c527
commit 72361f4171
3 changed files with 39 additions and 20 deletions

View file

@ -77,11 +77,14 @@
# "device": "virtio-net" # "device": "virtio-net"
# "mac": (undefined) # "mac": (undefined)
# There are no default drives. The supported types are "ide-cd"
"drives": # and "raw". All types support a "bootindex" property.
- "type": "ide-cd" # Type "raw" can have a property "file" (if backed by a file on
"bootindex": (undefined) # the host) or a property "device" (if backed by a device).
"file": (undefined) # "drives":
# - "type": "ide-cd"
# "bootindex": (undefined)
# "file": (undefined)
# "spice": # "spice":
# "port": 5900 # "port": 5900

View file

@ -89,6 +89,7 @@ class Configuration implements Dto {
public static class Drive implements Dto { public static class Drive implements Dto {
public String type; public String type;
public Integer bootindex; public Integer bootindex;
public String device;
public String file; public String file;
} }

View file

@ -50,10 +50,6 @@
# * https://bugzilla.redhat.com/show_bug.cgi?id=1170533, may be unnecessary # * https://bugzilla.redhat.com/show_bug.cgi?id=1170533, may be unnecessary
- [ "-global", "ICH9-LPC.disable_s3=1" ] - [ "-global", "ICH9-LPC.disable_s3=1" ]
- [ "-global", "ICH9-LPC.disable_s4=1" ] - [ "-global", "ICH9-LPC.disable_s4=1" ]
# {{- if .Values.vm.secureBoot }}
# -global driver=cfi.pflash01,property=secure,value=on
# -object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/var/local/qemu/master-key.aes"}'
# {{- end }}
<#if firmwareRom??> <#if firmwareRom??>
# * Provide ROM/EEPROM devices (instead of built-in BIOS) # * Provide ROM/EEPROM devices (instead of built-in BIOS)
- [ "-blockdev", "node-name=fw-rom-file,driver=file,cache.direct=on,\ - [ "-blockdev", "node-name=fw-rom-file,driver=file,cache.direct=on,\
@ -65,7 +61,9 @@
- [ "-blockdev", "node-name=fw-eeprom-device,driver=raw,\ - [ "-blockdev", "node-name=fw-eeprom-device,driver=raw,\
read-only=false,file=fw-eeprom-file" ] read-only=false,file=fw-eeprom-file" ]
</#if> </#if>
# * Driver tuning for secure boot
# https://wiki.debian.org/SecureBoot/VirtualMachine # https://wiki.debian.org/SecureBoot/VirtualMachine
# http://www.linux-kvm.org/downloads/lersek/ovmf-whitepaper-c770f8c.txt
<#if vm.firmware?starts_with("secure")> <#if vm.firmware?starts_with("secure")>
- [ "-global", "driver=cfi.pflash01,property=secure,value=on" ] - [ "-global", "driver=cfi.pflash01,property=secure,value=on" ]
</#if> </#if>
@ -115,6 +113,7 @@
- [ "-object", "rng-random,id=objrng0,filename=/dev/random" ] - [ "-object", "rng-random,id=objrng0,filename=/dev/random" ]
- [ "-device", "virtio-rng-pci,rng=objrng0,id=rng0" ] - [ "-device", "virtio-rng-pci,rng=objrng0,id=rng0" ]
# * Graphics and Audio Card # * Graphics and Audio Card
# This is the only video "card" without a flickering cursor.
- [ "-device", "virtio-vga,id=video0,max_outputs=1" ] - [ "-device", "virtio-vga,id=video0,max_outputs=1" ]
- [ "-device", "ich9-intel-hda,id=sound0" ] - [ "-device", "ich9-intel-hda,id=sound0" ]
# Network # Network
@ -139,7 +138,7 @@
# * CD-Drives # * CD-Drives
<#assign cdCounter = 0/> <#assign cdCounter = 0/>
<#list vm.drives![] as drive> <#list vm.drives![] as drive>
<#if (drive.type!"hdd") == "ide-cd"> <#if (drive.type!"") == "ide-cd">
- [ "-drive", "id=drive-cdrom${ cdCounter },if=none,media=cdrom,cache=none\ - [ "-drive", "id=drive-cdrom${ cdCounter },if=none,media=cdrom,cache=none\
<#if drive.file??>,file=${ drive.file }</#if>" ] <#if drive.file??>,file=${ drive.file }</#if>" ]
# (IDE is old, but faster than usb-storage. virtio-blk-pci does not # (IDE is old, but faster than usb-storage. virtio-blk-pci does not
@ -149,16 +148,32 @@
<#assign cdCounter += 1/> <#assign cdCounter += 1/>
</#if> </#if>
</#list> </#list>
# * Disks
# - how to access the resource on the host (a file) <#assign drvCounter = 0/>
# - [ "-blockdev", "node-name=blockdev-cdrom-file,driver=file,\ <#list vm.drives![] as drive>
# filename=/home/mnl/Downloads/archlinux-2023.05.03-x86_64.iso" ] <#switch (drive.type!"raw")>
<#case "raw">
# - how to access the resource on the host (a file or a block device)
<#if drive.file??>
- [ "-blockdev", "node-name=drive-${ drvCounter }-host-resource,\
driver=file,filename=${ drive.file }" ]
</#if>
<#if drive.device??>
- [ "-blockdev", "node-name=drive-${ drvCounter }-host-resource,\
driver=host_device,filename=${ drive.device },\
aio=native,cache.direct=on,cache.no-flush=off,\
auto-read-only=true,discard=unmap" ]
</#if>
# - how to use the file (as sequence of literal blocks) # - how to use the file (as sequence of literal blocks)
# - [ "-blockdev", "node-name=blockdev-cdrom-backend,driver=raw,\ - [ "-blockdev", "node-name=drive-${ drvCounter }-backend,driver=raw,\
# read-only=true,file=blockdev-cdrom-file" ] file=drive-${ drvCounter }-host-resource" ]
# - the driver (what the guest sees) # - the driver (what the guest sees)
# - [ "-device", "virtio-blk-pci,id=virtio-disk-cdrom,\ - [ "-device", "virtio-blk-pci,drive=drive-${ drvCounter }-backend\
# drive=blockdev-cdrom-backend,bootindex=1" ] <#if drive.bootindex??>,bootindex=${ drive.bootindex }</#if>" ]
<#assign drvCounter += 1/>
<#break>
</#switch>
</#list>
# SPICE (display, channels ...) # SPICE (display, channels ...)
# https://www.linux-kvm.org/page/SPICE # https://www.linux-kvm.org/page/SPICE