From 2457abe3d1ca6fbf6a37b4e3c1ca6dc548f5eb94 Mon Sep 17 00:00:00 2001 From: Hippolyte Chauvin Date: Sun, 15 Oct 2023 11:32:26 +0200 Subject: [PATCH 01/10] Ajout : script startvm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit startvm permet de contrôler l'exécution de machines virtuelles en tant que l'utilisateur Unix qemu --- bin/startvm | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 bin/startvm diff --git a/bin/startvm b/bin/startvm new file mode 100755 index 0000000..1774c05 --- /dev/null +++ b/bin/startvm @@ -0,0 +1,20 @@ +#!/bin/bash + +exec_as() { + local user="$1" + shift + + if [ "$(whoami)" != "$user" ]; then + exec sudo -u "$user" "$0" "$@" + else + cd + fi +} + +exec_as qemu "$@" || exit +PATH="./bin:${PATH}" + +vm_name="$1" +shift + +"$vm_name" "$@" From 30b1b52a1b2c50d5def82ba806157136aeeaf883 Mon Sep 17 00:00:00 2001 From: Hippolyte Chauvin Date: Sun, 15 Oct 2023 11:33:02 +0200 Subject: [PATCH 02/10] Suppression : lien symbolique windows10 --- bin/windows10 | 1 - 1 file changed, 1 deletion(-) delete mode 120000 bin/windows10 diff --git a/bin/windows10 b/bin/windows10 deleted file mode 120000 index c83465d..0000000 --- a/bin/windows10 +++ /dev/null @@ -1 +0,0 @@ -../share/qemu/scripts/windows10 \ No newline at end of file From 7f934cd200907d138bf710c08b41f22d3a80ba8c Mon Sep 17 00:00:00 2001 From: Hippolyte Chauvin Date: Sun, 15 Oct 2023 11:33:24 +0200 Subject: [PATCH 03/10] Remaniement : nouveau nom pour startvm -> qemush --- bin/{startvm => qemush} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename bin/{startvm => qemush} (100%) diff --git a/bin/startvm b/bin/qemush similarity index 100% rename from bin/startvm rename to bin/qemush From b4921b8686c05a647c8b41e416932ad81ce6d57f Mon Sep 17 00:00:00 2001 From: Hippolyte Chauvin Date: Sun, 15 Oct 2023 11:57:01 +0200 Subject: [PATCH 04/10] =?UTF-8?q?Ajout=20:=20fonctions=20dans=20qemush.=20?= =?UTF-8?q?Remaniement=20:=20screen=20g=C3=A9r=C3=A9=20par=20qemush=20pour?= =?UTF-8?q?=20les=20machines=20virtuelles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/qemush | 46 ++++++++++++++++++++++++++++-- {share/qemu => qemu}/bin/linux | 3 +- {share/qemu => qemu}/bin/windows10 | 3 +- 3 files changed, 46 insertions(+), 6 deletions(-) rename {share/qemu => qemu}/bin/linux (71%) rename {share/qemu => qemu}/bin/windows10 (82%) diff --git a/bin/qemush b/bin/qemush index 1774c05..eb8fa9b 100755 --- a/bin/qemush +++ b/bin/qemush @@ -14,7 +14,49 @@ exec_as() { exec_as qemu "$@" || exit PATH="./bin:${PATH}" -vm_name="$1" +perror() { + >&2 printf '\033[1;31mERROR:\033[0m \033[1m%s\033[0m\n' "$*" +} + +public_help() { + local name + name="$(basename "$0")" + cat << EOF +${name}: usage: + ${name} start - start a VM + ${name} watch - attach VM screen session + ${name} active - (default behaviour) list active VMs + ${name} list - list available VMs + ${name} help - show this help +EOF +} + +error_usage() { + perror "Invalid usage" + >&2 public_help + return 1 +} + +public_start() { + local vm_name="$1" + shift + + screen -d -m -S "$vm_name" "$vm_name" "$@" +} + +public_watch() { + screen -dr "$1" +} + +public_list() { + screen -ls +} + +function="$1" shift -"$vm_name" "$@" +if declare -F | cut -d \ -f 3- | grep '^public_' | sed 's/^public_//' | grep -q "^${function}$"; then + "public_${function}" "$@" +else + error_usage +fi diff --git a/share/qemu/bin/linux b/qemu/bin/linux similarity index 71% rename from share/qemu/bin/linux rename to qemu/bin/linux index 50e9f72..1cc1d29 100755 --- a/share/qemu/bin/linux +++ b/qemu/bin/linux @@ -1,7 +1,6 @@ #!/bin/sh -ex name="$(basename "$0")" -cd "$(dirname "$(readlink -f "$0")")/.." -exec screen -S "QEMU : ${name}" -d -m qemu-system-x86_64 \ +qemu-system-x86_64 \ -monitor stdio -enable-kvm \ -cpu host -smp "$(nproc)" \ -m 4G \ diff --git a/share/qemu/bin/windows10 b/qemu/bin/windows10 similarity index 82% rename from share/qemu/bin/windows10 rename to qemu/bin/windows10 index e758bf4..9bbac80 100755 --- a/share/qemu/bin/windows10 +++ b/qemu/bin/windows10 @@ -1,7 +1,6 @@ #!/bin/sh -ex name="$(basename "$0")" -cd "$(dirname "$(readlink -f "$0")")/.." -exec screen -S "QEMU : ${name}" -d -m qemu-system-x86_64 \ +qemu-system-x86_64 \ -monitor stdio -enable-kvm \ -bios /usr/share/edk2/x64/OVMF_CODE.fd \ -usb -device usb-ehci,id=ehci -device usb-host,bus=ehci.0,vendorid=1452 \ From 7db32e1bbf2059e34338c896243a7232ed4fd561 Mon Sep 17 00:00:00 2001 From: Hippolyte Chauvin Date: Sun, 15 Oct 2023 11:59:15 +0200 Subject: [PATCH 05/10] Correction : la fonction list affiche les VM disponibles. Ajout : la fonction active remplace la fonction list --- bin/qemush | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bin/qemush b/bin/qemush index eb8fa9b..d42e6b4 100755 --- a/bin/qemush +++ b/bin/qemush @@ -48,10 +48,15 @@ public_watch() { screen -dr "$1" } -public_list() { +public_active() { screen -ls } +public_list() { + echo "Available machines:" + ls --color=auto bin +} + function="$1" shift From c115dbd144b058a83b75fea33dd53eb663856282 Mon Sep 17 00:00:00 2001 From: Hippolyte Chauvin Date: Sun, 15 Oct 2023 12:08:45 +0200 Subject: [PATCH 06/10] Ajout : fonctions pour manipuler des images disque dans qemush --- bin/qemush | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/bin/qemush b/bin/qemush index d42e6b4..2a8f798 100755 --- a/bin/qemush +++ b/bin/qemush @@ -23,11 +23,14 @@ public_help() { name="$(basename "$0")" cat << EOF ${name}: usage: - ${name} start - start a VM - ${name} watch - attach VM screen session - ${name} active - (default behaviour) list active VMs - ${name} list - list available VMs - ${name} help - show this help + ${name} start - start a VM + ${name} watch - attach VM screen session + ${name} active - (default behaviour) list active VMs + ${name} list - list available VMs + ${name} help - show this help + ${name} diskls - list available disk images + ${name} diskadd - create a disk image + ${name} diskrm - delete disk image EOF } @@ -57,6 +60,23 @@ public_list() { ls --color=auto bin } +diskpath() { + printf 'images/%s.qcow2' "$1" +} + +public_diskadd() { + qemu-img create -f qcow2 "$(diskpath "$1")" "$2" +} + +public_diskrm() { + rm -vi -- "$(diskpath "$1")" +} + +public_diskls() { + echo "Available disks:" + ls --color=auto images +} + function="$1" shift From 3497bd31e9c3168687e7cd33228de9e2c1dbde9f Mon Sep 17 00:00:00 2001 From: Hippolyte Chauvin Date: Sun, 15 Oct 2023 13:50:03 +0200 Subject: [PATCH 07/10] Ajout : fonctions pour ajouter ou supprimer des VM dans qemush --- bin/qemush | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bin/qemush b/bin/qemush index 2a8f798..2b57931 100755 --- a/bin/qemush +++ b/bin/qemush @@ -31,6 +31,8 @@ ${name}: usage: ${name} diskls - list available disk images ${name} diskadd - create a disk image ${name} diskrm - delete disk image + ${name} add