-
Notifications
You must be signed in to change notification settings - Fork 9
/
initMicroOSSetup
153 lines (129 loc) · 4.19 KB
/
initMicroOSSetup
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/bash
set -e
if [ -z "$DISK0" ] ; then
if [ -e /dev/nvme0n1 ] ; then
DISK0="/dev/nvme0n1"
PARTITIONSUFFIX="p"
elif [ -e /dev/sda ] ; then
DISK0="/dev/sda"
PARTITIONSUFFIX=""
else
echo "No suitable DISK0 found"
exit -1
fi
fi
if [ -z "$DISK1" ] ; then
if [ -e /dev/nvme1n1 ] ; then
DISK1="/dev/nvme1n1"
elif [ -e /dev/nvme0n2 ] ; then
DISK1="/dev/nvme0n2"
elif [ -e /dev/sdb ] ; then
DISK1="/dev/sdb"
else
echo "No suitable DISK1 found, will not create a RAID"
fi
fi
: ${GUI:="SSH"}
if [ "$GUI" = "VNC" ] ; then
GUICMD="vnc=1 vncpassword=\"12345678\""
elif [ "$GUI" = "SSH" ] ; then
GUICMD="ssh=1 ssh.password=\"12345678\""
else
echo "Invalid GUI type: $GUI"
exit 1
fi
: ${DOWNLOAD_BASE:="http://download.opensuse.org/tumbleweed/repo/oss/boot/x86_64/loader/"}
DISK0SIZE=`lsblk -b --output SIZE -n -d $DISK0`
if [ $DISK0SIZE -gt 214748364800 ] ; then #200G
: ${VAR_PARTITION:=1}
: ${SWAPSIZE:=32G}
: ${ROOTSIZE:=40G}
elif [ $DISK0SIZE -gt 107374182400 ] ; then #100G
: ${VAR_PARTITION:=1}
: ${SWAPSIZE:=16G}
: ${ROOTSIZE:=40G}
elif [ $DISK0SIZE -gt 53687091200 ] ; then #50G
: ${VAR_PARTITION:=0}
: ${SWAPSIZE:=8G}
else
: ${VAR_PARTITION:=0}
: ${SWAPSIZE:=4G}
fi
echo "####################################"
echo "# Install required packages to the #"
echo "# rescue system #"
echo "####################################"
echo
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install --assume-yes --show-progress kexec-tools aria2 btrfs-progs net-tools
echo "####################################"
echo "# Creating partitions on $DISK0 #"
echo "####################################"
echo
if [ $VAR_PARTITION -eq 1 ] ; then
PARTITION_TABLE="
label: gpt
,2M,21686148-6449-6E6F-744E-656564454649
,${SWAPSIZE},0657FD6D-A4AB-43C4-84E5-0933C84B4F4F
,${ROOTSIZE},4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709
;
"
else
echo "Do not create a separate /var partition"
PARTITION_TABLE="
label: gpt
,2M,21686148-6449-6E6F-744E-656564454649
,${SWAPSIZE},0657FD6D-A4AB-43C4-84E5-0933C84B4F4F
,,4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709
"
fi
echo "Paritition table:"
echo "$PARTITION_TABLE"
echo "$PARTITION_TABLE" | sfdisk $DISK0
if [ -e "$DISK1" ] ; then
echo "####################################"
echo "# Creating partitions on $DISK1 #"
echo "####################################"
echo
echo "$PARTITION_TABLE" | sfdisk $DISK1
fi
echo "####################################"
echo "# Creating filesystems #"
echo "####################################"
echo
mkswap ${DISK0}${PARTITIONSUFFIX}2
if [ -e "$DISK1" ] ; then
mkswap ${DISK1}${PARTITIONSUFFIX}2
mkfs.btrfs -f -m raid1 -d raid1 -L root -f ${DISK0}${PARTITIONSUFFIX}3 ${DISK1}${PARTITIONSUFFIX}3
if [ $VAR_PARTITION -eq 1 ] ; then
mkfs.btrfs -f -m raid1 -d raid1 -L data -f ${DISK0}${PARTITIONSUFFIX}4 ${DISK1}${PARTITIONSUFFIX}4
fi
else
mkfs.btrfs -f -L root ${DISK0}${PARTITIONSUFFIX}3
if [ $VAR_PARTITION -eq 1 ] ; then
mkfs.btrfs -f -L data ${DISK0}${PARTITIONSUFFIX}4
fi
fi
echo "####################################"
echo "# Download installation system #"
echo "####################################"
echo
wget --output-document=initrd.install ${DOWNLOAD_BASE}initrd
wget --output-document=vmlinuz.install ${DOWNLOAD_BASE}linux
echo "####################################"
echo "# Switching to installation system #"
echo "####################################"
echo
NETDEV=`ip -o route get to 1.1.1.1 | sed -n 's/.*dev \([a-z0-9.]\+\).*/\1/p'`
IP=`ip -o route get to 1.1.1.1 | sed -n 's/.*src \([0-9.]\+\).*/\1/p'`
GW=`ip -o route get to 1.1.1.1 | sed -n 's/.*via \([0-9.]\+\).*/\1/p'`
NETMASK=`ifconfig "$NETDEV" | awk '/netmask/{ print $4;}'`
COMMANDLINE="noapic $GUICMD install=http://download.opensuse.org/tumbleweed/repo/oss/ hostip=$IP netmask=$NETMASK gateway=$GW nameserver=1.1.1.1"
echo "Commandline for kexec: $COMMANDLINE"
kexec -l vmlinuz.install --initrd=initrd.install --command-line="$COMMANDLINE"
echo "####################################"
echo "# Ready #"
echo "####################################"
echo
echo "Everything set up, run the following command to switch to the installation system:"
echo " kexec -e"