-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·69 lines (55 loc) · 1.91 KB
/
install.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
#!/bin/sh -e
# A script to create debian VM as a KVM guest using virt-install in fully
# automated way based on preseed.cfg
# Domain is necessary in order to avoid debian installer to
# require manual domain entry during the install.
DOMAIN=`/bin/hostname -d` # Use domain of the host system
#DOMAIN="dp-net.com" # Alternatively, hardcode domain
# NB: See postinst.sh for ability to override domain received from
# DHCP during the install.
#DIST_URL="http://ftp.de.debian.org/debian/dists/stretch/main/installer-amd64/"
DIST_URL='http://ftp.de.debian.org/debian/dists/stretch/main/installer-amd64/'
LINUX_VARIANT="debian9"
# NB: Also see preseed.cfg for debian mirror hostname.
if [ $# -lt 1 ]
then
cat <<EOF
Usage: $0 <GUEST_NAME> [MAC_ADDRESS]"
GUEST_NAME used as guest hostname, name of the VM and image file name
MAC_ADDRESS allows to use specific MAC on the network, this is helpful
when DHCP server expects your guest to have predefined MAC
Examples:
$0 backend 52:54:00:bf:b3:86 # create guest named "backend" with given MAC
$0 wow # create guest named "wow" with random MAC
EOF
exit 1
fi
MAC="RANDOM"
if [ $# -eq 2 ]
then
MAC=$2
fi
# Fetch SSH key from github.
#wget -q https://github.com/pin.keys -O postinst/authorized_keys
# Create tarball with some stuff we would like to install into the system.
#tar cvfz postinst.tar.gz postinst
#create lvm partition
lvcreate --name ${1} --size 10G ssd
virt-install \
--connect=qemu:///system \
--name=${1} \
--memory=2048 \
--vcpus=1 \
--cpu host \
--disk /dev/ssd/${1},bus=virtio \
--initrd-inject=preseed.cfg \
--initrd-inject=postinst.sh \
--location ${DIST_URL} \
--os-type linux \
--os-variant ${LINUX_VARIANT} \
--virt-type=kvm \
--controller usb,model=none \
--graphics none \
--network bridge=br0,mac=${MAC},model=virtio \
--extra-args="auto=true hostname="${1}" domain="${DOMAIN}" console=tty0 console=ttyS0,115200n8 serial"
#rm postinst.tar.gz