Compare commits
No commits in common. "2119154718fada2092d08d7fdd6bccd1a2c53959" and "0a2de050ddccd7ca109ba3c97df74aa0e40ac33f" have entirely different histories.
2119154718
...
0a2de050dd
8 changed files with 46 additions and 54 deletions
|
@ -50,7 +50,8 @@ 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
|
||||||
- `pathof` - see [Installation instructions](#installation-instructions)
|
- `diskpath` and `sockpath` - see [Installation
|
||||||
|
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
|
||||||
|
|
|
@ -66,7 +66,7 @@ public_start() {
|
||||||
QEMUSH_NAME="$1"
|
QEMUSH_NAME="$1"
|
||||||
|
|
||||||
set -- "$@" \
|
set -- "$@" \
|
||||||
-monitor "unix:$(pathof socket),server,nowait" \
|
-monitor "unix:$(sockpath),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:$(pathof socket)"
|
exec socat -,echo=0,icanon=0 "UNIX-CONNECT:$(sockpath)"
|
||||||
}
|
}
|
||||||
|
|
||||||
# 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 "$(pathof disk)" "$1"
|
exec qemu-img create -f qcow2 "$(diskpath)" "$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 -- "$(pathof disk)"
|
rm -vi -- "$(diskpath)"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
16
qemu/bin/diskpath
Executable file
16
qemu/bin/diskpath
Executable file
|
@ -0,0 +1,16 @@
|
||||||
|
#!/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"
|
|
@ -1,37 +0,0 @@
|
||||||
#!/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"
|
|
16
qemu/bin/sockpath
Executable file
16
qemu/bin/sockpath
Executable file
|
@ -0,0 +1,16 @@
|
||||||
|
#!/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"
|
|
@ -1,8 +1,8 @@
|
||||||
#!/bin/sh -x
|
#!/bin/sh -x
|
||||||
exec "$QEMUSH_BASE" \
|
exec kvm \
|
||||||
-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 \
|
||||||
"$@"
|
"$@"
|
|
@ -1,7 +0,0 @@
|
||||||
#!/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 \
|
|
||||||
"$@"
|
|
|
@ -3,13 +3,16 @@
|
||||||
# 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 spice \
|
exec kvm-spice \
|
||||||
-drive file="$(pathof disk)",if=virtio \
|
-drive file="$(diskpath)",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 \
|
||||||
"$@"
|
"$@"
|
||||||
|
|
Loading…
Reference in a new issue