summaryrefslogtreecommitdiff
path: root/createvm.sh
blob: db0c870d0f76976206ee19d1676ac38bdaba452d (plain)
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
#!/bin/bash

# configuration

NAME=arch32
HOST=192.168.130.1
NETMASK=255.255.255.0
PREFIX=24
CLIENT=192.168.130.101

vm_is_running() {
  if [ "$(virsh domstate $1 2>/dev/null)" == "running" ]; then
    return 0
  else
    return 1
  fi
}

wait_for_vm_to_stop() {
  while vm_is_running $1; do
    sleep 1
  done
}

mount -o loop,ro /data/arch32/mirror/archisos/archlinux-2019.03.07-i686.iso archiso

#darkhttpd . --port 8088 &

virt-install --name ${NAME} -r 1536 --vcpus=1 --os-type=linux --os-variant=archlinux \
	--disk pool=default,size=4,format=qcow2 --network bridge=br0,model=virtio \
	--arch i686 --cpu coreduo --graphics none \
	--boot kernel=archiso/arch/boot/i686/vmlinuz,initrd=archiso/arch/boot/i686/archiso.img,kernel_args="archisobasedir=archiso/arch archiso_http_srv=http://${HOST}:8088/ script=http://${HOST}:8088/archauto.sh ip=${CLIENT}:::${NETMASK}:${NAME}::off nomodeset i915.modeset=0" &

sleep 15

virsh start ${NAME}

sleep 15

wait_for_vm_to_stop ${NAME}

virsh dumpxml ${NAME} | xmllint -format - > ${NAME}.xml

# remove explicit kernel used for installation, boot from hard disk via boot manager now
xmlstarlet ed \
	--inplace \
	--delete '/domain/os/kernel' \
	--delete '/domain/os/initrd' \
	--delete '/domain/os/cmdline' \
	${NAME}.xml

# append VNC console (virt-install was with graphics=none, so we add it here)
xmlstarlet ed \
	--inplace \
	--append /domain/devices/rng --type elem -n graphics --value '' \
	--insert /domain/devices/graphics \
		--type attr -n type --value vnc \
	--insert /domain/devices/graphics \
		--type attr -n port --value 5909 \
	--insert /domain/devices/graphics \
		--type attr -n autoport --value no \
	--insert /domain/devices/graphics \
		--type attr -n listen --value '0.0.0.0' \
	-s /domain/devices/graphics --type elem -n listen --value '' \
	--insert /domain/devices/graphics/listen \
		--type attr -n type --value address \
	--insert /domain/devices/graphics/listen \
		--type attr -n address --value '0.0.0.0' \
	${NAME}.xml
	
virsh define ${NAME}.xml

virsh start ${NAME}

rm -f ${NAME}.xml

#pkill darkhttpd
umount archiso