-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-os.sh
More file actions
executable file
·100 lines (88 loc) · 2.62 KB
/
Copy pathtest-os.sh
File metadata and controls
executable file
·100 lines (88 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
# Script to create and run a QEMU VM with:
# - 2GB RAM
# - 16GB disk storage
# - 2 CPU threads
# - Using nebula.iso
# Configuration variables
VM_NAME="nebula-vm"
RAM_SIZE="2G"
DISK_SIZE="16G"
CPU_THREADS=2
ISO_FILE="nebula.iso"
DISK_IMG="${VM_NAME}.qcow2"
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check if the ISO file exists
if [ ! -f "$ISO_FILE" ]; then
echo -e "${YELLOW}Warning: ISO file '${ISO_FILE}' not found in the current directory.${NC}"
read -p "Do you want to continue anyway? (y/n): " CONTINUE
if [[ ! "$CONTINUE" =~ ^[Yy]$ ]]; then
echo "Exiting."
exit 1
fi
fi
# Check if QEMU is installed
if ! command -v qemu-system-x86_64 &> /dev/null; then
echo "QEMU is not installed. Installing QEMU..."
# Check the package manager and install QEMU
if command -v dnf &> /dev/null; then
sudo dnf install -y qemu-kvm
elif command -v apt-get &> /dev/null; then
sudo apt-get update
sudo apt-get install -y qemu-kvm qemu-system-x86
elif command -v pacman &> /dev/null; then
sudo pacman -S qemu
else
echo "Could not detect package manager. Please install QEMU manually."
exit 1
fi
fi
# Check if disk image already exists
if [ -f "$DISK_IMG" ]; then
echo -e "${YELLOW}Disk image '${DISK_IMG}' already exists.${NC}"
read -p "Do you want to create a new one? This will delete the existing one. (y/n): " CREATE_NEW
if [[ "$CREATE_NEW" =~ ^[Yy]$ ]]; then
rm "$DISK_IMG"
else
echo "Using existing disk image."
fi
fi
# Create disk image if it doesn't exist
if [ ! -f "$DISK_IMG" ]; then
echo "Creating disk image '${DISK_IMG}' with size ${DISK_SIZE}..."
qemu-img create -f qcow2 "$DISK_IMG" "$DISK_SIZE"
if [ $? -ne 0 ]; then
echo "Failed to create disk image. Exiting."
exit 1
fi
echo -e "${GREEN}Disk image created successfully.${NC}"
fi
# Run the VM
echo -e "${GREEN}Starting QEMU VM with:${NC}"
echo " - RAM: $RAM_SIZE"
echo " - Disk: $DISK_IMG ($DISK_SIZE)"
echo " - CPU Threads: $CPU_THREADS"
echo " - ISO: $ISO_FILE"
echo
qemu-system-x86_64 \
-name "$VM_NAME" \
-m "$RAM_SIZE" \
-smp "$CPU_THREADS" \
-boot d \
-drive file="$DISK_IMG",format=qcow2 \
-cdrom "$ISO_FILE" \
-enable-kvm \
-machine type=q35,accel=kvm \
-device virtio-net-pci,netdev=net0 \
-netdev user,id=net0 \
-display gtk
# Check if QEMU exited successfully
if [ $? -eq 0 ]; then
echo -e "${GREEN}VM session ended normally.${NC}"
else
echo -e "${YELLOW}VM session ended with an error code: $?${NC}"
fi
exit 0