-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQEMU-QuickBoot.sh
278 lines (204 loc) · 11.5 KB
/
QEMU-QuickBoot.sh
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#!/bin/bash
# Set the GTK theme to dark
export GTK_THEME=Orchis:dark
# Calculate 30% wider size for the first Zenity window
original_width=440
original_height=320
smaller_width=$(awk "BEGIN {printf \"%.0f\n\", $original_width * 0.5}")
smaller_height=$(awk "BEGIN {printf \"%.0f\n\", $original_height * 0.7}")
bigger_width=$(awk "BEGIN {printf \"%.0f\n\", $original_width * 1.3}")
geometry="${smaller_width}x${smaller_height}"
extra_disks=""
while true; do
# Option to choose boot source using Zenity
boot_source_choice=$(zenity --list --title="Select VM Boot Source" --column="Option" --width="$original_width" --height="$smaller_height" \
"Boot from connected device" "Boot from file (.vhd, .img, .iso)" "ISO & Drive (Virtual disk or Physical Device)")
if [ $? -ne 0 ]; then
exit 1
fi
case $boot_source_choice in
"Boot from connected device")
drives=$(lsblk -o NAME,SIZE -lnp -d -e 7,11)
selected_drive=$(zenity --list --title="Select Disk" --column="Drive" --column="Size" --text "Select a disk:" --width="$bigger_width" --height="$smaller_height" $drives)
if [ $? -ne 0 ]; then
exit 1
fi
# Prompt for extra disks
add_extra_disk=$(zenity --list --title="Add Extra Disk" --column="Option" --text="Do you want to add an extra disk?" --width="$smaller_width" --height="$smaller_height" \
"Yes" "No")
if [ $? -ne 0 ]; then
exit 1
fi
if [ "$add_extra_disk" == "Yes" ]; then
extra_disk_id=1
while true; do
extra_disk_choice=$(zenity --list --title="Select Extra Disk Type" --column="Option" --width="$bigger_width" --height="$smaller_height" \
"Select Virtual Disk" "Select Physical Device" "Done")
if [ $? -ne 0 ]; then
exit 1
fi
if [ "$extra_disk_choice" == "Select Virtual Disk" ]; then
extra_disk=$(zenity --file-selection --title="Select Extra Virtual Disk (.img, .vhd, .vhdx)" --width="$smaller_width" --height="$smaller_height")
if [ $? -ne 0 ] || [ ! -f "$extra_disk" ]; then
continue
fi
extra_disks="$extra_disks -drive file=\"$extra_disk\",format=raw,id=extra_drive$extra_disk_id"
extra_disk_id=$((extra_disk_id + 1))
elif [ "$extra_disk_choice" == "Select Physical Device" ]; then
drives=$(lsblk -o NAME,SIZE -lnp -d -e 7,11)
extra_disk=$(zenity --list --title="Select Extra Physical Device" --column="Drive" --column="Size" --text "Select an extra physical device:" --width="$bigger_width" --height="$smaller_height" $drives)
if [ $? -ne 0 ]; then
exit 1
fi
extra_disks="$extra_disks -drive file=\"$extra_disk\",format=raw,id=extra_drive$extra_disk_id"
extra_disk_id=$((extra_disk_id + 1))
elif [ "$extra_disk_choice" == "Done" ]; then
break
else
continue
fi
done
fi
boot_mode=$(zenity --list --title="Select Boot Mode" --column="Boot Mode" "BIOS" "UEFI" --width="$smaller_width" --height="$smaller_height")
if [ $? -ne 0 ]; then
exit 1
fi
;;
"Boot from file (.vhd, .img, .iso)")
selected_drive=$(zenity --file-selection --title="Select Virtual Disk (.vhd, .img, .iso)" --width="$smaller_width" --height="$smaller_height")
if [ $? -ne 0 ] || [ ! -f "$selected_drive" ]; then
continue
fi
# Prompt for extra disks
add_extra_disk=$(zenity --list --title="Add Extra Disk" --column="Option" --text="Do you want to add an extra disk?" --width="$smaller_width" --height="$smaller_height" \
"Yes" "No")
if [ $? -ne 0 ]; then
exit 1
fi
if [ "$add_extra_disk" == "Yes" ]; then
extra_disk_id=1
while true; do
extra_disk_choice=$(zenity --list --title="Select Extra Disk Type" --column="Option" --width="$bigger_width" --height="$smaller_height" \
"Select Virtual Disk" "Select Physical Device" "Done")
if [ $? -ne 0 ]; then
exit 1
fi
if [ "$extra_disk_choice" == "Select Virtual Disk" ]; then
extra_disk=$(zenity --file-selection --title="Select Extra Virtual Disk (.img, .vhd, .vhdx)" --width="$smaller_width" --height="$smaller_height")
if [ $? -ne 0 ] || [ ! -f "$extra_disk" ]; then
continue
fi
extra_disks="$extra_disks -drive file=\"$extra_disk\",format=raw,id=extra_drive$extra_disk_id"
extra_disk_id=$((extra_disk_id + 1))
elif [ "$extra_disk_choice" == "Select Physical Device" ]; then
drives=$(lsblk -o NAME,SIZE -lnp -d -e 7,11)
extra_disk=$(zenity --list --title="Select Extra Physical Device" --column="Drive" --column="Size" --text "Select an extra physical device:" --width="$bigger_width" --height="$smaller_height" $drives)
if [ $? -ne 0 ]; then
exit 1
fi
extra_disks="$extra_disks -drive file=\"$extra_disk\",format=raw,id=extra_drive$extra_disk_id"
extra_disk_id=$((extra_disk_id + 1))
elif [ "$extra_disk_choice" == "Done" ]; then
break
else
continue
fi
done
fi
boot_mode=$(zenity --list --title="Select Boot Mode" --column="Boot Mode" "BIOS" "UEFI" --width="$smaller_width" --height="$smaller_height")
if [ $? -ne 0 ]; then
exit 1
fi
;;
"ISO & Drive (Virtual disk or Physical Device)")
iso_path=$(zenity --file-selection --title="Select .ISO file" --width="$smaller_width" --height="$smaller_height")
if [ $? -ne 0 ] || [ ! -f "$iso_path" ]; then
continue
fi
selected_drive=$(zenity --list --title="Select Virtual Disk or Physical Device" --column="Option" --width="$bigger_width" --height="$smaller_height" \
"Select Virtual Disk" "Select Physical Device")
if [ $? -ne 0 ]; then
exit 1
fi
if [ "$selected_drive" == "Select Virtual Disk" ]; then
selected_drive=$(zenity --file-selection --title="Select Virtual Disk (.img, .vhd, .vhdx)" --width="$smaller_width" --height="$smaller_height")
if [ $? -ne 0 ] || [ ! -f "$selected_drive" ]; then
continue
fi
elif [ "$selected_drive" == "Select Physical Device" ]; then
drives=$(lsblk -o NAME,SIZE -lnp -d -e 7,11)
selected_drive=$(zenity --list --title="Select Physical Device" --column="Drive" --column="Size" --text "Select a physical device:" --width="$bigger_width" --height="$smaller_height" $drives)
if [ $? -ne 0 ]; then
exit 1
fi
else
continue
fi
# Prompt for extra disks
add_extra_disk=$(zenity --list --title="Add Extra Disk" --column="Option" --text="Do you want to add an extra disk?" --width="$smaller_width" --height="$smaller_height" \
"Yes" "No")
if [ $? -ne 0 ]; then
exit 1
fi
if [ "$add_extra_disk" == "Yes" ]; then
extra_disk_id=1
while true; do
extra_disk_choice=$(zenity --list --title="Select Extra Disk Type" --column="Option" --width="$bigger_width" --height="$smaller_height" \
"Select Virtual Disk" "Select Physical Device" "Done")
if [ $? -ne 0 ]; then
exit 1
fi
if [ "$extra_disk_choice" == "Select Virtual Disk" ]; then
extra_disk=$(zenity --file-selection --title="Select Extra Virtual Disk (.img, .vhd, .vhdx)" --width="$smaller_width" --height="$smaller_height")
if [ $? -ne 0 ] || [ ! -f "$extra_disk" ]; then
continue
fi
extra_disks="$extra_disks -drive file=\"$extra_disk\",format=raw,id=extra_drive$extra_disk_id"
extra_disk_id=$((extra_disk_id + 1))
elif [ "$extra_disk_choice" == "Select Physical Device" ]; then
drives=$(lsblk -o NAME,SIZE -lnp -d -e 7,11)
extra_disk=$(zenity --list --title="Select Extra Physical Device" --column="Drive" --column="Size" --text "Select an extra physical device:" --width="$bigger_width" --height="$smaller_height" $drives)
if [ $? -ne 0 ]; then
exit 1
fi
extra_disks="$extra_disks -drive file=\"$extra_disk\",format=raw,id=extra_drive$extra_disk_id"
extra_disk_id=$((extra_disk_id + 1))
elif [ "$extra_disk_choice" == "Done" ]; then
break
else
continue
fi
done
fi
boot_mode=$(zenity --list --title="Select Boot Mode" --column="Boot Mode" "BIOS" "UEFI" --width="$smaller_width" --height="$smaller_height")
if [ $? -ne 0 ]; then
exit 1
fi
;;
*)
continue
;;
esac
ram_size=$(zenity --entry --title="Enter RAM Size" --text "Enter the amount of RAM for the VM (in MB):" --width="$smaller_width" --height="$smaller_height")
if [ $? -ne 0 ] || ! [[ "$ram_size" =~ ^[1-9][0-9]*$ ]]; then
continue
fi
# Print the selected drive, extra disks, boot mode, and RAM size for debugging
echo -e "\nSelected Drive: $selected_drive"
echo "Extra Disks: $extra_disks"
echo "Boot Mode: $boot_mode"
echo "RAM Size: $ram_size MB"
# Start QEMU VM with the specified parameters
qemu_command="qemu-system-x86_64 -enable-kvm -cpu host -smp 4 -m ${ram_size}M -drive file=\"$selected_drive\",format=raw -cdrom \"$iso_path\" -boot order=dc -netdev user,id=net0,hostfwd=tcp::2222-:22 -device e1000,netdev=net0 $extra_disks"
if [ "$boot_mode" == "UEFI" ]; then
qemu_command="qemu-system-x86_64 -enable-kvm -cpu host -smp 4 -m ${ram_size}M -drive file=\"$selected_drive\",format=raw -cdrom \"$iso_path\" -bios /usr/share/qemu/OVMF.fd -boot order=dc -netdev user,id=net0,hostfwd=tcp::2222-:22 -device e1000,netdev=net0 $extra_disks"
fi
# Run QEMU command
eval $qemu_command
# Combine notifications and prompt in a single Zenity window
zenity --question --title="QEMU - QuickBoot" --text="QuickBoot another VM?" --width="$smaller_width" --height="$smaller_height"
if [ $? -ne 0 ]; then
break
fi
done
# End of script