boot_opts="-boot $boot"
fi
+ if [ ! -z "$usb" ] && [ "$usb" != "0" ]; then
+ # Basic USB support
+ if [ "$usb" == "1" ]; then
+ usb_opts="-usb"
+ fi
+
+ # USB support with 1.0 and 2.0 hub
+ if [ "$usb" == "2" ]; then
+ usb_opts="-usb -device usb-ehci,id=ehci -device usb-host,bus=ehci.0,vendorid=1452"
+ fi
+
+ # USB support with 1.0, 2.0 and 3.0 hubs
+ if [ "$usb" == "3" ]; then
+ usb_opts="-usb -device usb-ehci,id=ehci -device usb-host,bus=ehci.0,vendorid=1452 -device qemu-xhci,id=xhci"
+ fi
+ fi
+
# Check kvm version
if kvm --help | grep -q -- "^-balloon"; then
local new_qemu="0"
$boot_opts \
$net_opts \
$rng_opts \
+ $usb_opts \
-pidfile $PIDFILE \
-D $LOGFILE \
$qemu_opts
socat $MONITORFILE STDIO
else
socat STDIO $MONITORFILE <<EOF
-$1
+$*
EOF
fi
}
done
}
+# USB attach
+function kvmx_usb_attach {
+ if ! kvmx_running; then
+ echo "$BASENAME: guest $VM is not running"
+ exit 1
+ fi
+
+ # Check for lsusb
+ if ! which lsusb &> /dev/null; then
+ echo "Please install usbutils package."
+ exit 1
+ fi
+
+ local total="`lsusb | wc -l`"
+
+ # Check if USB is available in the system
+ if [ "$total" == "0" ]; then
+ echo "Sorry, but you don't have any available USB devices on your system."
+ exit 1
+ fi
+
+ # Check for usb config option
+ if [ -z "$usb" ] || [ "$usb" == "0" ]; then
+ echo "You need to enable USB support into the kvmxfile."
+ exit 1
+ fi
+
+ # List available devices
+ echo "Available devices:"
+ echo ""
+ lsusb | cat -n
+ echo ""
+
+ # Read option
+ read -rep "Choose a device (1-$total): " choice
+
+ # Validate choice
+ if (($choice < 1)) || (($choice > $total)); then
+ echo "Invalid choice."
+ exit 1
+ fi
+
+ # Get bus, device, vendor and product IDs
+ local option="`lsusb | cat -n | grep \"^ $choice\"`"
+ local bus="`echo $option | awk '{ print $3 }'`"
+ local device="`echo $option | awk '{ print $5 }' | cut -d ':' -f 1`"
+ local vendor="`echo $option | awk '{ print $7 }' | cut -d ':' -f 1`"
+ local product="`echo $option | awk '{ print $7 }' | cut -d ':' -f 2`"
+
+ # Give permission to the device
+ echo "Changing ownership of /dev/bus/usb/${bus}/${device} to you..."
+ sudo chown `whoami` /dev/bus/usb/$bus/$device
+
+ # Attach into the guest
+ echo "Attaching device ${vendor}:${product} into the guest..."
+ kvmx_monitor device_add usb-host,vendorid=0x${vendor},productid=0x${product}
+}
+
# Dispatch
if type kvmx_$ACTION 2> /dev/null | grep -q "kvmx_$ACTION ()"; then
__kvmx_initialize $*
# See http://www.reactos.org/wiki/QEMU#Setting_up_network
#nic_model="ne2k_pci"
+# USB support
+#
+# Allowed values:
+#
+# 0 - No USB support
+# 1 - Support for USB 1.0
+# 2 - Support for USB 1.0 and 2.0
+# 3 - Support for USB 1.0, 2.0 and 3.0
+#
+#usb="0"
+
# Additional qemu opts
# Example: http://www.linux-kvm.org/page/USB_Host_Device_Assigned_to_Guest
# See also: https://qemu.readthedocs.io/en/latest/system/usb.html
# https://wiki.gentoo.org/wiki/QEMU/Windows_guest
-#qemu_opts="-usb" # Basic USB support
-#qemu_opts="-usb -device usb-ehci,id=ehci -device usb-host,bus=ehci.0,vendorid=1452" # USB support with 1.0 and 2.0 hub
-#qemu_opts="-usb -device usb-ehci,id=ehci -device usb-host,bus=ehci.0,vendorid=1452 -device qemu-xhci,id=xhci" # USB support with 1.0, 2.0 and 3.0 hubs
-#qemu_opts="-usb -device usb-ehci,id=ehci -device usb-host,hostbus=2,hostaddr=3" # USB support, attaching an specific device
+#qemu_opts="-device usb-host,hostbus=2,hostaddr=3" # Automatically attach an specific USB device
+#qemu_opts=""
# Number of CPUs
#smp="4"