mirror of
				https://github.com/oSoWoSo/DistroHopper.git
				synced 2024-08-14 22:46:53 +00:00 
			
		
		
		
	Refactor qemu launcher
Disks, network device, Smartcard and USB pass-through are exported platform specific variables then composed in a single launcher.
This commit is contained in:
		
							parent
							
								
									bf69f54d74
								
							
						
					
					
						commit
						f18d8e994e
					
				
					 1 changed files with 86 additions and 91 deletions
				
			
		
							
								
								
									
										177
									
								
								quickemu
									
										
									
									
									
								
							
							
						
						
									
										177
									
								
								quickemu
									
										
									
									
									
								
							|  | @ -441,99 +441,94 @@ function vm_boot() { | ||||||
| 
 | 
 | ||||||
|   enable_usb_passthrough |   enable_usb_passthrough | ||||||
| 
 | 
 | ||||||
|   # Boot the iso image |   # Build the VM configuration | ||||||
|   if [ "${boot}" == "efi" ] || [ "${boot}" == "uefi" ]; then |   local DISKS="" | ||||||
|     if [ "${guest_os}" == "macos" ]; then |   local NET_DEVICE="" | ||||||
|       if [ -z "${img}" ]; then |   local SMARTCARD="" | ||||||
|         ${QEMU} \ |   local USB_HOSTPASS="" | ||||||
|           -name ${VMNAME},process=${VMNAME} \ |   local USB_SPICEPASS="" | ||||||
|           -enable-kvm -machine q35 ${GUEST_TWEAKS} \ | 
 | ||||||
|           ${CPU} ${SMP} \ |   if [ "${guest_os}" == "macos" ]; then | ||||||
|           -m ${RAM_VM} -device virtio-balloon \ |     DISKS="-drive if=pflash,format=raw,readonly=on,file=${EFI_CODE} | ||||||
|           -drive if=pflash,format=raw,readonly=on,file="${EFI_CODE}" \ |     -drive if=pflash,format=raw,file=${EFI_VARS} | ||||||
|           -drive if=pflash,format=raw,file="${EFI_VARS}" \ |     -drive id=ESP,cache=directsync,aio=native,if=none,format=qcow2,file=${VMDIR}/ESP.qcow2" | ||||||
|           -drive id=ESP,cache=directsync,aio=native,if=none,format=qcow2,file="${VMDIR}/ESP.qcow2" \ |     if [ -n "${img}" ]; then | ||||||
|           -device virtio-blk-pci,drive=ESP,scsi=off \ |       DISKS="${DISKS} | ||||||
|           -drive id=SystemDisk,cache=directsync,aio=native,if=none,format=qcow2,file="${disk_img}" ${STATUS_QUO} \ |       -drive id=InstallMedia,cache=directsync,aio=native,if=none,format=raw,readonly=on,file=${img} | ||||||
|           -device virtio-blk-pci,drive=SystemDisk,scsi=off \ |       -device virtio-blk-pci,drive=InstallMedia,scsi=off" | ||||||
|           ${VIDEO} -display ${OUTPUT},gl=${GL}${OUTPUT_EXTRA} \ |  | ||||||
|           -device usb-ehci,id=usb -device usb-kbd,bus=usb.0 -device usb-tablet,bus=usb.0 ${USB_PASSTHROUGH} \ |  | ||||||
|           -device vmxnet3,netdev=nic -netdev ${NET},id=nic \ |  | ||||||
|           -audiodev pa,id=pa,server=unix:${XDG_RUNTIME_DIR}/pulse/native,out.stream-name=${LAUNCHER}-${VMNAME},in.stream-name=${LAUNCHER}-${VMNAME} \ |  | ||||||
|           -device intel-hda -device hda-duplex,audiodev=pa,mixer=off \ |  | ||||||
|           -rtc base=localtime,clock=host \ |  | ||||||
|           -serial mon:stdio |  | ||||||
|       else |  | ||||||
|         ${QEMU} \ |  | ||||||
|           -name ${VMNAME},process=${VMNAME} \ |  | ||||||
|           -enable-kvm -machine q35 ${GUEST_TWEAKS} \ |  | ||||||
|           ${CPU} ${SMP} \ |  | ||||||
|           -m ${RAM_VM} -device virtio-balloon \ |  | ||||||
|           -drive if=pflash,format=raw,readonly=on,file="${EFI_CODE}" \ |  | ||||||
|           -drive if=pflash,format=raw,file="${EFI_VARS}" \ |  | ||||||
|           -drive id=ESP,cache=directsync,aio=native,if=none,format=qcow2,file="${VMDIR}/ESP.qcow2" \ |  | ||||||
|           -device virtio-blk-pci,drive=ESP,scsi=off \ |  | ||||||
|           -drive id=InstallMedia,cache=directsync,aio=native,if=none,format=raw,readonly=on,file="${img}" \ |  | ||||||
|           -device virtio-blk-pci,drive=InstallMedia,scsi=off \ |  | ||||||
|           -drive id=SystemDisk,cache=directsync,aio=native,if=none,format=qcow2,file="${disk_img}" ${STATUS_QUO} \ |  | ||||||
|           -device virtio-blk-pci,drive=SystemDisk,scsi=off \ |  | ||||||
|           ${VIDEO} -display ${OUTPUT},gl=${GL}${OUTPUT_EXTRA} \ |  | ||||||
|           -device usb-ehci,id=usb -device usb-kbd,bus=usb.0 -device usb-tablet,bus=usb.0 ${USB_PASSTHROUGH} \ |  | ||||||
|           -device vmxnet3,netdev=nic -netdev ${NET},id=nic \ |  | ||||||
|           -audiodev pa,id=pa,server=unix:${XDG_RUNTIME_DIR}/pulse/native,out.stream-name=${LAUNCHER}-${VMNAME},in.stream-name=${LAUNCHER}-${VMNAME} \ |  | ||||||
|           -device intel-hda -device hda-duplex,audiodev=pa,mixer=off \ |  | ||||||
|           -rtc base=localtime,clock=host \ |  | ||||||
|           -serial mon:stdio |  | ||||||
|       fi |  | ||||||
|     else |  | ||||||
|       ${QEMU} \ |  | ||||||
|         -name ${VMNAME},process=${VMNAME} \ |  | ||||||
|         -enable-kvm -machine q35 ${GUEST_TWEAKS} \ |  | ||||||
|         ${CPU} ${SMP} \ |  | ||||||
|         -m ${RAM_VM} -device virtio-balloon \ |  | ||||||
|         -drive if=pflash,format=raw,readonly=on,file="${EFI_CODE}" \ |  | ||||||
|         -drive if=pflash,format=raw,file="${EFI_VARS}" \ |  | ||||||
|         -drive media=cdrom,index=0,file="${iso}" \ |  | ||||||
|         -drive media=cdrom,index=1,file="${driver_iso}" \ |  | ||||||
|         -drive if=none,id=drive0,cache=directsync,aio=native,format=qcow2,file="${disk_img}" \ |  | ||||||
|         -device virtio-blk-pci,drive=drive0,scsi=off ${STATUS_QUO} \ |  | ||||||
|         ${VIDEO} -display ${OUTPUT},gl=${GL}${OUTPUT_EXTRA} \ |  | ||||||
|         -device qemu-xhci,id=usb,p2=8,p3=8 -device usb-kbd,bus=usb.0 -device usb-tablet,bus=usb.0 ${USB_PASSTHROUGH} \ |  | ||||||
|         -device virtio-net,netdev=nic -netdev ${NET},id=nic \ |  | ||||||
|         -audiodev pa,id=pa,server=unix:${XDG_RUNTIME_DIR}/pulse/native,out.stream-name=${LAUNCHER}-${VMNAME},in.stream-name=${LAUNCHER}-${VMNAME} \ |  | ||||||
|         -device intel-hda -device hda-duplex,audiodev=pa,mixer=off \ |  | ||||||
|         -rtc base=localtime,clock=host \ |  | ||||||
|         -object rng-random,id=rng0,filename=/dev/urandom \ |  | ||||||
|         -device virtio-rng-pci,rng=rng0 \ |  | ||||||
|         -spice port=${SPICE_PORT},disable-ticketing=on \ |  | ||||||
|         -device virtio-serial-pci \ |  | ||||||
|         -device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 \ |  | ||||||
|         -chardev spicevmc,id=spicechannel0,name=vdagent \ |  | ||||||
|         -serial mon:stdio |  | ||||||
|     fi |     fi | ||||||
|  |     DISKS="${DISKS} | ||||||
|  |     -device virtio-blk-pci,drive=ESP,scsi=off | ||||||
|  |     -drive id=SystemDisk,cache=directsync,aio=native,if=none,format=qcow2,file=${disk_img} ${STATUS_QUO} | ||||||
|  |     -device virtio-blk-pci,drive=SystemDisk,scsi=off" | ||||||
|  |     NET_DEVICE="vmxnet3" | ||||||
|  |     # UNTESTED! USB2 passthrough since USB3 isn't(?) supported in macOS VMs | ||||||
|  |     # USB_SPICEPASS=" | ||||||
|  |     # -device usb-ehci,id=spicepass | ||||||
|  |     # -device ich9-usb-uhci1,masterbus=spicepass.0,firstport=0,multifunction=on | ||||||
|  |     # -device ich9-usb-uhci2,masterbus=spicepass.0,firstport=2 | ||||||
|  |     # -device ich9-usb-uhci3,masterbus=spicepass.0,firstport=4 | ||||||
|  |     # -chardev spicevmc,name=usbredir,id=usbredirchardev1 | ||||||
|  |     # -device usb-redir,chardev=usbredirchardev1,id=usbredirdev1 | ||||||
|  |     # -chardev spicevmc,name=usbredir,id=usbredirchardev2 | ||||||
|  |     # -device usb-redir,chardev=usbredirchardev2,id=usbredirdev2 | ||||||
|  |     # -chardev spicevmc,name=usbredir,id=usbredirchardev3 | ||||||
|  |     # -device usb-redir,chardev=usbredirchardev3,id=usbredirdev3" | ||||||
|  |     USB_HOSTPASS="-device usb-ehci,id=hostpass | ||||||
|  |     ${USB_PASSTHROUGH}" | ||||||
|   else |   else | ||||||
|     ${QEMU} \ |     if [ "${boot}" == "efi" ] || [ "${boot}" == "uefi" ]; then | ||||||
|       -name ${VMNAME},process=${VMNAME} \ |       DISKS="-drive if=pflash,format=raw,readonly=on,file=${EFI_CODE} | ||||||
|       -enable-kvm -machine q35 ${GUEST_TWEAKS} \ |       -drive if=pflash,format=raw,file=${EFI_VARS}" | ||||||
|       ${CPU} ${SMP} \ |     fi | ||||||
|       -m ${RAM_VM} -device virtio-balloon \ |     DISKS="${DISKS} | ||||||
|       -drive media=cdrom,index=0,file="${iso}" \ |     -drive media=cdrom,index=0,file=${iso} | ||||||
|       -drive media=cdrom,index=1,file="${driver_iso}" \ |     -drive media=cdrom,index=1,file=${driver_iso} | ||||||
|       -drive if=none,id=drive0,cache=directsync,aio=native,format=qcow2,file="${disk_img}" \ |     -drive if=none,id=drive0,cache=directsync,aio=native,format=qcow2,file=${disk_img} | ||||||
|       -device virtio-blk-pci,drive=drive0,scsi=off ${STATUS_QUO} \ |     -device virtio-blk-pci,drive=drive0,scsi=off ${STATUS_QUO}" | ||||||
|       ${VIDEO} -display ${OUTPUT},gl=${GL}${OUTPUT_EXTRA} \ |     NET_DEVICE="virtio-net" | ||||||
|       -device qemu-xhci,id=usb,p2=8,p3=8 -device usb-kbd,bus=usb.0 -device usb-tablet,bus=usb.0 ${USB_PASSTHROUGH} \ |     SMARTCARD="-device usb-ccid | ||||||
|       -device virtio-net,netdev=nic -netdev ${NET},id=nic \ |     -chardev spicevmc,id=ccid,name=smartcard | ||||||
|       -audiodev pa,id=pa,server=unix:${XDG_RUNTIME_DIR}/pulse/native,out.stream-name=${LAUNCHER}-${VMNAME},in.stream-name=${LAUNCHER}-${VMNAME} \ |     -device ccid-card-passthru,chardev=ccid" | ||||||
|       -device intel-hda -device hda-duplex,audiodev=pa,mixer=off \ |     USB_SPICEPASS="-device qemu-xhci,id=spicepass | ||||||
|       -rtc base=localtime,clock=host \ |     -chardev spicevmc,id=usbredirchardev1,name=usbredir | ||||||
|       -object rng-random,id=rng0,filename=/dev/urandom \ |     -device usb-redir,chardev=usbredirchardev1,id=usbredirdev1 | ||||||
|       -device virtio-rng-pci,rng=rng0 \ |     -chardev spicevmc,id=usbredirchardev2,name=usbredir | ||||||
|       -spice port=${SPICE_PORT},disable-ticketing=on \ |     -device usb-redir,chardev=usbredirchardev2,id=usbredirdev2 | ||||||
|       -device virtio-serial-pci \ |     -chardev spicevmc,id=usbredirchardev3,name=usbredir | ||||||
|       -device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 \ |     -device usb-redir,chardev=usbredirchardev3,id=usbredirdev3" | ||||||
|       -chardev spicevmc,id=spicechannel0,name=vdagent \ |     USB_HOSTPASS="-device qemu-xhci,id=hostpass | ||||||
|       -serial mon:stdio |     ${USB_PASSTHROUGH}" | ||||||
|  |   fi | ||||||
|  | 
 | ||||||
|  |   # Boot the VM | ||||||
|  |   ${QEMU} \ | ||||||
|  |     -name ${VMNAME},process=${VMNAME} \ | ||||||
|  |     -enable-kvm -machine q35,vmport=off ${GUEST_TWEAKS} \ | ||||||
|  |     ${CPU} ${SMP} \ | ||||||
|  |     -m ${RAM_VM} -device virtio-balloon \ | ||||||
|  |     ${DISKS} \ | ||||||
|  |     ${VIDEO} -display ${OUTPUT} \ | ||||||
|  |     -device usb-ehci,id=input \ | ||||||
|  |     -device usb-kbd,bus=input.0 \ | ||||||
|  |     -device usb-tablet,bus=input.0 \ | ||||||
|  |     ${USB_SPICEPASS} \ | ||||||
|  |     ${USB_HOSTPASS} \ | ||||||
|  |     ${SMARTCARD} \ | ||||||
|  |     -device ${NET_DEVICE},netdev=nic -netdev ${NET},id=nic \ | ||||||
|  |     -audiodev pa,id=pa,out.stream-name=${LAUNCHER}-${VMNAME},in.stream-name=${LAUNCHER}-${VMNAME} \ | ||||||
|  |     -device intel-hda -device hda-duplex,audiodev=pa,mixer=off \ | ||||||
|  |     -rtc base=localtime,clock=host \ | ||||||
|  |     -object rng-random,id=rng0,filename=/dev/urandom \ | ||||||
|  |     -device virtio-rng-pci,rng=rng0 \ | ||||||
|  |     -spice ${SPICE} \ | ||||||
|  |     -device virtio-serial-pci \ | ||||||
|  |     -chardev spicevmc,id=vdagent0,name=vdagent \ | ||||||
|  |     -device virtserialport,chardev=vdagent0,name=com.redhat.spice.0 \ | ||||||
|  |     -device virtio-serial-pci \ | ||||||
|  |     -chardev spiceport,id=webdav0,name=org.spice-space.webdav.0 \ | ||||||
|  |     -device virtserialport,chardev=webdav0,name=org.spice-space.webdav.0 \ | ||||||
|  |     -serial mon:stdio > "${VMDIR}/${VMNAME}.log" & | ||||||
|   echo " - PID:      ${!}" |   echo " - PID:      ${!}" | ||||||
| 
 | 
 | ||||||
|   # If output is 'none' then SPICE was requested. |   # If output is 'none' then SPICE was requested. | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue