-
Notifications
You must be signed in to change notification settings - Fork 5
/
zpxe.rexx
385 lines (314 loc) · 11.2 KB
/
zpxe.rexx
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
/* zPXE: REXX PXE Client for System z
zPXE is a PXE client used with Cobbler. It must be run under
z/VM. zPXE uses TFTP to first download a list of profiles,
then a specific kernel, initial RAMdisk, and PARM file. These
files are then punched to start the install process.
zPXE does not require a writeable 191 A disk. Files are
downloaded to a temporary disk (VDISK).
zPXE can also IPL a DASD disk by default. You can specify the
default dasd in ZPXE CONF, as well as the hostname of the Cobbler
server.
---
Copyright 2006-2019, Red Hat, Inc
Brad Hinson <bhinson@redhat.com>
Leo Jones <lejones@redhat.com>
Tomas Klohna <tklohna@redhat.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
/* Defaults */
CONFIG_VERSION = '1.3.0'
say 'zPXE version: ' CONFIG_VERSION
server = '' /* define server in ZPXE CONF */
iplDisk = 100 /* overridden by value in ZPXE CONF */
profilelist = PROFILE LIST T /* VDISK will be defined as T later */
profiledetail = PROFILE DETAIL T
zpxeparm = ZPXE PARM T
zpxeconf = ZPXE CONF T
config = ZPXE CONF
/* For translating strings to lowercase */
upper = xrange('A', 'Z')
lower = xrange('a', 'z')
/* Query user ID. This is used later to determine:
1. Whether a user-specific PXE profile exists.
2. Whether user is disconnected. If so, IPL the default disk.
*/
'pipe cp query' userid() '| var user'
parse value user with id . dsc .
userid = translate(id, lower, upper)
/* Useful settings normally found in PROFILE EXEC */
'cp set run on'
'cp set pf11 retrieve forward'
'cp set pf12 retrieve'
/* Make it possible to interrupt zPXE and to enter CMS even with a
specific user profile present
*/
if (dsc <> 'DSC') then do /* user is connected */
say ''
say 'Enter a non-blank character and ENTER (or two ENTERs) within 10'
say ' seconds to interrupt zPXE.'
'WAKEUP +00:10 (CONS'
/* Check for interrupt */
if rc = 6 then do
say 'zPXE interrupted, entering CMS...'
pull /* Clear Stack */
exit
end
end
/* Check for config file */
if lines(config) > 0 then do
inputline = linein(config) /* first line is server hostname/IP */
parse var inputline . server .
inputline = linein(config) /* second line is DASD disk to IPL */
parse var inputline . iplDisk .
if lines(config) > 0 then do
inputline = linein(config) /* third line is name of system in cobbler */
parse var inputline . userid .
end
end
/* Define temporary disk (VDISK) to store files */
/* z/Linux guest do not have the proper CP priv classes to */
/* issue the following two commands. */
/* 'set vdisk syslim infinite' */
/* 'set vdisk userlim infinite' */
'detach ffff' /* detach ffff if present */
'define vfb-512 as ffff blk 400000' /* 512 byte block size =~ 200 MB */
/* create a new stack */
'makebuf'
queue '1'
queue 'tmpdsk'
'format ffff t' /* format VDISK as file mode t */
/* drop the stack */
'dropbuf'
/* Link TCPMAINT disk for access to TFTP */
'link tcpmaint 592 592 rr'
'access 592 e'
/* Check whether a user-specific PXE profile exists.
If so, proceed with this. Otherwise, continue and
show the system-wide profile menu.
*/
call GetTFTP '/s390x/s_'userid 'profile.detail.t'
if lines(profiledetail) > 0 then do
/* Get user PARM and CONF containing network info */
call GetTFTP '/s390x/s_'userid'_parm' 'zpxe.parm.t'
call GetTFTP '/s390x/s_'userid'_conf' 'zpxe.conf.t'
vmfclear /* clear screen */
call CheckServer /* print server name */
say 'Profile 'userid' found'
say ''
bootRc = ParseSystemRecord() /* parse file for boot action */
if bootRc = 0 then do
say 'Booting locally...'
'detach ffff' /* detach ffff if present */
'cp ipl' iplDisk
end
/* boot default DASD */
else do
call DownloadBinaries /* download kernel and initrd */
say 'Starting install...'
say ''
call PunchFiles /* punch files to begin install */
exit
end /* if bootRc = 0 */
end /* if user-specific profile found */
/* Download initial profile list */
call GetTFTP '/s390x/profile_list' 'profile.list.t'
vmfclear /* clear screen */
call CheckServer /* print server name */
say 'zPXE MENU' /* show menu */
say '---------'
count = 0
do while lines(profilelist) > 0 /* display one profile per line */
count = count + 1
inputline = linein(profilelist)
parse var inputline profile.count
say count'. 'profile.count
end
if (count = 0) then
say '** Error connecting to server: no profiles found **'
count = count + 1
say count'. Exit to CMS shell [IPL CMS]'
say ''
say ''
say 'Enter Choice -->'
say 'or press <Enter> to boot from disk [DASD 'iplDisk']'
/* Check if user is disconnected, indicating
logon by XAUTOLOG. In this case, IPL the
default disk.
*/
if (dsc = 'DSC') then do /* user is disconnected */
say 'User disconnected. Booting from DASD 'iplDisk'...'
'detach ffff' /* detach ffff if present */
'cp ipl' iplDisk
end
else do /* user is interactive -> prompt */
parse upper pull answer .
select
when (answer = count)
then do
say 'Exiting to CMS shell...'
exit
end
when (answer = '') /* IPL by default */
then do
say 'Booting from DASD 'iplDisk'...'
'detach ffff' /* detach ffff if present */
'cp ipl' iplDisk
end
when (answer < 0) | (answer > count) /* invalid respone */
then do
say 'Invalid choice, exiting to CMS shell.'
exit
end
when (answer > 0) & (answer < count) /* valid response */
then do
call GetTFTP '/s390x/p_'profile.answer 'profile.detail.t'
/* get profile-based PARM and CONF files */
call GetTFTP '/s390x/p_'profile.answer'_parm' 'zpxe.parm.t'
call GetTFTP '/s390x/p_'profile.answer'_conf' 'zpxe.conf.t'
vmfclear /* clear screen */
say 'Using profile 'answer' ['profile.answer']'
say ''
call DownloadBinaries /* download kernel and initrd */
say 'Starting install...'
say ''
call PunchFiles
end /* valid answer */
otherwise
say 'Invalid choice, exiting to CMS shell.'
exit
end /* Select */
end
exit
/* Procedure CheckServer
Print error message if server is not defined. Otherwise
show server name
*/
CheckServer:
if server = '' then
say '** Error: No host defined in ZPXE.CONF **'
else say 'Connected to server 'server
say ''
return 0 /* CheckServer */
/* Procedure GetTFTP
Use CMS TFTP client to download files
path: remote file location
filename: local file name
transfermode [optional]: 'ascii' or 'octet'
*/
GetTFTP:
parse arg path filename transfermode
/* make a stack */
'makebuf'
if transfermode <> '' then
queue 'mode' transfermode
queue 'get 'path filename
queue 'quit'
'set cmstype ht' /* suppress tftp output */
tftp server
'set cmstype rt'
/* drop the stack */
'dropbuf'
return 0 /* GetTFTP */
/* Procedure GetFTP
Use CMS FTP client to download files over anonymous FTP
server: remote FTP server hostname
path: remote file location
filename: local file name
transfermode: 'ascii' or 'binary'
*/
GetFTP:
parse arg ftpserver path filename transfermode
/* make a new buffer */
'makebuf'
queue 'anonymous anonymous'
if transfermode <> '' then
queue transfermode
/* Paths longer than 80 chars are not processed correctly by z/VM FTP */
do while length(path) > 80
parse value path with onedir '/' remainder
queue 'cd' onedir
path = remainder
end
queue 'get' path filename
queue 'quit'
'set cmstype ht' /* suppress ftp output */
'ftp' ftpserver '(exit'
'set cmstype rt'
/* drop it */
'dropbuf'
return 0 /* GetFTP */
/* Procedure GetURL
Download from a URL (or plain TFTP path)
*/
GetURL:
/* is it an FTP url? */
parse arg 'ftp://' ftpserver '/' path filename
if ftpserver <> '' & path <> '' then do
call GetFTP ftpserver path filename 'binary'
return 0
end
/* assume it's a TFTP path on the PXE server */
parse arg path filename
call GetTFTP path filename 'octet'
return 0 /* GetURL */
/* Procedure DownloadBinaries
Download kernel and initial RAMdisk. Convert both
to fixed record length 80.
*/
DownloadBinaries:
inputline = linein(profiledetail) /* first line is kernel */
parse var inputline kernelpath
say 'Downloading kernel ['kernelpath']...'
call GetURL kernelpath 'kernel.img.t'
inputline = linein(profiledetail) /* second line is initrd */
parse var inputline initrdpath
say 'Downloading initrd ['initrdpath']...'
call GetURL initrdpath 'initrd.img.t'
inputline = linein(profiledetail) /* third line is ks kernel arg */
parse var inputline ksline
call lineout zpxeparm, ksline /* add ks line to end of parm */
call lineout zpxeparm /* close file */
/* convert to fixed record length */
'pipe < KERNEL IMG T | fblock 80 00 | > KERNEL IMG T'
'pipe < INITRD IMG T | fblock 80 00 | > INITRD IMG T'
return 0 /* DownloadBinaries */
/* Procedure PunchFiles
Punch the kernel, initial RAMdisk, and PARM file.
Then IPL to start the install process.
*/
PunchFiles:
'spool punch *'
'close reader'
'purge reader all' /* clear reader contents */
'punch kernel img t (noh' /* punch kernel */
'punch zpxe parm t (noh' /* punch PARM file */
'punch initrd img t (noh' /* punch initrd */
'change reader all keep' /* keep files in reader */
'detach ffff' /* detach vdisk save mem*/
'ipl 00c clear' /* IPL the reader */
return 0 /* PunchFiles */
/* Procedure ParseSystemRecord
Open system record file to look for local boot flag.
Return 0 if local flag found (guest will IPL default DASD).
Return 1 otherwise (guest will download kernel/initrd and install).
*/
ParseSystemRecord:
inputline = linein(profiledetail) /* get first line */
parse var inputline systemaction .
call lineout profiledetail /* close file */
if systemaction = 'local' then
return 0
else
return 1
/* End ParseSystemRecord */