239 lines
		
	
	
		
			8.4 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			239 lines
		
	
	
		
			8.4 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
| #!/bin/bash
 | |
| #===============================================================================
 | |
| #
 | |
| # DIRECTORY:
 | |
| #   /home/*/.local/share/nautilus/scripts/06-Qemu/
 | |
| # OR
 | |
| #   /home/*/.gnome2/nautilus-sctipts/06-Qemu/ (deprecated)
 | |
| #
 | |
| # FILE:
 | |
| #   03-uefi
 | |
| #
 | |
| # USAGE:
 | |
| #   Right klick on a RAW image (.dd) and
 | |
| #   choose this nautilus script from the context menu.
 | |
| #
 | |
| # OPTIONS:
 | |
| #   none
 | |
| #
 | |
| # DESCRIPTION:
 | |
| #   Boot up a virtual machine in UEFI mode (with OVMF).
 | |
| #
 | |
| # REQUIREMENTS:
 | |
| #   bash, zenity, gnome-terminal, file, grep, qemu-system-x86, coreutils
 | |
| #     and vinagre
 | |
| #
 | |
| # BUGS:
 | |
| #   ---
 | |
| #
 | |
| # NOTES:
 | |
| #   Tested on
 | |
| #   - Debian 8+
 | |
| #   - Arch Linux
 | |
| #
 | |
| # AUTHOR:
 | |
| #   Patrick Neumann, patrick@neumannsland.de
 | |
| #
 | |
| # COMPANY:
 | |
| #   (privately)
 | |
| #
 | |
| # VERSION:
 | |
| #   0.9 (beta)
 | |
| #
 | |
| # LINK TO THE MOST CURRENT VERSION:
 | |
| #   https://...
 | |
| #
 | |
| # CREATED:
 | |
| #   06.02.2020
 | |
| #
 | |
| # COPYRIGHT (C):
 | |
| #   2015-2020 - Patrick Neumann
 | |
| #
 | |
| # LICENSE:
 | |
| #   This program is free software: you can redistribute it and/or modify
 | |
| #   it under the terms of the GNU General Public License as published by
 | |
| #   the Free Software Foundation, either version 3 of the License, or
 | |
| #   (at your option) any later version.
 | |
| #
 | |
| # WARRANTY:
 | |
| #   This program is distributed in the hope that it will be useful,
 | |
| #   but WITHOUT ANY WARRANTY; without even the implied warranty of
 | |
| #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | |
| #   GNU General Public License for more details.
 | |
| #
 | |
| #   You should have received a copy of the GNU General Public License
 | |
| #   along with this program. If not, see <http://www.gnu.org/licenses/>.
 | |
| #
 | |
| # TODO:
 | |
| #   - Support for different port of VNC server
 | |
| #   - Support for S-ATA, SCSI and SAS in addition to IDE
 | |
| #   - Mount VirtualBox Guest Additions ISO image
 | |
| #       and VMware Tools ISO for more flexibility after hand over the vmdk
 | |
| #
 | |
| # HISTORY:
 | |
| #   0.9 - Patrick Neumann - Initial (public) release
 | |
| #
 | |
| #===============================================================================
 | |
| 
 | |
| #-------------------------------------------------------------------------------
 | |
| # Additional supported Distribution(s) (add before Library!).
 | |
| #-------------------------------------------------------------------------------
 | |
| SUPPORTED_OSR="arch"
 | |
| 
 | |
| #-------------------------------------------------------------------------------
 | |
| # Check for library (casualscripter_nautilus-scripts_functions.sh).
 | |
| #-------------------------------------------------------------------------------
 | |
| readonly LIBRARY="${0%/*/*}/.casualscripter_nautilus-scripts_functions.sh"
 | |
| if [ ! -f "${LIBRARY}" ] ; then
 | |
|   ${ZENITY_BIN} --error \
 | |
|                 --text \
 | |
|                 "ERROR: casualscripter_nautilus-scripts_functions.sh MISSING!"
 | |
|   exit 1
 | |
| fi
 | |
| 
 | |
| source "${LIBRARY}"
 | |
| 
 | |
| #-------------------------------------------------------------------------------
 | |
| # Checks (see library "casualscripter_nautilus-scripts_functions.sh").
 | |
