Compare commits
2 commits
0a2de050dd
...
2119154718
Author | SHA1 | Date | |
---|---|---|---|
2119154718 | |||
9cc7cad967 |
8 changed files with 54 additions and 46 deletions
|
@ -50,8 +50,7 @@ need it
|
|||
- `coreutils` - used for basic OS operations
|
||||
- `sudo` - execute commands as `qemu`
|
||||
- `socat` - monitor machines via Unix sockets
|
||||
- `diskpath` and `sockpath` - see [Installation
|
||||
instructions](#installation-instructions)
|
||||
- `pathof` - see [Installation instructions](#installation-instructions)
|
||||
- any text editor - used for builtin function to edit launching scripts
|
||||
|
||||
## Installation instructions
|
||||
|
|
|
@ -66,7 +66,7 @@ public_start() {
|
|||
QEMUSH_NAME="$1"
|
||||
|
||||
set -- "$@" \
|
||||
-monitor "unix:$(sockpath),server,nowait" \
|
||||
-monitor "unix:$(pathof socket),server,nowait" \
|
||||
-daemonize
|
||||
if ! "$@"; then
|
||||
perror "error launching virtual machine \"${QEMUSH_NAME}\""
|
||||
|
@ -80,7 +80,7 @@ public_attach() {
|
|||
QEMUSH_NAME="$1"
|
||||
shift
|
||||
|
||||
exec socat -,echo=0,icanon=0 "UNIX-CONNECT:$(sockpath)"
|
||||
exec socat -,echo=0,icanon=0 "UNIX-CONNECT:$(pathof socket)"
|
||||
}
|
||||
|
||||
# List running virtual machines
|
||||
|
@ -103,14 +103,14 @@ public_ls() {
|
|||
public_diskadd() {
|
||||
QEMUSH_NAME="$1"
|
||||
shift
|
||||
exec qemu-img create -f qcow2 "$(diskpath)" "$1"
|
||||
exec qemu-img create -f qcow2 "$(pathof disk)" "$1"
|
||||
}
|
||||
|
||||
# Delete a disk
|
||||
public_diskrm() {
|
||||
for disk in "$@"; do
|
||||
QEMUSH_NAME="$disk"
|
||||
rm -vi -- "$(diskpath)"
|
||||
rm -vi -- "$(pathof disk)"
|
||||
done
|
||||
}
|
||||
|
||||
|
|
|
@ -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
37
qemu/bin/pathof
Executable 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"
|
|
@ -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"
|
|
@ -1,5 +1,5 @@
|
|||
#!/bin/sh -x
|
||||
exec kvm \
|
||||
exec "$QEMUSH_BASE" \
|
||||
-vga qxl \
|
||||
-chardev spicevmc,id=vdagent,debug=0,name=vdagent \
|
||||
-device virtio-serial \
|
7
qemu/launchers/virtiofs
Executable file
7
qemu/launchers/virtiofs
Executable 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 \
|
||||
"$@"
|
|
@ -3,16 +3,13 @@
|
|||
# Store VM name in environment variable
|
||||
export QEMUSH_NAME
|
||||
export QEMUSH_RAM=4G
|
||||
export QEMUSH_BASE=kvm
|
||||
[ -z "$QEMUSH_NAME" ] && QEMUSH_NAME=$(basename "$0")
|
||||
|
||||
# Launch the virtual machine
|
||||
exec kvm-spice \
|
||||
-drive file="$(diskpath)",if=virtio \
|
||||
exec spice \
|
||||
-drive file="$(pathof disk)",if=virtio \
|
||||
-net user,hostname="${QEMUSH_NAME}" \
|
||||
-usbdevice tablet \
|
||||
-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