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

View file

@ -18,6 +18,7 @@ exec_as qemu "$@"
# Directories used in the program # Directories used in the program
bin="${HOME}/launchers" bin="${HOME}/launchers"
images="${HOME}/disks" images="${HOME}/disks"
sockets="${HOME}/sockets"
# Environment # Environment
PATH="${bin}:${HOME}/bin:${PATH}" PATH="${bin}:${HOME}/bin:${PATH}"
@ -62,7 +63,6 @@ ${name}: usage:
${name} help - show this help ${name} help - show this help
${name} add <path to script> [<VM name>] - add a launching script ${name} add <path to script> [<VM name>] - add a launching script
${name} do <command> - run shell input as user qemu ${name} do <command> - run shell input as user qemu
${name} depcheck - check if script dependencies are met
EOF EOF
} }
@ -73,29 +73,27 @@ error_usage() {
return 1 return 1
} }
# Function to start a virtual machine ; fails if the virtual machine is # Function to start a virtual machine
# already started thanks to tmux
public_start() { public_start() {
QEMUSH_NAME="$1" QEMUSH_NAME="$1"
shift shift
exec tmux new-session \ exec "$QEMUSH_NAME" "$@"
-s "$QEMUSH_NAME" \
"$QEMUSH_NAME" \
"$@"
} }
# Attach to a running virtual machine output, the latest opened if no # Attach to a running virtual machine output, the latest opened if no
# argument is provided # argument is provided
public_watch() { 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 # List running virtual machines
public_active() { public_active() {
exec tmux list-sessions echo "Running machines:"
exec ls "$sockets"
} }
# List available virtual machines entrypoints # List available virtual machines entrypoints
@ -109,7 +107,7 @@ 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
@ -117,7 +115,7 @@ public_diskrm() {
QEMUSH_NAME="$1" QEMUSH_NAME="$1"
shift shift
exec rm -vi -- "$(pathof disk)" exec rm -vi -- "$(diskpath)"
} }
# List available disks # 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 = [ command = [
'qemu-system-x86_64', 'qemu-system-x86_64',
'-enable-kvm', '-enable-kvm', '-daemonize',
'-M', 'q35', '-M', 'q35',
'-cpu', 'host', '-smp', str(nproc), '-cpu', 'host', '-smp', str(nproc),
'-m', '{}K'.format(ram_kilo), '-m', '{}K'.format(ram_kilo),

View file

@ -6,8 +6,8 @@ export QEMUSH_NAME
# Launch the virtual machine # Launch the virtual machine
exec kvm-spice \ exec kvm-spice \
-monitor "unix:$(pathof socket)" \ -monitor "unix:$(sockpath),server,nowait" \
-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" \

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