Compare commits

...

2 commits

8 changed files with 54 additions and 46 deletions

View file

@ -50,8 +50,7 @@ need it
- `coreutils` - used for basic OS operations - `coreutils` - used for basic OS operations
- `sudo` - execute commands as `qemu` - `sudo` - execute commands as `qemu`
- `socat` - monitor machines via Unix sockets - `socat` - monitor machines via Unix sockets
- `diskpath` and `sockpath` - see [Installation - `pathof` - see [Installation instructions](#installation-instructions)
instructions](#installation-instructions)
- any text editor - used for builtin function to edit launching scripts - any text editor - used for builtin function to edit launching scripts
## Installation instructions ## Installation instructions

View file

@ -66,7 +66,7 @@ public_start() {
QEMUSH_NAME="$1" QEMUSH_NAME="$1"
set -- "$@" \ set -- "$@" \
-monitor "unix:$(sockpath),server,nowait" \ -monitor "unix:$(pathof socket),server,nowait" \
-daemonize -daemonize
if ! "$@"; then if ! "$@"; then
perror "error launching virtual machine \"${QEMUSH_NAME}\"" perror "error launching virtual machine \"${QEMUSH_NAME}\""
@ -80,7 +80,7 @@ public_attach() {
QEMUSH_NAME="$1" QEMUSH_NAME="$1"
shift shift
exec socat -,echo=0,icanon=0 "UNIX-CONNECT:$(sockpath)" exec socat -,echo=0,icanon=0 "UNIX-CONNECT:$(pathof socket)"
} }
# List running virtual machines # List running virtual machines
@ -103,14 +103,14 @@ public_ls() {
public_diskadd() { public_diskadd() {
QEMUSH_NAME="$1" QEMUSH_NAME="$1"
shift shift
exec qemu-img create -f qcow2 "$(diskpath)" "$1" exec qemu-img create -f qcow2 "$(pathof disk)" "$1"
} }
# Delete a disk # Delete a disk
public_diskrm() { public_diskrm() {
for disk in "$@"; do for disk in "$@"; do
QEMUSH_NAME="$disk" QEMUSH_NAME="$disk"
rm -vi -- "$(diskpath)" rm -vi -- "$(pathof disk)"
done done
} }

View file

@ -1,16 +0,0 @@
#!/bin/sh -e
# Invoked on termination if the last command failed
error() { >&2 echo "$(basename "$0"): failed"; }
# Trap errors
trap error EXIT
# Assert that the QEMUSH_NAME variable is not null
[ -n "$QEMUSH_NAME" ]
# Release the trap
trap - EXIT
# Print the actual string
printf %s/%s.qcow2\\n ~/disks "$QEMUSH_NAME"

37
qemu/bin/pathof Executable file
View file

@ -0,0 +1,37 @@
#!/bin/sh -e
# Invoked on termination if the last command failed
error() { >&2 echo "$(basename "$0"): ${*}"; }
error_envvar() { error "missing environment variable QEMUSH_NAME"; }
error_arg() { error "invalid argument \"${*}\""; }
# Assert that the QEMUSH_NAME variable is not null
trap error_envvar EXIT
[ -n "$QEMUSH_NAME" ]
# Determine the base dir to use
trap 'error_arg "$*"' EXIT
case "$1" in
disk)
basedir=disks
extension=qcow2
;;
socket)
basedir=sockets
;;
spice)
basedir=spice
extension=sock
;;
*)
false
;;
esac
# Release the trap
trap - EXIT
# Print the actual string
basedir="${HOME}/${basedir}"
[ -n "$extension" ] && extension=".${extension}"
printf %s/%s%s\\n "$basedir" "$QEMUSH_NAME" "$extension"

View file

@ -1,16 +0,0 @@
#!/bin/sh -e
# Invoked on termination if the last command failed
error() { >&2 echo "$(basename "$0"): failed"; }
# Trap errors
trap error EXIT
# Assert that the QEMUSH_NAME variable is not null
[ -n "$QEMUSH_NAME" ]
# Release the trap
trap - EXIT
# Print the actual string
printf %s/%s ~/sockets "$QEMUSH_NAME"

View file

@ -1,8 +1,8 @@
#!/bin/sh -x #!/bin/sh -x
exec kvm \ exec "$QEMUSH_BASE" \
-vga qxl \ -vga qxl \
-chardev spicevmc,id=vdagent,debug=0,name=vdagent \ -chardev spicevmc,id=vdagent,debug=0,name=vdagent \
-device virtio-serial \ -device virtio-serial \
-device virtserialport,chardev=vdagent,name=com.redhat.spice.0 \ -device virtserialport,chardev=vdagent,name=com.redhat.spice.0 \
-spice port="$(first-free-port 5900)",addr=127.0.0.1,disable-ticketing=on \ -spice port="$(first-free-port 5900)",addr=127.0.0.1,disable-ticketing=on \
"$@" "$@"

7
qemu/launchers/virtiofs Executable file
View file

@ -0,0 +1,7 @@
#!/bin/sh -x
exec "${QEMUSH_BASE}" \
-chardev socket,id=char0,path=/run/virtiofsd.sock \
-device vhost-user-fs-pci,chardev=char0,tag=shared \
-object memory-backend-memfd,id=mem,size="${QEMUSH_RAM}",share=on \
-numa node,memdev=mem \
"$@"

View file

@ -3,16 +3,13 @@
# Store VM name in environment variable # Store VM name in environment variable
export QEMUSH_NAME export QEMUSH_NAME
export QEMUSH_RAM=4G export QEMUSH_RAM=4G
export QEMUSH_BASE=kvm
[ -z "$QEMUSH_NAME" ] && QEMUSH_NAME=$(basename "$0") [ -z "$QEMUSH_NAME" ] && QEMUSH_NAME=$(basename "$0")
# Launch the virtual machine # Launch the virtual machine
exec kvm-spice \ exec spice \
-drive file="$(diskpath)",if=virtio \ -drive file="$(pathof disk)",if=virtio \
-net user,hostname="${QEMUSH_NAME}" \ -net user,hostname="${QEMUSH_NAME}" \
-usbdevice tablet \ -usbdevice tablet \
-name "$QEMUSH_NAME" \ -name "$QEMUSH_NAME" \
-chardev socket,id=char0,path=/run/virtiofsd.sock \
-device vhost-user-fs-pci,chardev=char0,tag=shared \
-object memory-backend-memfd,id=mem,size="${QEMUSH_RAM}",share=on \
-numa node,memdev=mem \
"$@" "$@"