-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvm.live.active.sh
executable file
·48 lines (40 loc) · 987 Bytes
/
vm.live.active.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
#!/bin/bash
# using : active virtual machine with live distribution
# author : [email protected]
# bash options
set -e
# variables
vm_type="kvm"
vm_name="lfs-live.amd64"
vm_cpus="2"
vm_ram="512"
vm_cdrom="/mnt/lfs/dist/dest/lfs-live.amd64.iso"
vm_disk_path="disk/lfs-live.amd64.vm.img"
vm_disk_size="8"
# handle for exit event
on_exit() {
echo "stop vm.$vm_name"
virsh destroy $vm_name
sudo umount "/mnt/lfs"
}
# shen exit script, kill virtual machine
trap on_exit EXIT
# mount build image
if ! mount -l | grep /mnt/lfs; then
sudo mount "disk/lfs-disk.img" "/mnt/lfs"
fi
# remove early virtual machine
if virsh list | grep $vm_name; then
virsh destroy $vm_name
fi
if virsh list --all | grep $vm_name; then
virsh undefine $vm_name
fi
# vm.install, show on window
virt-install \
--virt-type $vm_type \
--name $vm_name \
--vcpus $vm_cpus \
--ram $vm_ram \
--cdrom $vm_cdrom \
--disk path=$vm_disk_path,size=$vm_disk_size