virt-install-debian 2.87 KB
Newer Older
Server Team's avatar
Server Team committed
1
#!/bin/bash
Server Team's avatar
Server Team committed
2

Server Team's avatar
Server Team committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
MACHINE_CONF_FILE="/root/machine.conf"
if [ ! -f "$MACHINE_CONF_FILE" ]; then
	echo "you must supply the path to a config file"
	exit 99
fi

source $MACHINE_CONF_FILE

# we should now have the following variables

echo "SERVER_NAME $SERVER_NAME"

echo "NET_IPV4_MAC $NET_IPV4_MAC"
echo "NET_IPV4_ADDRESS $NET_IPV4_ADDRESS"
echo "NET_IPV4_GATEWAY $NET_IPV4_GATEWAY"
echo "NET_IPV4_BROADCAST $NET_IPV4_BROADCAST"
echo "NET_IPV4_NETMASK $NET_IPV4_NETMASK"

read -p "Do you cant to creat a machine with this config? " -n 1 -r
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
    exit 1
fi
Server Team's avatar
Server Team committed
26

Server Team's avatar
Server Team committed
27
28
29
30
31
32
33
34
###########################################
###########################################
###                                     ###
### no customisation below this point   ###
###                                     ###
###########################################
###########################################

35
36
37
38
39
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=740895
#NET_IPV6_ADDRESS="2a01:4f8:141:21a3::3"
#NET_IPV6_NETMASK="64"
#NET_IPV6_GATEWAY="fe80::1"

40
41
HOST_NAME=$SERVER_NAME

Server Team's avatar
Server Team committed
42
# create passwd
Server Team's avatar
Server Team committed
43
44
45
PASSWORD=$(makepasswd --minchars=10 --maxchars=12)
echo "Generated random password"
echo "ADD TO PASSWORD STORE/KEEP IN SAFE PLACE"
Server Team's avatar
Server Team committed
46
echo $PASSWORD
Server Team's avatar
Server Team committed
47
48
49
50
51
52
53
read -p "Are you reay to continue? " -n 1 -r
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
    exit 1
fi


Server Team's avatar
Server Team committed
54
55
56
57
58
59
60
# note on preseeding
# file must be injected in the root/intrd filesysetm
# if file is not named preseed.cfg the file name must be passed to the kerne like preseed/file=/some/whatever.cfg
# see here for the full story:
# https://www.debian.org/releases/stable/amd64/apbs02.html.en#preseed-loading


Server Team's avatar
Server Team committed
61
62
#VOLUME=$SERVER_NAME
#--network bridge=br0 \
63
#--network bridge=br-ext,mac=$NET_IPV4_MAC,model=virtio \
Server Team's avatar
Server Team committed
64

Server Team's avatar
Server Team committed
65
virt-install \
Server Team's avatar
Server Team committed
66
--connect qemu:///system \
Server Team's avatar
Server Team committed
67
--name $SERVER_NAME \
Server Team's avatar
Server Team committed
68
--ram 2048 \
69
--disk pool=vgpool,size=50,bus=ide \
Server Team's avatar
Server Team committed
70
71
72
--vcpus 2 \
--os-type linux \
--os-variant generic \
73
--network bridge=br-int,model=virtio \
Server Team's avatar
Server Team committed
74
75
--graphics none \
--console pty,target_type=serial \
76
--location 'http://mirror.hetzner.de/debian/packages/dists/jessie/main/installer-amd64/' \
Peter Niederlag's avatar
Peter Niederlag committed
77
--initrd-inject '/usr/local/virtinstaller/preseed.cfg' \
78
--extra-args "auto=true netcfg/get_hostname=$HOST_NAME netcfg/hostname=$HOST_NAME passwd/root-password=$PASSWORD passwd/root-password-again=$PASSWORD netcfg/get_ipaddress=$NET_IPV4_ADDRESS netcfg/get_netmask=$NET_IPV4_NETMASK netcfg/get_gateway=$NET_IPV4_GATEWAY console=ttyS0,115200n8 serial"
Steffen Gebert's avatar
Steffen Gebert committed
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

echo "Finished with virt-install."
echo "Doing some aftermath..."
# shutdown
virsh shutdown $SERVER_NAME

# copy ssh-keys of admins into machine
# generate ssh-authorized keys so they can be uploaded into the root-account
SCRIPT_PATH=$(dirname $([ -L $0 ] && readlink -f $0 || echo $0))
$SCRIPT_PATH/gatherkeys.sh > $SCRIPT_PATH/authorized_keys
virt-copy-in -d $SERVER_NAME $SCRIPT_PATH/authorized_keys /root/.ssh/

# start again
virsh start $SERVER_NAME

# set domain to autostart
virsh autostart $SERVER_NAME