| #-------------------------------------------------------------------------------
 | |
| check_dep "${FILE_BIN}" "file"
 | |
| check_dep "${GREP_BIN}" "grep"
 | |
| check_dep "${GTERMINAL_BIN}" "gnome-terminal"
 | |
| check_dep "${SUDO_BIN}" "sudo"
 | |
| check_dep "${QEMUSYS64_BIN}" "qemu-system-x86"
 | |
| check_dep "${SLEEP_BIN}" "coreutils"
 | |
| check_dep "${VINAGRE_BIN}" "vinagre"
 | |
| 
 | |
| check_ext "${SOURCE}" "dd"
 | |
| 
 | |
| #-------------------------------------------------------------------------------
 | |
| # Avoid unintended changes to the Image.
 | |
| #-------------------------------------------------------------------------------
 | |
| check_if_pwd_is_used_as_mountpoint
 | |
| 
 | |
| #-------------------------------------------------------------------------------
 | |
| # Check, if source is not mounted.
 | |
| #-------------------------------------------------------------------------------
 | |
| check_if_source_is_not_mounted
 | |
| 
 | |
| #-------------------------------------------------------------------------------
 | |
| # Open Virtual Machine Firmware (http://www.tianocore.org/ovmf/)
 | |
| #-------------------------------------------------------------------------------
 | |
| OVMF="/usr/share/edk2-ovmf/x64/OVMF_CODE.fd"
 | |
| if [ ! -f "${OVMF}" ] ; then
 | |
|   error_exit "Open Virtual Machine Firmware not found"
 | |
| fi
 | |
| 
 | |
| #-------------------------------------------------------------------------------
 | |
| # Ideas for some content for the drivers-and-tools.iso...
 | |
| #   Drivers for Windows guests:
 | |
| #   - https://www.spice-space.org/download/windows/qxl/qxl-0.1-21/qxl_xp_x86.zip
 | |
| #   - https://www.spice-space.org/download/windows/qxl/qxl-0.1-24/qxl_w7_x86.zip
 | |
| #   - https://www.spice-space.org/download/windows/qxl/qxl-0.1-24/qxl_w7_x64.zip
 | |
| #   - https://www.spice-space.org/download/windows/qxl/qxl-0.1-24/qxl_8k2R2_x64.zip
 | |
| #   - https://people.redhat.com/~vrozenfe/qxlwddm/qxlwddm-0.12.zip (Windows 8)
 | |
| #   - https://www.spice-space.org/download/windows/qxl-wddm-dod/qxl-wddm-dod-0.19/spice-qxl-wddm-dod-0.19.zip (Windows 10)
 | |
| #   Windows tools:
 | |
| #   - https://technet.microsoft.com/de-de/sysinternals/bb842062.aspx
 | |
| #   - http://nirsoft.net/utils/index.html
 | |
| #   GNU/Linux tools (i386, amd64, arm and aarch64):
 | |
| #   - https://busybox.net
 | |
| #   - https://matt.ucc.asn.au/dropbear/dropbear.html
 | |
| #   - https://rsync.samba.org/
 | |
| #   macOS tools:
 | |
| #   - ?
 | |
| #-------------------------------------------------------------------------------
 | |
| DRIVERSANDTOOLS="${HOME}/Additions/drivers-and-tools.iso"
 | |
| if [ ! -f "${DRIVERSANDTOOLS}" ] ; then
 | |
|   error_exit "ISO with drivers and tools not found"
 | |
| fi
 | |
| 
 | |
| #-------------------------------------------------------------------------------
 | |
| # Collect additional options.
 | |
| #-------------------------------------------------------------------------------
 | |
| readonly ASK_SHAREDFOLDER="Additional device with drivers"
 | |
| readonly ASK_CONNECT="Connect to the Network"
 | |
| readonly ASK_VNC="Start QEMU VNC service"
 | |
| readonly SELECTS="$( ${ZENITY_BIN} --list \
 | |
|                                    --text "Include some additional options:" \
 | |
|                                    --checklist \
 | |
|                                    --column "Pick" \
 | |
|                                    --column "Option" TRUE "${ASK_SHAREDFOLDER}" \
 | |
|                                                      FALSE "${ASK_CONNECT}" \
 | |
|                                                      FALSE "${ASK_VNC}" )"
 | |
| 
 | |
| if echo "${SELECTS}" | ${GREP_BIN} --fixed-strings "${ASK_SHAREDFOLDER}" > /dev/null 2>&1 ; then
 | |
|   DRIVERS="-cdrom ${DRIVERSANDTOOLS}"
 | |
| else
 | |
|   DRIVERS=""
 | |
| fi
 | |
| 
 | |
| if echo "${SELECTS}" | ${GREP_BIN} --fixed-strings "${ASK_CONNECT}" > /dev/null 2>&1 ; then
 | |
|   RESTRICT="off"
 | |
| else
 | |
|   RESTRICT="on"
 | |
| fi
 | |
|   
 | |
| if echo "${SELECTS}" | ${GREP_BIN} --fixed-strings "${ASK_VNC}" > /dev/null 2>&1 ; then
 | |
|   VNC="-k de -vnc :0,tls,password"
 | |
| else
 | |
|   VNC=""
 | |
| fi
 | |
| 
 | |
| case "${OR_ID}${OR_VERSION_ID}" in
 | |
|   debian8) readonly EFI_ROM="/usr/lib/ipxe/qemu/efi-e1000.rom"
 | |
|            ;;
 | |
|   arch)    readonly EFI_ROM="/usr/share/qemu/efi-e1000.rom"
 | |
|            ;;
 | |
|   *)       error_exit "sorry, ${OR_PRETTY_NAME} is not supported"
 | |
| esac
 | |
| 
 | |
| #-------------------------------------------------------------------------------
 | |
| # Boot up the virtual machine:
 | |
| # - Enable KVM full virtualization support.
 | |
| # - KVM processor with all supported host features.
 | |
| # - Simulate an SMP system with 2 CPUs and 2 cores.
 | |
| # - Set virtual RAM size to 3072 megabytes (3 GB).
 | |
| # - Use ".OVMF.fd" as a parallel flash image.
 | |
| #     (needs readonly if a package from the distribution is used!)
 | |
| # - Enable "S3" (Standby, Sleep or Suspend to RAM).
 | |
| # - Pointer device that uses absolute coordinates without grab the mouse.
 | |
| # - QXL paravirtual VGA compatible (VESA 2.0 VBE) graphic card (rev4).
 | |
| # - With a "newer" and good supported network card.
 | |
| #     (QEMU/KVM + OVMF needs an EFI ROM for the Intel (Client) NIC!)
 | |
| # - Connect to the network if selected.
 | |
| # - Windowed or VNC mode.
 | |
| # - Redirect the "monitor" to standart input/output.
 | |
| # - Use the RAW image as harddisk.
 | |
| # - Use shared folder as additional drive.
 | |
| #-------------------------------------------------------------------------------
 | |
| readonly CPU_SOCKETS="1"
 | |
| readonly CPU_CORES="2"
 | |
| readonly CPU_THREADS="4"
 | |
| 
 | |
| ${GTERMINAL_BIN} --execute \
 | |
|   ${QEMUSYS64_BIN} \
 | |
|     -enable-kvm \
 | |
|     -cpu host \
 | |
|     -smp "${CPU_THREADS}",cores="${CPU_CORES}",sockets="${CPU_SOCKETS}" \
 | |
|     -m 3072 \
 | |
|     -drive file="${OVMF}",if=pflash,format=raw,readonly \
 | |
|     -global PIIX4_PM.disable_s3=0 \
 | |
|     -usb -device usb-tablet \
 | |
|     -device qxl-vga,revision=4 \
 | |
|     -device e1000-82540em,romfile="${EFI_ROM}",netdev=net0 \
 | |
|     -netdev user,restrict=${RESTRICT},id=net0 \
 | |
|     ${VNC} \
 | |
|     -monitor stdio \
 | |
|     -drive file="${SOURCE}",index=0,media=disk,format=raw \
 | |
|     ${DRIVERS}
 | |
| 
 | |
| if [ -n "${VNC}" ] ; then
 | |
|   # give qemu-system some time to bind process to port!
 | |
|   ${SLEEP_BIN} 1
 | |
|   ${VINAGRE_BIN} ::5900
 | |
| fi
 | |
| 
 | |
| exit 0
 | |
| 
 |