Compare commits

..

4 commits

8 changed files with 21 additions and 46 deletions

View file

@ -33,7 +33,6 @@ the same virtual machines
- **Modularization**: `qemush` launching scripts are intended to be
stackable to reuse common `qemu` parameters in all virtual machines
needing them
- **Process supervision**: `qemush` uses `tmux` to supervise processes and
keep track of them
- **Copy-on-write**: images are formatted using `qcow2` to use less space
on disk
@ -48,10 +47,10 @@ need it
- `bash` - the `qemush` interpreter
- `coreutils` - used for basic OS operations
- `sudo` - execute commands as `qemu`
- `tmux` - for process supervision
- `source-highlight` - for syntax highlighting when displaying launching
scripts
- `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
## Installation instructions
@ -94,7 +93,6 @@ by the `Makefile` for the installation process.
- Compile C programs from `src` in `~qemu/bin` with mode `740`
- Copy the default launching scripts to `~qemu/launchers` with mode `740`
- Copy `bin/qemush` to `/usr/local/bin/qemush` with mode `755`
- Copy the `tmux` configuration to the `qemu` user homedir
## Usage

View file

@ -18,6 +18,7 @@ exec_as qemu "$@"
# Directories used in the program
bin="${HOME}/launchers"
images="${HOME}/disks"
sockets="${HOME}/sockets"
# Environment
PATH="${bin}:${HOME}/bin:${PATH}"
@ -62,7 +63,6 @@ ${name}: usage:
${name} help - show this help
${name} add <path to script> [<VM name>] - add a launching script
${name} do <command> - run shell input as user qemu
${name} depcheck - check if script dependencies are met
EOF
}
@ -73,29 +73,27 @@ error_usage() {
return 1
}
# Function to start a virtual machine ; fails if the virtual machine is
# already started thanks to tmux
# Function to start a virtual machine
public_start() {
QEMUSH_NAME="$1"
shift
exec tmux new-session \
-s "$QEMUSH_NAME" \
"$QEMUSH_NAME" \
"$@"
exec "$QEMUSH_NAME" "$@"
}
# Attach to a running virtual machine output, the latest opened if no
# argument is provided
public_watch() {
[ -n "$1" ] && set -- -t "$1"
QEMUSH_NAME="$1"
shift
exec tmux attach "$@"
socat -,echo=0,icanon=0 "UNIX-CONNECT:$(sockpath)"
}
# List running virtual machines
public_active() {
exec tmux list-sessions
echo "Running machines:"
exec ls "$sockets"
}
# List available virtual machines entrypoints
@ -109,7 +107,7 @@ public_diskadd() {
QEMUSH_NAME="$1"
shift
exec qemu-img create -f qcow2 "$(pathof disk)" "$1"
exec qemu-img create -f qcow2 "$(diskpath)" "$1"
}
# Delete a disk
@ -117,7 +115,7 @@ public_diskrm() {
QEMUSH_NAME="$1"
shift
exec rm -vi -- "$(pathof disk)"
exec rm -vi -- "$(diskpath)"
}
# List available disks

3
qemu/bin/diskpath Executable file
View file

@ -0,0 +1,3 @@
#!/bin/sh -e
[ -n "$QEMUSH_NAME" ]
printf %s/%s.qcow2\\n ~/disks "$QEMUSH_NAME"

View file

@ -1,22 +0,0 @@
#!/bin/sh -e
# Check if QEMUSH_NAME variable is initialized, abort if not
[ -n "$QEMUSH_NAME" ]
# Choose the base dir to print according to argv[1]
case "$1" in
socket)
path="${HOME}/sockets"
;;
disk)
path="${HOME}/disks"
;;
*)
false
;;
esac
# Create the base dir if it doesn't exist and print the path of the
# ressource
mkdir -p -- "$path"
printf %s/%s\\n "$path" "$QEMUSH_NAME"

3
qemu/bin/sockpath Executable file
View file

@ -0,0 +1,3 @@
#!/bin/sh -e
[ -n "$QEMUSH_NAME" ]
printf %s/%s ~/sockets "$QEMUSH_NAME"

View file

@ -9,7 +9,7 @@ ram_kilo = virtual_memory().available // 2 // 1024
command = [
'qemu-system-x86_64',
'-enable-kvm',
'-enable-kvm', '-daemonize',
'-M', 'q35',
'-cpu', 'host', '-smp', str(nproc),
'-m', '{}K'.format(ram_kilo),

View file

@ -6,8 +6,8 @@ export QEMUSH_NAME
# Launch the virtual machine
exec kvm-spice \
-monitor "unix:$(pathof socket)" \
-drive file="$(pathof disk)",if=virtio \
-monitor "unix:$(sockpath),server,nowait" \
-drive file="$(diskpath)",if=virtio \
-net user,hostname="${QEMUSH_NAME}" \
-usbdevice tablet \
-name "$QEMUSH_NAME" \

View file

@ -1,5 +0,0 @@
# Keep tmux sessions visible after exit
set -g remain-on-exit on
# Override the nologin directive
set -g default-shell /bin/sh