Compare commits
No commits in common. "5274a5056e13f9d6eb11df71a9a2b3e38ef19e0d" and "50603a52f661380ee1f4ec3e2df959a8173422d9" have entirely different histories.
5274a5056e
...
50603a52f6
8 changed files with 46 additions and 21 deletions
|
@ -33,6 +33,7 @@ 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
|
||||||
|
@ -47,10 +48,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
|
||||||
- `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
|
||||||
|
@ -93,6 +94,7 @@ 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
|
||||||
|
|
||||||
|
|
22
bin/qemush
22
bin/qemush
|
@ -18,7 +18,6 @@ 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}"
|
||||||
|
@ -63,6 +62,7 @@ ${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,27 +73,29 @@ error_usage() {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to start a virtual machine
|
# Function to start a virtual machine ; fails if the virtual machine is
|
||||||
|
# already started thanks to tmux
|
||||||
public_start() {
|
public_start() {
|
||||||
QEMUSH_NAME="$1"
|
QEMUSH_NAME="$1"
|
||||||
shift
|
shift
|
||||||
|
|
||||||
exec "$QEMUSH_NAME" "$@"
|
exec tmux new-session \
|
||||||
|
-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() {
|
||||||
QEMUSH_NAME="$1"
|
[ -n "$1" ] && set -- -t "$1"
|
||||||
shift
|
|
||||||
|
|
||||||
socat -,echo=0,icanon=0 "UNIX-CONNECT:$(sockpath)"
|
exec tmux attach "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
# List running virtual machines
|
# List running virtual machines
|
||||||
public_active() {
|
public_active() {
|
||||||
echo "Running machines:"
|
exec tmux list-sessions
|
||||||
exec ls "$sockets"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# List available virtual machines entrypoints
|
# List available virtual machines entrypoints
|
||||||
|
@ -107,7 +109,7 @@ 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
|
||||||
|
@ -115,7 +117,7 @@ public_diskrm() {
|
||||||
QEMUSH_NAME="$1"
|
QEMUSH_NAME="$1"
|
||||||
shift
|
shift
|
||||||
|
|
||||||
exec rm -vi -- "$(diskpath)"
|
exec rm -vi -- "$(pathof disk)"
|
||||||
}
|
}
|
||||||
|
|
||||||
# List available disks
|
# List available disks
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
#!/bin/sh -e
|
|
||||||
[ -n "$QEMUSH_NAME" ]
|
|
||||||
printf %s/%s.qcow2\\n ~/disks "$QEMUSH_NAME"
|
|
22
qemu/bin/pathof
Executable file
22
qemu/bin/pathof
Executable file
|
@ -0,0 +1,22 @@
|
||||||
|
#!/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"
|
|
@ -1,3 +0,0 @@
|
||||||
#!/bin/sh -e
|
|
||||||
[ -n "$QEMUSH_NAME" ]
|
|
||||||
printf %s/%s ~/sockets "$QEMUSH_NAME"
|
|
|
@ -9,7 +9,7 @@ ram_kilo = virtual_memory().available // 2 // 1024
|
||||||
|
|
||||||
command = [
|
command = [
|
||||||
'qemu-system-x86_64',
|
'qemu-system-x86_64',
|
||||||
'-enable-kvm', '-daemonize',
|
'-enable-kvm',
|
||||||
'-M', 'q35',
|
'-M', 'q35',
|
||||||
'-cpu', 'host', '-smp', str(nproc),
|
'-cpu', 'host', '-smp', str(nproc),
|
||||||
'-m', '{}K'.format(ram_kilo),
|
'-m', '{}K'.format(ram_kilo),
|
||||||
|
|
|
@ -6,8 +6,8 @@ export QEMUSH_NAME
|
||||||
|
|
||||||
# Launch the virtual machine
|
# Launch the virtual machine
|
||||||
exec kvm-spice \
|
exec kvm-spice \
|
||||||
-monitor "unix:$(sockpath),server,nowait" \
|
-monitor "unix:$(pathof socket)" \
|
||||||
-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" \
|
||||||
|
|
5
qemu/tmux.conf
Normal file
5
qemu/tmux.conf
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# Keep tmux sessions visible after exit
|
||||||
|
set -g remain-on-exit on
|
||||||
|
|
||||||
|
# Override the nologin directive
|
||||||
|
set -g default-shell /bin/sh
|
Loading…
Reference in a new issue