mirror of
				https://github.com/oSoWoSo/DistroHopper.git
				synced 2024-08-14 22:46:53 +00:00 
			
		
		
		
	Add USB pass-through support
I decided to not have `quickemu` create `udev` rules and apply them because I was cautious about permanently altering the system `udev` configuration. Instead the permissions of the requested USB devices are modified so that the invoking user has write permission; which will persist until next boot. All changes are clearly communicated.
This commit is contained in:
		
							parent
							
								
									e33886f43e
								
							
						
					
					
						commit
						ec67184925
					
				
					 1 changed files with 51 additions and 1 deletions
				
			
		
							
								
								
									
										52
									
								
								quickemu
									
										
									
									
									
								
							
							
						
						
									
										52
									
								
								quickemu
									
										
									
									
									
								
							|  | @ -86,10 +86,56 @@ function get_port() { | ||||||
|     done |     done | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | enable_usb_passthrough() { | ||||||
|  |   local DEVICE="" | ||||||
|  |   local USB_BUS="" | ||||||
|  |   local USB_DEV="" | ||||||
|  |   local USB_NAME="" | ||||||
|  |   local VENDOR_ID="" | ||||||
|  |   local PRODUCT_ID="" | ||||||
|  |   local TEMP_SCRIPT=$(mktemp) | ||||||
|  |   local EXEC_SCRIPT=0 | ||||||
|  | 
 | ||||||
|  |   # Have any USB devices been requested for pass-through? | ||||||
|  |   if (( ${#usb_devices[@]} )); then | ||||||
|  |     echo " - USB:      Device pass-through requested:" | ||||||
|  |     echo "#!/usr/bin/env bash" > "${TEMP_SCRIPT}" | ||||||
|  |     for DEVICE in "${usb_devices[@]}"; do | ||||||
|  |       VENDOR_ID=$(echo ${DEVICE} | cut -d':' -f1) | ||||||
|  |       PRODUCT_ID=$(echo ${DEVICE} | cut -d':' -f2) | ||||||
|  |       USB_BUS=$(lsusb -d ${VENDOR_ID}:${PRODUCT_ID} | cut -d' ' -f2) | ||||||
|  |       USB_DEV=$(lsusb -d ${VENDOR_ID}:${PRODUCT_ID} | cut -d' ' -f4 | cut -d':' -f1) | ||||||
|  |       USB_NAME=$(lsusb -d ${VENDOR_ID}:${PRODUCT_ID} | cut -d' ' -f7-) | ||||||
|  |       echo "              - ${USB_NAME}" | ||||||
|  |       USB_PASSTHROUGH="${USB_PASSTHROUGH} -usb -device usb-host,vendorid=0x${VENDOR_ID},productid=0x${PRODUCT_ID}" | ||||||
|  |        | ||||||
|  |       if [ ! -w /dev/bus/usb/${USB_BUS}/${USB_DEV} ]; then | ||||||
|  |         local EXEC_SCRIPT=1 | ||||||
|  |         echo "chown root:${USER} /dev/bus/usb/${USB_BUS}/${USB_DEV}" >> "${TEMP_SCRIPT}" | ||||||
|  |       fi | ||||||
|  |     done | ||||||
|  | 
 | ||||||
|  |     if [ ${EXEC_SCRIPT} -eq 1 ]; then | ||||||
|  |       chmod +x "${TEMP_SCRIPT}" | ||||||
|  |       echo "             Requested USB device(s) are NOT accessible." | ||||||
|  |       echo "             ${TEMP_SCRIPT} will be executed to enable access:" | ||||||
|  |       echo | ||||||
|  |       cat ${TEMP_SCRIPT} | ||||||
|  |       echo | ||||||
|  |       sudo "${TEMP_SCRIPT}" | ||||||
|  |       if [ $? -ne 0 ]; then | ||||||
|  |         echo "            WARNING! Enabling USB device access failed." | ||||||
|  |       fi | ||||||
|  |     else | ||||||
|  |       echo "             Requested USB device(s) are accessible." | ||||||
|  |     fi | ||||||
|  |     rm -f "${TEMP_SCRIPT}" | ||||||
|  |   fi | ||||||
|  | } | ||||||
|  | 
 | ||||||
| function vm_boot() { | function vm_boot() { | ||||||
|   local VMNAME=$(basename "${VM}" .conf) |   local VMNAME=$(basename "${VM}" .conf) | ||||||
|   local VMDIR=$(dirname "${disk_img}") |   local VMDIR=$(dirname "${disk_img}") | ||||||
|   local BIOS="" |  | ||||||
|   local CPU="-cpu host,kvm=on" |   local CPU="-cpu host,kvm=on" | ||||||
|   local GUEST_TWEAKS="" |   local GUEST_TWEAKS="" | ||||||
|   local DISPLAY_DEVICE="" |   local DISPLAY_DEVICE="" | ||||||
|  | @ -275,6 +321,8 @@ function vm_boot() { | ||||||
|     echo " - ssh:      All ports for exposing ssh have been exhausted." |     echo " - ssh:      All ports for exposing ssh have been exhausted." | ||||||
|   fi |   fi | ||||||
| 
 | 
 | ||||||
|  |   enable_usb_passthrough | ||||||
|  | 
 | ||||||
|   # Boot the iso image |   # Boot the iso image | ||||||
|   if [ "${boot}" == "efi" ] || [ "${boot}" == "uefi" ]; then |   if [ "${boot}" == "efi" ] || [ "${boot}" == "uefi" ]; then | ||||||
|     ${QEMU} \ |     ${QEMU} \ | ||||||
|  | @ -351,12 +399,14 @@ iso="" | ||||||
| driver_iso="" | driver_iso="" | ||||||
| disk_img="" | disk_img="" | ||||||
| disk="64G" | disk="64G" | ||||||
|  | usb_devices=() | ||||||
| 
 | 
 | ||||||
| DELETE=0 | DELETE=0 | ||||||
| ENABLE_EFI=0 | ENABLE_EFI=0 | ||||||
| SNAPSHOT_ACTION="" | SNAPSHOT_ACTION="" | ||||||
| SNAPSHOT_TAG="" | SNAPSHOT_TAG="" | ||||||
| STATUS_QUO="" | STATUS_QUO="" | ||||||
|  | USB_PASSTHOUGH="" | ||||||
| VM="" | VM="" | ||||||
| 
 | 
 | ||||||
| readonly LAUNCHER=$(basename "${0}") | readonly LAUNCHER=$(basename "${0}") | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue