mirror of
https://github.com/oSoWoSo/DistroHopper.git
synced 2024-08-14 22:46:53 +00:00
Refactored so that quickemu is only compatible with qemu-virgil
Trying to maintain compatibility with other builds of QEMU going back into the past is futile. Quickemu now only intended to work with the qemu-virgil snap.
This commit is contained in:
parent
db33fc02a7
commit
2690663b3b
2 changed files with 57 additions and 94 deletions
31
README.md
31
README.md
|
@ -17,29 +17,22 @@ distributions where the virtual machines can be stored anywhere, such as
|
||||||
external USB storage.
|
external USB storage.
|
||||||
|
|
||||||
Quickemu is opinionated and will attempt to *"do the right thing"* rather than
|
Quickemu is opinionated and will attempt to *"do the right thing"* rather than
|
||||||
expose rich configuration options. See the video where I explain some of my
|
expose rich configuration options. Quickemu is a frontend to the fully
|
||||||
motivations for creating this script.
|
accelerated [qemu-virgil](https://snapcraft.io/qemu-virgil). See the video
|
||||||
|
where I explain some of my motivations for creating this script.
|
||||||
|
|
||||||
[![Replace VirtualBox with Bash & QEMU](https://img.youtube.com/vi/AOTYWEgw0hI/0.jpg)](https://www.youtube.com/watch?v=AOTYWEgw0hI)
|
[![Replace VirtualBox with Bash & QEMU](https://img.youtube.com/vi/AOTYWEgw0hI/0.jpg)](https://www.youtube.com/watch?v=AOTYWEgw0hI)
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
### Ubuntu 19.10 or newer
|
Clone this repository:
|
||||||
|
|
||||||
Install qemu
|
```
|
||||||
|
git clone https://github.com/wimpysworld/quickemu.git
|
||||||
```bash
|
|
||||||
sudo apt install qemu qemu-kvm libvirt-clients libvirt-daemon bridge-utils ovmf
|
|
||||||
sudo adduser ${SUDO_USER} kvm
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Install `samba` *(optional)* if you want to share home directories with guest virtual machines
|
Install the `qemu-virgil` snap. You can find details about how to install snapd
|
||||||
|
and `qemu-virgil` on the [Snap Store page for qemu-virgil](https://snapcraft.io/qemu-virgil)
|
||||||
```bash
|
|
||||||
sudo apt install samba
|
|
||||||
```
|
|
||||||
|
|
||||||
Install the `qemu-virgil` snap *(optional)*
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
snap install qemu-virgil
|
snap install qemu-virgil
|
||||||
|
@ -68,16 +61,16 @@ Which will output something like this:
|
||||||
|
|
||||||
```
|
```
|
||||||
Starting /media/martin/Quickemu/ubuntu-focal-desktop.conf
|
Starting /media/martin/Quickemu/ubuntu-focal-desktop.conf
|
||||||
|
- QEMU: /snap/bin/qemu-virgil v4.2.0
|
||||||
- BIOS: Legacy
|
- BIOS: Legacy
|
||||||
- Disk: /media/martin/Quickemu/ubuntu/focal-desktop-amd64.qcow2
|
- Disk: /media/martin/Quickemu/ubuntu/focal-desktop-amd64.qcow2 (64G)
|
||||||
- Size: 64G
|
|
||||||
- ISO: /media/martin/Quickemu/ubuntu/focal-desktop-amd64.iso
|
- ISO: /media/martin/Quickemu/ubuntu/focal-desktop-amd64.iso
|
||||||
- CPU: 4 Core(s)
|
- CPU: 4 Core(s)
|
||||||
- RAM: 4G
|
- RAM: 4G
|
||||||
- UI: sdl
|
- UI: sdl
|
||||||
- GL: on
|
- GL: on
|
||||||
- VIRGL: on
|
- VIRGL: on
|
||||||
- Monitor: 1664x936
|
- Display: 1664x936
|
||||||
- smbd: /home/martin will be exported to the guest via smb://10.0.2.4/qemu
|
- smbd: /home/martin will be exported to the guest via smb://10.0.2.4/qemu
|
||||||
- ssh: 22221/tcp is connected. Login via 'ssh user@localhost -p 22221'
|
- ssh: 22221/tcp is connected. Login via 'ssh user@localhost -p 22221'
|
||||||
```
|
```
|
||||||
|
@ -93,7 +86,6 @@ You can also pass optional parameters
|
||||||
--efi : Enable EFI BIOS (experimental).
|
--efi : Enable EFI BIOS (experimental).
|
||||||
--restore : Restore the snapshot.
|
--restore : Restore the snapshot.
|
||||||
--snapshot : Create a disk snapshot.
|
--snapshot : Create a disk snapshot.
|
||||||
--virgil : Use virgil, if available.
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
|
@ -102,3 +94,4 @@ You can also pass optional parameters
|
||||||
- [x] Improve stdout presentation
|
- [x] Improve stdout presentation
|
||||||
- [x] Make disk image optionally size configurable
|
- [x] Make disk image optionally size configurable
|
||||||
- [ ] Improve snapshot management
|
- [ ] Improve snapshot management
|
||||||
|
- [ ] Create desktop launcher for a VM
|
92
quickemu.sh
92
quickemu.sh
|
@ -48,41 +48,34 @@ function vm_boot() {
|
||||||
local GL="on"
|
local GL="on"
|
||||||
local VIRGL="on"
|
local VIRGL="on"
|
||||||
local UI="sdl"
|
local UI="sdl"
|
||||||
|
|
||||||
# If QEMU has not already been selected, pick one
|
|
||||||
if [ -z "${QEMU}" ]; then
|
|
||||||
if [ -e /snap/bin/qemu-virgil ]; then
|
|
||||||
QEMU="/snap/bin/qemu-virgil"
|
|
||||||
QEMU_IMG="/snap/bin/qemu-virgil.qemu-img"
|
|
||||||
#QEMU_IMG="/usr/bin/qemu-img"
|
|
||||||
elif [ -e /usr/bin/qemu-system-x86_64 ]; then
|
|
||||||
QEMU="/usr/bin/qemu-system-x86_64"
|
|
||||||
QEMU_IMG="/usr/bin/qemu-img"
|
|
||||||
else
|
|
||||||
echo "ERROR! Could not find QEMU. Quitting."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
local QEMU_VER=$(${QEMU} -version | head -n1 | cut -d' ' -f4 | cut -d'(' -f1)
|
local QEMU_VER=$(${QEMU} -version | head -n1 | cut -d' ' -f4 | cut -d'(' -f1)
|
||||||
local QEMU_BIN=$(basename ${QEMU})
|
echo "Starting ${VM}"
|
||||||
echo " - QEMU: ${QEMU} v${QEMU_VER}"
|
echo " - QEMU: ${QEMU} v${QEMU_VER}"
|
||||||
|
|
||||||
if [ ${ENABLE_EFI} -eq 1 ]; then
|
if [ ${ENABLE_EFI} -eq 1 ]; then
|
||||||
if [ "${QEMU_BIN}" == "qemu-virgil" ] && [ -e /snap/qemu-virgil/current/usr/share/qemu/edk2-x86_64-code.fd ] ; then
|
if [ -e /snap/qemu-virgil/current/usr/share/qemu/edk2-x86_64-code.fd ] ; then
|
||||||
BIOS="-drive if=pflash,format=raw,readonly,file=/snap/qemu-virgil/current/usr/share/qemu/edk2-x86_64-code.fd"
|
BIOS="-drive if=pflash,format=raw,readonly,file=/snap/qemu-virgil/current/usr/share/qemu/edk2-x86_64-code.fd"
|
||||||
VIRGL="off"
|
VIRGL="off"
|
||||||
elif [ -e /usr/share/qemu/OVMF.fd ]; then
|
|
||||||
BIOS="-drive if=pflash,format=raw,readonly,file=/usr/share/qemu/OVMF.fd"
|
|
||||||
VIRGL="off"
|
|
||||||
else
|
else
|
||||||
echo " - EFI: Booting requested but no EFI firmware found."
|
echo " - EFI: Booting requested but no EFI firmware found."
|
||||||
echo " Booting from Legacy BIOS."
|
echo " Booting from Legacy BIOS."
|
||||||
fi
|
fi
|
||||||
echo " - BIOS: ${BIOS}"
|
echo " - BIOS: EFI"
|
||||||
else
|
else
|
||||||
echo " - BIOS: Legacy"
|
echo " - BIOS: Legacy"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -n "${disk_img}" ]; then
|
||||||
|
disk_img_snapshot="${disk_img}.snapshot"
|
||||||
|
else
|
||||||
|
echo "ERROR! No disk_img defined."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "${disk}" ]; then
|
||||||
|
disk="64G"
|
||||||
|
fi
|
||||||
|
|
||||||
echo " - Disk: ${disk_img} (${disk})"
|
echo " - Disk: ${disk_img} (${disk})"
|
||||||
# If the disk is present but doesn't appear to have an install, then
|
# If the disk is present but doesn't appear to have an install, then
|
||||||
# remove it.
|
# remove it.
|
||||||
|
@ -130,21 +123,13 @@ function vm_boot() {
|
||||||
|
|
||||||
# Determine what display to use
|
# Determine what display to use
|
||||||
local display="-display ${UI},gl=${GL}"
|
local display="-display ${UI},gl=${GL}"
|
||||||
if [ "${QEMU_VER}" == "2.11.1" ]; then
|
|
||||||
display="-display sdl"
|
|
||||||
# Fix stuttering mouse pointer when SDL backend is used.
|
|
||||||
export SDL_VIDEO_X11_DGAMOUSE=0
|
|
||||||
fi
|
|
||||||
echo " - UI: ${UI}"
|
echo " - UI: ${UI}"
|
||||||
echo " - GL: ${GL}"
|
echo " - GL: ${GL}"
|
||||||
echo " - VIRGL: ${VIRGL}"
|
echo " - VIRGL: ${VIRGL}"
|
||||||
|
|
||||||
# TODO: Detect Wayland here and "do the right thing".
|
local xres=1152
|
||||||
# Determine the most suitable 16:9 resolution of for VM based
|
local yres=648
|
||||||
# on the lowest resolution connected monitor.
|
if [ "${XDG_SESSION_TYPE}" == "x11" ]; then
|
||||||
local xres=800
|
|
||||||
local yres=600
|
|
||||||
|
|
||||||
local LOWEST_WIDTH=$(xrandr --listmonitors | grep -v Monitors | cut -d' ' -f4 | cut -d'/' -f1 | sort | head -n1)
|
local LOWEST_WIDTH=$(xrandr --listmonitors | grep -v Monitors | cut -d' ' -f4 | cut -d'/' -f1 | sort | head -n1)
|
||||||
if [ ${LOWEST_WIDTH} -ge 3840 ]; then
|
if [ ${LOWEST_WIDTH} -ge 3840 ]; then
|
||||||
xres=3200
|
xres=3200
|
||||||
|
@ -159,16 +144,13 @@ function vm_boot() {
|
||||||
xres=1152
|
xres=1152
|
||||||
yres=648
|
yres=648
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${QEMU_BIN}" == "qemu-virgil" ]; then
|
|
||||||
echo " - Monitor: ${xres}x${yres}"
|
|
||||||
fi
|
fi
|
||||||
|
echo " - Display: ${xres}x${yres}"
|
||||||
|
|
||||||
|
|
||||||
local NET=""
|
local NET=""
|
||||||
# If smbd is available, export $HOME to the guest via samba
|
# If smbd is available, export $HOME to the guest via samba
|
||||||
if [ "${QEMU_BIN}" == "qemu-virgil" ] && [ -e /snap/qemu-virgil/current/usr/sbin/smbd ]; then
|
if [ -e /snap/qemu-virgil/current/usr/sbin/smbd ]; then
|
||||||
NET=",smb=${HOME}"
|
|
||||||
elif [ "${QEMU_BIN}" == "qemu-system-x86_64" ] && [ -e /usr/sbin/smbd ]; then
|
|
||||||
NET=",smb=${HOME}"
|
NET=",smb=${HOME}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -187,7 +169,6 @@ 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
|
||||||
|
|
||||||
#echo " - QEMU: qemu-${ENGINE}"
|
|
||||||
# Boot the iso image
|
# Boot the iso image
|
||||||
${QEMU} -name ${VMNAME},process=${VMNAME} \
|
${QEMU} -name ${VMNAME},process=${VMNAME} \
|
||||||
${BIOS} \
|
${BIOS} \
|
||||||
|
@ -221,17 +202,15 @@ function usage() {
|
||||||
echo "You can also pass optional parameters"
|
echo "You can also pass optional parameters"
|
||||||
echo " --delete : Delete the disk image."
|
echo " --delete : Delete the disk image."
|
||||||
echo " --efi : Enable EFI BIOS (experimental)."
|
echo " --efi : Enable EFI BIOS (experimental)."
|
||||||
echo " --qemu : Override full path to QEMU executable."
|
|
||||||
echo " --restore : Restore the snapshot."
|
echo " --restore : Restore the snapshot."
|
||||||
echo " --snapshot : Create a disk snapshot."
|
echo " --snapshot : Create a disk snapshot."
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
disk="64G"
|
|
||||||
BIOS=""
|
|
||||||
DELETE=0
|
DELETE=0
|
||||||
ENABLE_EFI=0
|
ENABLE_EFI=0
|
||||||
QEMU=""
|
readonly QEMU="/snap/bin/qemu-virgil"
|
||||||
|
readonly QEMU_IMG="/snap/bin/qemu-virgil.qemu-img"
|
||||||
RESTORE=0
|
RESTORE=0
|
||||||
SNAPSHOT=0
|
SNAPSHOT=0
|
||||||
VM=""
|
VM=""
|
||||||
|
@ -250,10 +229,6 @@ while [ $# -gt 0 ]; do
|
||||||
-snapshot|--snapshot)
|
-snapshot|--snapshot)
|
||||||
SNAPSHOT=1
|
SNAPSHOT=1
|
||||||
shift;;
|
shift;;
|
||||||
-qemu|--qemu)
|
|
||||||
QEMU="$2"
|
|
||||||
shift
|
|
||||||
shift;;
|
|
||||||
-vm|--vm)
|
-vm|--vm)
|
||||||
VM="$2"
|
VM="$2"
|
||||||
shift
|
shift
|
||||||
|
@ -266,23 +241,18 @@ while [ $# -gt 0 ]; do
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ -n "${VM}" ] || [ -e "${VM}" ]; then
|
# Check we have qemu-virgil available
|
||||||
source "${VM}"
|
if [ ! -e "${QEMU}" ] && [ ! -e "${QEMU_IMG}" ]; then
|
||||||
echo Starting "${VM}"
|
echo "ERROR! qemu-virgil not found. Please install the qemu-virgil snap."
|
||||||
if [ -n "${disk_img}" ]; then
|
echo " https://snapcraft.io/qemu-virgil"
|
||||||
disk_img_snapshot="${disk_img}.snapshot"
|
|
||||||
else
|
|
||||||
echo "ERROR! No disk_img defined."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "ERROR! VM not found."
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "${QEMU}" ] && [ ! -e "${QEMU}" ]; then
|
if [ -n "${VM}" ] || [ -e "${VM}" ]; then
|
||||||
echo "ERROR! ${QEMU} not found. Quitting"
|
source "${VM}"
|
||||||
exit 1
|
else
|
||||||
|
echo "ERROR! Virtual machine configuration not found."
|
||||||
|
usage
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ${DELETE} -eq 1 ]; then
|
if [ ${DELETE} -eq 1 ]; then
|
||||||
|
|
Loading…
Reference in a new issue