feat: add rules and guidelines for Cloonar Assistant LLM
This commit is contained in:
@@ -2,12 +2,11 @@
|
||||
set -Euo pipefail
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# This script sets up and launches a QEMU virtual machine with OVMF (UEFI).
|
||||
# It checks for the necessary files, creates directories/images as needed,
|
||||
# and provides clear, user-friendly output along the way.
|
||||
# This script sets up and launches (or stops) a QEMU virtual machine with OVMF.
|
||||
#
|
||||
# Usage:
|
||||
# ./run-vm.sh [install]
|
||||
# - Pass "install" to attach the ISO as a CD-ROM for installation.
|
||||
# ./run-vm.sh [install] # starts (and backgrounds) the VM; use "install" to attach the ISO
|
||||
# ./run-vm.sh stop # kills the running QEMU VM (reads PID from .vm/qemu.pid)
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
# Paths to OVMF firmware (pflash)
|
||||
@@ -17,9 +16,33 @@ OVMF_VARS_DEFAULT="/run/libvirt/nix-ovmf/OVMF_VARS.fd"
|
||||
# Determine where this script lives and compute related paths
|
||||
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
|
||||
TARGET_DIR=$(readlink -f "$SCRIPT_DIR/../.vm")
|
||||
OVMF_VARS_PATH=$(readlink -f "$SCRIPT_DIR/../.vm/OVMF_VARS-myvm.fd")
|
||||
IMG_PATH=$(readlink -f "$SCRIPT_DIR/../.vm/disk.img")
|
||||
OVMF_VARS_PATH="$TARGET_DIR/OVMF_VARS-myvm.fd"
|
||||
IMG_PATH="$TARGET_DIR/disk.img"
|
||||
ISO_DIR=$(readlink -f "$SCRIPT_DIR/../iso/result/iso")
|
||||
PID_FILE="$TARGET_DIR/qemu.pid"
|
||||
|
||||
# If first argument is "stop", then kill the running VM and exit:
|
||||
if [ "${1-}" = "stop" ]; then
|
||||
if [ -f "$PID_FILE" ]; then
|
||||
VM_PID=$(<"$PID_FILE")
|
||||
if kill -0 "$VM_PID" 2>/dev/null; then
|
||||
echo "Killing QEMU (PID $VM_PID)..."
|
||||
kill "$VM_PID"
|
||||
# Optionally wait for it to die:
|
||||
wait "$VM_PID" 2>/dev/null || true
|
||||
echo "✅ VM stopped."
|
||||
rm -f "$PID_FILE"
|
||||
exit 0
|
||||
else
|
||||
echo "⚠️ No running QEMU process with PID $VM_PID. Removing stale PID file."
|
||||
rm -f "$PID_FILE"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "⚠️ No PID file found at $PID_FILE. Is the VM running?"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "============================================================"
|
||||
@@ -92,7 +115,8 @@ fi
|
||||
|
||||
if [ "$INSTALL_MODE" -eq 1 ]; then
|
||||
echo "[5/6] Install mode enabled: CD-ROM will be attached"
|
||||
CDROM_OPTS="-drive file=\"$ISO_FILE\",format=raw,if=none,media=cdrom,id=cd1,readonly=on -device ahci,id=ahci0 -device ide-cd,bus=ahci0.0,drive=cd1,bootindex=1"
|
||||
CDROM_OPTS="-drive file=\"$ISO_FILE\",format=raw,if=none,media=cdrom,id=cd1,readonly=on \
|
||||
-device ahci,id=ahci0 -device ide-cd,bus=ahci0.0,drive=cd1,bootindex=1"
|
||||
else
|
||||
echo "[5/6] Normal boot mode: No CD-ROM attached"
|
||||
CDROM_OPTS=""
|
||||
@@ -100,9 +124,9 @@ fi
|
||||
echo
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# 6. Launch QEMU
|
||||
# 6. Launch QEMU (in the background)
|
||||
# -----------------------------------------------------------------------------
|
||||
echo "[6/6] Launching QEMU VM now..."
|
||||
echo "[6/6] Launching QEMU VM now (in background)..."
|
||||
echo "------------------------------------------------------------"
|
||||
echo " • Machine: q35, KVM acceleration"
|
||||
echo " • Memory: 4096 MB"
|
||||
@@ -122,7 +146,7 @@ echo
|
||||
# Construct network options
|
||||
NET_OPTS="-netdev user,id=net0,hostfwd=tcp::2222-:22 -device e1000,netdev=net0"
|
||||
|
||||
# Run QEMU using eval to allow variable expansion in CDROM_OPTS
|
||||
# Run QEMU in the background and store its PID
|
||||
eval qemu-system-x86_64 \
|
||||
-machine type=q35,accel=kvm \
|
||||
-m 4096 \
|
||||
@@ -137,9 +161,14 @@ eval qemu-system-x86_64 \
|
||||
$CDROM_OPTS \
|
||||
\
|
||||
$NET_OPTS \
|
||||
-vga virtio
|
||||
-vga virtio \
|
||||
&
|
||||
|
||||
VM_PID=$!
|
||||
echo "$VM_PID" > "$PID_FILE"
|
||||
echo "✅ QEMU started with PID $VM_PID. PID file: $PID_FILE"
|
||||
echo
|
||||
echo "============================================================"
|
||||
echo " QEMU VM has exited"
|
||||
echo "============================================================"
|
||||
echo "To stop the VM at any time, run:"
|
||||
echo " $0 stop"
|
||||
echo
|
||||
exit 0
|
||||
|
||||
Reference in New Issue
Block a user