ar08 commited on
Commit
e545035
·
verified ·
1 Parent(s): 3551e02

Update manage.sh

Browse files
Files changed (1) hide show
  1. manage.sh +71 -0
manage.sh CHANGED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Function to create a virtual disk image
4
+ create_disk_image() {
5
+ qemu-img create -f qcow2 /app/ubuntu_vm.qcow2 15G
6
+ echo "Virtual disk image created: /app/ubuntu_vm.qcow2 (15GB)"
7
+ }
8
+
9
+ # Function to download Ubuntu ISO
10
+ download_ubuntu_iso() {
11
+ wget -O /app/ubuntu-20.04-live-server-amd64.iso https://old-releases.ubuntu.com/releases/20.04.2/ubuntu-20.04.2-live-server-amd64.iso
12
+ echo "Ubuntu ISO downloaded: /app/ubuntu-20.04-live-server-amd64.iso"
13
+ }
14
+
15
+ # Function to install Ubuntu on VM
16
+ install_ubuntu_vm() {
17
+ virt-install \
18
+ --name ubuntu_vm \
19
+ --ram 2048 \
20
+ --disk path=/app/ubuntu_vm.qcow2,format=qcow2 \
21
+ --vcpus 2 \
22
+ --os-type linux \
23
+ --os-variant ubuntu20.04 \
24
+ --network bridge=virbr0,model=virtio \
25
+ --graphics none \
26
+ --console pty,target_type=serial \
27
+ --location 'http://archive.ubuntu.com/ubuntu/dists/focal/main/installer-amd64/' \
28
+ --extra-args 'console=ttyS0,115200n8 serial'
29
+ echo "Ubuntu installation initiated for VM: ubuntu_vm"
30
+ }
31
+
32
+ # Function to manage VM state
33
+ manage_vm() {
34
+ case $1 in
35
+ start)
36
+ virsh start ubuntu_vm
37
+ echo "VM started: ubuntu_vm"
38
+ ;;
39
+ stop)
40
+ virsh shutdown ubuntu_vm
41
+ echo "VM stopped: ubuntu_vm"
42
+ ;;
43
+ console)
44
+ virsh console ubuntu_vm
45
+ ;;
46
+ *)
47
+ echo "Usage: $0 {start|stop|console}"
48
+ ;;
49
+ esac
50
+ }
51
+
52
+ # Main menu
53
+ case $1 in
54
+ create-disk)
55
+ create_disk_image
56
+ ;;
57
+ download-iso)
58
+ download_ubuntu_iso
59
+ ;;
60
+ install-vm)
61
+ install_ubuntu_vm
62
+ ;;
63
+ manage-vm)
64
+ manage_vm $2
65
+ ;;
66
+ *)
67
+ echo "Usage: $0 {create-disk|download-iso|install-vm|manage-vm {start|stop|console}}"
68
+ ;;
69
+ esac
70
+
71
+