Openbsd autoinstall » Historique » Version 6
sacha, 15/06/2021 13:57
1 | 1 | sacha | # Autoinstall OpenBSD ! |
---|---|---|---|
2 | |||
3 | * What ? |
||
4 | |||
5 | You want to build a full automated OpenBSD in 3 minuts, here is the cookbook. |
||
6 | I used it to deploy various PC Engines APU routers/firewalls. |
||
7 | |||
8 | * How ? |
||
9 | |||
10 | PXE Boot from the OpenBSD Builder |
||
11 | |||
12 | #### Packages |
||
13 | |||
14 | ~~~ |
||
15 | pkg_add bash colorls curl git gmake gnuwatch go jq python-3.6 |
||
16 | ~~~ |
||
17 | |||
18 | #### PXE Interface |
||
19 | |||
20 | ~~~ |
||
21 | builder# cat /etc/hostname.em1 |
||
22 | 172.16.16.254/24 description "PXE" |
||
23 | ~~~ |
||
24 | |||
25 | #### dhcpd |
||
26 | |||
27 | ~~~ |
||
28 | filename "auto_install"; |
||
29 | next-server 172.16.16.254; |
||
30 | subnet 172.16.16.0 netmask 255.255.255.0 { |
||
31 | range 172.16.16.1 172.16.16.2; |
||
32 | option subnet-mask 255.255.255.0; |
||
33 | option broadcast-address 172.16.16.255; |
||
34 | option routers 172.16.16.254; |
||
35 | } |
||
36 | ~~~ |
||
37 | |||
38 | ~~~ |
||
39 | echo "dhcpd_flags=em1">> /etc/rc.conf.local |
||
40 | ~~~ |
||
41 | |||
42 | #### PXE |
||
43 | |||
44 | ~~~ |
||
45 | mkdir -p /tftp/etc && chown _tftpd:_tftpd /tftp |
||
46 | cd /tftp |
||
47 | ftp http://mirrors.ircam.fr/pub/OpenBSD/6.5/amd64/pxeboot |
||
48 | ftp http://mirrors.ircam.fr/pub/OpenBSD/6.5/amd64/bsd.mp |
||
49 | ln -s pxeboot auto_install |
||
50 | ln -s bsd.rd bsd |
||
51 | |||
52 | echo " |
||
53 | stty com0 115200 |
||
54 | boot bsd |
||
55 | " > /tftp/etc/boot.conf |
||
56 | |||
57 | echo 'tftpd_flags="-4 /tftp"' >> /etc/rc.conf.local |
||
58 | /etc/rc.d/dhcpd start |
||
59 | /etc/rc.d/tftpd start |
||
60 | ~~~ |
||
61 | |||
62 | #### Copy sources |
||
63 | |||
64 | ~~~ |
||
65 | $ cd /var/www/htdocs |
||
66 | $ mkdir -p pub/OpenBSD/6.5/amd64/ |
||
67 | $ cd pub/OpenBSD/6.5/amd64/ |
||
68 | $ ftp 'ftp://ftp.nluug.nl/pub/OpenBSD/6.5/amd64/*' |
||
69 | ~~~ |
||
70 | |||
71 | ~~~ |
||
72 | signify -C -p /etc/signify/openbsd-65-base.pub -x SHA256.sig |
||
73 | ~~~ |
||
74 | |||
75 | #### /etc/httpd.conf |
||
76 | |||
77 | ~~~ |
||
78 | server "*" { |
||
79 | listen on * port 80 |
||
80 | directory auto index |
||
81 | } |
||
82 | |||
83 | 4 | sacha | ~~~ |
84 | 1 | sacha | |
85 | #### builder |
||
86 | |||
87 | ~~~ |
||
88 | #!/usr/local/bin/bash |
||
89 | |||
90 | ##################################### |
||
91 | 2 | sacha | # Builder - v1.0 |
92 | 1 | sacha | ##################################### |
93 | |||
94 | echo "==========================================" |
||
95 | echo "= OpenBSD Configuration builder - V1.1 =" |
||
96 | 2 | sacha | echo "= sacha at aquilenet.fr -=o=- 20190722 =" |
97 | 1 | sacha | echo "==========================================" |
98 | |||
99 | BPATH="/builder" |
||
100 | SKEL="$BPATH/skel" |
||
101 | WWW="$BPATH/www" |
||
102 | TGZ="$BPATH/siteXX.tgz" |
||
103 | VERSION="$(uname -r)" |
||
104 | VER="$(uname -r |tr -d '.')" |
||
105 | |||
106 | ok="n" |
||
107 | until [ $ok == "o" ]; do |
||
108 | |||
109 | read -p "Nom du site: " SITE |
||
110 | #read -p "Departement: " DEP |
||
111 | read -p "Code Postal: " CP |
||
112 | read -p "infos OSM:" OSM |
||
113 | read -p "pppoe user: " PPPOEU |
||
114 | read -p "pppoe pass: " PPPOEP |
||
115 | |||
116 | DEP=${CP:0:2} |
||
117 | |||
118 | echo "----------------------------------" |
||
119 | echo "Site : $SITE" |
||
120 | echo "Departement : $DEP" |
||
121 | echo "Code Postal : $CP" |
||
122 | echo "Infos OSM : $OSM" |
||
123 | echo "pppoe user : $PPPOEU" |
||
124 | echo "pppoe pass : $PPPOEP" |
||
125 | read -p "ok ? (o/n):" ok |
||
126 | done |
||
127 | |||
128 | |||
129 | SITEPATH="$BPATH/site/$SITE" |
||
130 | |||
131 | mkdir -p $SITEPATH/{root,etc,var/unbound/etc/,home,usr/local/bin} |
||
132 | |||
133 | cp -R $SKEL/* $SITEPATH/ |
||
134 | |||
135 | #------------------- |
||
136 | # myname |
||
137 | #------------------- |
||
138 | 2 | sacha | echo "cerbere.$SITE.mydomain.fr" > $SITEPATH/etc/myname |
139 | 1 | sacha | |
140 | #------------------- |
||
141 | # dhcpd.conf |
||
142 | #------------------- |
||
143 | sed -e "s/DEP/$DEP/g" -e "s/SITE/$SITE/g" $SKEL/etc/dhcpd.conf > $SITEPATH/etc/dhcpd.conf |
||
144 | |||
145 | #------------------- |
||
146 | # hostname.pppoe0 |
||
147 | #------------------- |
||
148 | sed -e "s/PPPOEU/$PPPOEU/g" -e "s/PPPOEP/$PPPOEP/g" $SKEL/etc/hostname.pppoe0 > $SITEPATH/etc/hostname.pppoe0 |
||
149 | |||
150 | #------------------- |
||
151 | # hostname.em2 |
||
152 | #------------------- |
||
153 | sed -e "s/DEP/$DEP/g" $SKEL/etc/hostname.em2 > $SITEPATH/etc/hostname.em2 |
||
154 | |||
155 | #------------------- |
||
156 | # unbound.conf |
||
157 | #------------------- |
||
158 | sed -e "s/DEP/$DEP/g" $SKEL/var/unbound/etc/unbound.conf > $SITEPATH/var/unbound/etc/unbound.conf |
||
159 | |||
160 | #------------------- |
||
161 | # prometheus geoash |
||
162 | #------------------- |
||
163 | |||
164 | preposition=$(curl -Ls "https://nominatim.openstreetmap.org/search/$CP $OSM?format=geojson&limit=1" |jq '.features[].geometry.coordinates| .[]') |
||
165 | position=$(echo $preposition | awk '{ for (i=NF; i>1; i--) printf("%s ",$i); print $1; }') |
||
166 | position=${position/ /,} |
||
167 | pregeoash=$(curl -Ls -w %{url_effective} -o /dev/null "http://geohash.org?q=$position") |
||
168 | geoash=${pregeoash#"http://geohash.org/"} |
||
169 | echo $geoash |
||
170 | echo 'loc{geohash="$geoash",place="'$SITE'"} 10' > $SKEL/var/node_exporter/site_location.prom |
||
171 | |||
172 | #===================================================================================================== |
||
173 | # FIN |
||
174 | |||
175 | cd $SITEPATH && tar czvf $TGZ/$SITE-site$VER.tgz . |
||
176 | rm -f $WWW/pub/OpenBSD/$VERSION/amd64/site.tgz |
||
177 | cp $TGZ/$SITE-site$VER.tgz $WWW/pub/OpenBSD/$VERSION/amd64/site$VER.tgz |
||
178 | ~~~ |
||
179 | |||
180 | ~~~ |
||
181 | builder|02:37:51|:/builder#ls -alh /builder/ |
||
182 | total 32 |
||
183 | drwxr-xr-x 6 root wheel 512B Jul 22 02:37 . |
||
184 | drwxr-xr-x 15 root wheel 512B Jul 21 18:24 .. |
||
185 | -rwxr-xr-x 1 root wheel 1.8K Jul 22 02:32 builder.sh |
||
186 | lrwxr-xr-x 1 root wheel 54B Jul 21 21:35 prometheus-build -> /home/sacha/go/src/github.com/prometheus/node_exporter |
||
187 | drwxr-xr-x 3 root wheel 512B Jul 22 01:35 site |
||
188 | drwxr-xr-x 2 root wheel 512B Jul 22 01:35 siteXX.tgz |
||
189 | drwxr-xr-x 7 root wheel 512B Jul 22 01:30 skel |
||
190 | -rw-r--r-- 1 root wheel 1.2K Jul 22 01:07 test.tgz |
||
191 | lrwxr-xr-x 1 root wheel 5B Jul 21 18:24 tftp -> /tftp |
||
192 | drwxr-xr-x 2 root wheel 512B Jul 22 00:05 tmp |
||
193 | lrwxr-xr-x 1 root wheel 16B Jul 21 18:24 www -> /var/www/htdocs/ |
||
194 | ~~~ |
||
195 | |||
196 | |||
197 | |||
198 | |||
199 | 5 | sacha | #### /tmp/i/install.resp |
200 | ~~~ |
||
201 | 1 | sacha | printf '%s' 'yourpassword' | encrypt |
202 | 5 | sacha | ~~~ |
203 | 1 | sacha | #### install.conf |
204 | |||
205 | ~~~ |
||
206 | System hostname = cerbere |
||
207 | Which network interface do you wish to configure = em0 |
||
208 | IPv4 address for em0 = dhcp |
||
209 | IPv6 address for em0 = none |
||
210 | Which network interface do you wish to configure = done |
||
211 | 2 | sacha | DNS domain name = SITE.mydomain.fr |
212 | 1 | sacha | DNS nameservers = none |
213 | Start sshd(8) by default = yes |
||
214 | Do you expect to run the X Window System = no |
||
215 | Change the default console to com0 = yes |
||
216 | Which speed should com0 use = 115200 |
||
217 | Password for root account = $2b$10$V2wkDaLWTc0jmdPEMOW5VOPeg.nS9YbJOsj6LYZMrXdRiDCGoo6yu |
||
218 | Password for user sacha = $2b$09$GWtR24VPpbZTdKyu5MZStOlyiNn2IKUy2trMI1rOJh1YjEjjNZKJa |
||
219 | Setup a user = sacha |
||
220 | Full name for user sacha = sacha |
||
221 | Public ssh key for user sacha = ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAgEA4y0oNSz3pvt2WVY/kBnlciuKoO8Nhxc+zsiaA7EOw+MRaysGZ6tymgMBpwuOCwMA8oBdgOzzlZOk7oIM1AUVjykrcrS3JPW1AOp0rjHJSDQKc8x2jBZTM8VIt1GoDTvfxoO6WTjaPJwwOxZlcS1zT6nW1y5IvO0Apz4MVKKNUZaZNa7x7MBfV59nXvWORddf3zJD/lHpK8WxfRVgYRJoLrNiqUe26GaDCKPge5fAmtgJMLvKGSzdsoCxtrY04tZw3fsdb/hJl7/Ov7dyX9NXJEU0dveFXZnLhYwKVhUa0CRxawCez202HInhp3LttYptwoX8jCjuRMlPL4+rhKtnDnze4Q81hU08xTV+TmNOzdPpVs0hY9wkQXyYrBlAGMjLQS0JQVL0hnI5FBB90GhwxzxzvD7HYLjipXXyOpdn/GZeSEG9ayjxc8kgXesT9Ogwo0GiXxPOjHz32NEJbDXXktMJZJuSqM6zD3KroB4qB6gLFZRnklqiedRTOMYJLYhC1MtdXqN/wpdlFQemYvCCGr44FJKLMDBYch4AiChVnr8VmnMzs+3ZE/3cP6tzDwgjotZc3uKN9nbEQt6SamlxW68P35ScODT1tED0JHep4qRxa5wQjYbLFQNwlWU1Vj7SxNDW0ahyZO5OZiuqtUjYzthhGECFqCtJwc/y2NTstFM= nobody@nowhere |
||
222 | Allow root ssh login = no |
||
223 | Which disk is the root disk = sd0 |
||
224 | Use (W)hole disk MBR, whole disk (G)PT, (O)penBSD area or (E)dit = O |
||
225 | Use (A)uto layout, (E)dit auto layout, or create (C)ustom layout = a |
||
226 | Which disk do you wish to initialize = done |
||
227 | Location of sets = http |
||
228 | HTTP proxy URL = none |
||
229 | HTTP Server = 172.16.16.254 |
||
230 | Pathname to the sets = pub/OpenBSD/6.5/amd64 |
||
231 | Unable to connect using https. Use http instead = yes |
||
232 | Set name(s) = -x* |
||
233 | Set name(s) = -g* |
||
234 | Set name(s) = site65.tgz |
||
235 | Checksum test for site65.tgz failed. Continue anyway = yes |
||
236 | Unverified sets: site65.tgz. Continue without verification = yes |
||
237 | Set name(s) = done |
||
238 | Directory does not contain SHA256.sig. Continue without verification = yes |
||
239 | Location of sets = done |
||
240 | What timezone are you in = Europe/Paris |
||
241 | Exit to (S)hell, (H)alt or (R)eboot = R |
||
242 | ~~~ |
||
243 | |||
244 | #### build siteXX.tgz |
||
245 | exemple copier le site65.tgz dans www/pub/OpenBSD/6.5/amd64 puis ls -al > www/pub/OpenBSD/6.5/amd64/index.txt |
||
246 | script install: install.site https://undeadly.org/cgi?action=article;sid=20080111200305 |
||
247 | |||
248 | #### install.site |
||
249 | |||
250 | ~~~ |
||
251 | usermod -G wheel sacha |
||
252 | echo 'node_exporter:\ |
||
253 | :tc=daemon: '>> /etc/login.conf |
||
254 | cap_mkdb /etc/login.conf |
||
255 | groupadd _node_exporter |
||
256 | useradd -u _node_exporter -c "Prometheus Node Exporter agent" -d /var/empty -s /sbin/nologin -L node_exporter _node_exporter |
||
257 | ~~~ |
||
258 | |||
259 | |||
260 | |||
261 | 6 | sacha | #### Sources |
262 | 1 | sacha | |
263 | http://eradman.com/posts/autoinstall-openbsd.html |
||
264 | http://149.210.185.89/openbsd-autoinstall.html |
||
265 | http://www.openbsd.org/faq/faq4.html#site |
||
266 | https://man.openbsd.org/autoinstall.8 |