]> rtime.felk.cvut.cz Git - novaboot.git/blob - README.md
Add --prefix - a more generic variant of --grub-prefix
[novaboot.git] / README.md
1 # NAME
2
3 novaboot - A tool for booting various operating systems on various hardware or in qemu
4
5 # SYNOPSIS
6
7 **novaboot** --help
8
9 **novaboot** \[option\]... \[--\] script...
10
11 **./script** \[option\]...
12
13 # DESCRIPTION
14
15 This program makes booting of an operating system (e.g. NOVA or Linux)
16 as simple as running a local program. It facilitates booting on local
17 or remote hosts or in emulators such as qemu. Novaboot operation is
18 controlled by command line options and by a so called novaboot script,
19 which can be thought as a generalization of bootloader configuration
20 files (see ["NOVABOOT SCRIPT SYNTAX"](#novaboot-script-syntax)). Based on this input,
21 novaboot setups everything for the target host to boot the desired
22 configuration, i.e. it generates the bootloader configuration file in
23 the proper format, deploy the binaries and other needed files to
24 required locations, perhaps on a remote boot server and reset the
25 target host. Finally, target host's serial output is redirected to
26 standard output if that is possible.
27
28 Typical way of using novaboot is to make the novaboot script
29 executable and set its first line to _#!/usr/bin/env novaboot_. Then,
30 booting a particular OS configuration becomes the same as executing a
31 local program - the novaboot script.
32
33 For example, with `novaboot` you can:
34
35 1. Run an OS in Qemu. This is the default action when no other action is
36 specified by command line switches. Thus running `novaboot ./script`
37 (or `./script` as described above) will run Qemu and make it boot the
38 configuration specified in the `script`.
39 2. Create a bootloader configuration file (currently supported
40 bootloaders are GRUB, GRUB2, Pulsar and U-Boot) and copy it with all
41 other files needed for booting to a remote boot server.
42
43         ./script --server=192.168.1.1:/tftp --iprelay=192.168.1.2
44
45     This command copies files to the TFTP server and uses
46     TCP/IP-controlled relay to reset the target host and receive its
47     serial output.
48
49 3. Run DHCP and TFTP server on developer's machine to PXE-boot the target
50 host from it. E.g.
51
52         ./script --dhcp-tftp
53
54     When a PXE-bootable machine is connected via Ethernet to developer's
55     machine, it will boot the configuration described in _script_.
56
57 4. Create bootable ISO images. E.g.
58
59         novaboot --iso -- script1 script2
60
61     The created ISO image will have GRUB bootloader installed on it and
62     the boot menu will allow selecting between _script1_ and _script2_
63     configurations.
64
65 Note that the options needed for a specific target can be stored in a
66 ["CONFIGURATION FILE"](#configuration-file). Then it is sufficient to use only the **-t**
67 option to specify the name of the target.
68
69 # PHASES AND OPTIONS
70
71 Novaboot performs its work in several phases. Each phase can be
72 influenced by several options, certain phases can be skipped. The list
73 of phases (in the execution order) and the corresponding options
74 follow.
75
76 ## Configuration reading phase
77
78 After starting, novaboot reads configuration files. Their content is
79 described in ["CONFIGURATION FILE"](#configuration-file). By default, configuration is
80 read from two locations. First from the configuration directory and
81 second from `.novaboot` files along the path to the current
82 directory. The later read files override settings from the former
83 ones.
84
85 Configuration directory is determined by the content of
86 NOVABOOT\_CONFIG\_DIR environment variable defaulting to
87 `/etc/novaboot.d`. Files in this directory with names consisting
88 solely from English letters, numbers, dashes '-' and underscores '\_'
89 (note that dot '.' is not included) are read in alphabetical order.
90
91 Then novaboot searches for files named `.novaboot` starting
92 from the directory of the novaboot script (or working directory, see
93 bellow) and continuing upwards up to the root directory. The found
94 configuration files are then read in order from the root directory
95 downwards.
96
97 In certain cases, the location of the novaboot script cannot be
98 determined in this early phase. This happens either when the script is
99 read from the standard input or when novaboot is invoked explicitly
100 and options precede the script name, as in the example ["4."](#4) above.
101 In this case the current working directory is used as a starting point
102 for configuration file search instead of the novaboot script
103 directory.
104
105 - -c, --config=_filename_
106
107     Use the specified configuration file instead of the default one(s).
108
109 ## Command line processing phase
110
111 - --dump-config
112
113     Dump the current configuration to stdout end exits. Useful as an
114     initial template for a configuration file.
115
116 - -h, --help
117
118     Print short (**-h**) or long (**--help**) help.
119
120 - -t, --target=_target_
121
122     This option serves as a user configurable shortcut for other novaboot
123     options. The effect of this option is the same as the options stored
124     in the `%targets` configuration variable under key _target_. See
125     also ["CONFIGURATION FILE"](#configuration-file).
126
127 ## Script preprocessing phase
128
129 This phases allows to modify the parsed novaboot script before it is
130 used in the later phases.
131
132 - -a, --append=_parameters_
133
134     Append a string to the first `load` line in the novaboot script. This
135     can be used to append parameters to the kernel's or root task's
136     command line. Can appear multiple times.
137
138 - -b, --bender
139
140     Use `bender` chainloader. Bender scans the PCI bus for PCI serial
141     ports and stores the information about them in the BIOS data area for
142     use by the kernel.
143
144 - --chainloader=_chainloader_
145
146     Chainloader that is loaded before the kernel and other files specified
147     in the novaboot script. E.g. 'bin/boot/bender promisc'.
148
149 - --dump
150
151     Print the modules to boot and their parameters after this phase
152     finishes. Then exit. This is useful for seeing the effect of other
153     options in this section.
154
155 - -k, --kernel=`file`
156
157     Replace the first word on the first `load` line in the novaboot
158     script with `file`.
159
160 - --scriptmod=_perl expression_
161
162     When novaboot script is read, _perl expression_ is executed for every
163     line (in $\_ variable). For example, `novaboot
164     \--scriptmod=s/sigma0/omega6/g` replaces every occurrence of _sigma0_
165     in the script with _omega6_.
166
167     When this option is present, it overrides _$script\_modifier_ variable
168     from the configuration file, which has the same effect. If this option
169     is given multiple times all expressions are evaluated in the command
170     line order.
171
172 ## File generation phase
173
174 In this phase, files needed for booting are generated in a so called
175 _build directory_ (see ["--build-dir"](#build-dir)). In most cases configuration
176 for a bootloader is generated automatically by novaboot. It is also
177 possible to generate other files using _heredoc_ or _"<"_ syntax in
178 novaboot scripts. Finally, binaries can be generated in this phases by
179 running `scons` or `make`.
180
181 - --build-dir=_directory_
182
183     Overrides the default build directory location.
184
185     The default build directory location is determined as follows: If the
186     configuration file defines the `$builddir` variable, its value is
187     used. Otherwise, it is the directory that contains the first processed
188     novaboot script.
189
190     See also ["BUILDDIR"](#builddir) variable.
191
192 - -g, --grub\[=_filename_\]
193
194     Generates grub bootloader menu file. If the _filename_ is not
195     specified, `menu.lst` is used. The _filename_ is relative to the
196     build directory (see **--build-dir**).
197
198 - --grub-preamble=_prefix_
199
200     Specifies the _preable_ that is at the beginning of the generated
201     GRUB or GRUB2 config files. This is useful for specifying GRUB's
202     timeout.
203
204 - --prefix=_prefix_
205
206     Specifies _prefix_ (e.g. `/srv/tftp`) that is put in front of every
207     file name in generated bootloader configuration files (or in U-Boot
208     commands).
209
210     If the _prefix_ contains string $NAME, it will be replaced with the
211     name of the novaboot script (see also **--name**).
212
213     If the _prefix_ contains string $BUILDDIR, it will be replaced with
214     the build directory (see also **--build-dir**).
215
216 - --grub-prefix
217
218     Alias for **--prefix**.
219
220 - --grub2\[=_filename_\]
221
222     Generate GRUB2 menuentry in _filename_. If _filename_ is not
223     specified `grub.cfg` is used. The content of the menuentry can be
224     customized with **--grub-preable**, **--grub2-prolog** or
225     **--grub\_prefix** options.
226
227     In order to use the the generated menuentry on your development
228     machine that uses GRUB2, append the following snippet to
229     `/etc/grub.d/40_custom` file and regenerate your grub configuration,
230     i.e. run update-grub on Debian/Ubuntu.
231
232         if [ -f /path/to/nul/build/grub.cfg ]; then
233           source /path/to/nul/build/grub.cfg
234         fi
235
236 - --grub2-prolog=_prolog_
237
238     Specifies text _preable_ that is put at the beginning of the entry
239     GRUB2 entry.
240
241 - -m, --make\[=make command\]
242
243     Runs `make` to build files that are not generated by novaboot itself.
244
245 - --name=_string_
246
247     Use the name _string_ instead of the name of the novaboot script.
248     This name is used for things like a title of grub menu or for the
249     server directory where the boot files are copied to.
250
251 - --no-file-gen
252
253     Do not run external commands to generate files (i.e. "<" syntax and
254     `run` keyword). This switch does not influence generation of files
255     specified with "<<WORD" syntax.
256
257 - -p, --pulsar\[=mac\]
258
259     Generates pulsar bootloader configuration file named `config-_mac_`
260     The _mac_ string is typically a MAC address and defaults to
261     _novaboot_.
262
263 - --scons\[=scons command\]
264
265     Runs `scons` to build files that are not generated by novaboot
266     itself.
267
268 - --strip-rom
269
270     Strip _rom://_ prefix from command lines and generated config files.
271     The _rom://_ prefix is used by NUL. For NRE, it has to be stripped.
272
273 - --gen-only
274
275     Exit novaboot after file generation phase.
276
277 ## Target connection check
278
279 If supported by the target, the connection to it is made and it is
280 checked whether the target is not occupied by another novaboot
281 user/instance.
282
283 - --amt=_"\[user\[:password\]@\]host\[:port\]_
284
285     Use Intel AMT technology to control the target machine. WS management
286     is used to powercycle it and Serial-Over-Lan (SOL) for input/output.
287     The hostname or (IP address) is given by the _host_ parameter. If
288     _password_ is not specified, environment variable AMT\_PASSWORD is
289     used. The _port_ specifies a TCP port for SOL. If not specified, the
290     default is 16992. Default _user_ is admin.
291
292 - --ider
293
294     Use Intel AMT technology for IDE redirection. This allows the target
295     machine to boot from nonvaboot created ISO image.
296
297     The experimental _amtider_ utility needed by this option can be
298     obtained from https://github.com/wentasah/amtterm.
299
300 - --iprelay=_addr\[:port\]_
301
302     Use TCP/IP relay and serial port to access the target's serial port
303     and powercycle it. The IP address of the relay is given by _addr_
304     parameter. If _port_ is not specified, it default to 23.
305
306     Note: This option is supposed to work with HWG-ER02a IP relays.
307
308 - -s, --serial\[=device\]
309
310     Target's serial line is connected to host's serial line (device). The
311     default value for device is `/dev/ttyUSB0`.
312
313     The value of this option is exported in NB\_NOVABOOT environment
314     variable to all subprocesses run by `novaboot`.
315
316 - --stty=_settings_
317
318     Specifies settings passed to `stty` invoked on the serial line
319     specified with **--serial** option. If this option is not given,
320     `stty` is called with `raw -crtscts -onlcr 115200` settings.
321
322 - --remote-cmd=_cmd_
323
324     Command that mediates connection to the target's serial line. For
325     example `ssh server 'cu -l /dev/ttyS0'`.
326
327 - --remote-expect=_string_
328
329     Wait for reception of _string_ after establishing the the remote
330     connection before continuing.
331
332 ## File deployment phase
333
334 In some setups, it is necessary to copy the files needed for booting
335 to a particular location, e.g. to a TFTP boot server or to the
336 `/boot` partition.
337
338 - -d, --dhcp-tftp
339
340     Turns your workstation into a DHCP and TFTP server so that the OS can
341     be booted via PXE BIOS (or similar mechanism) on the test machine
342     directly connected by a plain Ethernet cable to your workstation.
343
344     The DHCP and TFTP servers requires root privileges and `novaboot`
345     uses `sudo` command to obtain those. You can put the following to
346     _/etc/sudoers_ to allow running the necessary commands without asking
347     for password.
348
349         Cmnd_Alias NOVABOOT = /bin/ip a add 10.23.23.1/24 dev eth0, /bin/ip l set dev eth0 up, /usr/sbin/dhcpd -d -cf dhcpd.conf -lf dhcpd.leases -pf dhcpd.pid, /usr/sbin/in.tftpd --listen --secure -v -v -v --pidfile tftpd.pid *, /usr/bin/touch dhcpd.leases, /usr/bin/pkill --pidfile=dhcpd.pid, /usr/bin/pkill --pidfile=tftpd.pid
350         your_login ALL=NOPASSWD: NOVABOOT
351
352 - --tftp
353
354     Starts a TFTP server on your workstation. This is similar to
355     **--dhcp-tftp** except that DHCP server is not started.
356
357     The TFTP server require root privileges and `novaboot` uses `sudo`
358     command to obtain those. You can put the following to _/etc/sudoers_
359     to allow running the necessary commands without asking for password.
360
361         Cmnd_Alias NOVABOOT =  /usr/sbin/in.tftpd --listen --secure -v -v -v --pidfile tftpd.pid *, /usr/bin/pkill --pidfile=tftpd.pid
362         your_login ALL=NOPASSWD: NOVABOOT
363
364 - --tftp-port=_port_
365
366     Port to run the TFTP server on. Implies **--tftp**.
367
368 - --iso\[=filename\]
369
370     Generates the ISO image that boots NOVA system via GRUB. If no filename
371     is given, the image is stored under _NAME_.iso, where _NAME_ is the name
372     of the novaboot script (see also **--name**).
373
374 - --server\[=\[\[user@\]server:\]path\]
375
376     Copy all files needed for booting to another location (implies **-g**
377     unless **--grub2** is given). The files will be copied (by **rsync**
378     tool) to the directory _path_. If the _path_ contains string $NAME,
379     it will be replaced with the name of the novaboot script (see also
380     **--name**).
381
382 - --concat
383
384     If **--server** is used and its value ends with $NAME, then after
385     copying the files, a new bootloader configuration file (e.g. menu.lst)
386     is created at _path-wo-name_, i.e. the path specified by **--server**
387     with $NAME part removed. The content of the file is created by
388     concatenating all files of the same name from all subdirectories of
389     _path-wo-name_ found on the "server".
390
391 - --rsync-flags=_flags_
392
393     Specifies which _flags_ are appended to `rsync` command line when
394     copying files as a result of _--server_ option.
395
396 ## Target power-on and reset phase
397
398 - --on, --off
399
400     Switch on/off the target machine and exit. The script (if any) is
401     completely ignored. Currently it works only with **--iprelay** or
402     **--amt**.
403
404 - -Q, --qemu\[=_qemu-binary_\]
405
406     Boot the configuration in qemu. Optionally, the name of qemu binary
407     can be specified as a parameter.
408
409 - --qemu-append=_flags_
410
411     Append _flags_ to the default qemu flags (QEMU\_FLAGS variable or
412     `-cpu coreduo -smp 2`).
413
414 - -q, --qemu-flags=_flags_
415
416     Replace the default qemu flags (QEMU\_FLAGS variable or `-cpu coreduo
417     \-smp 2`) with _flags_ specified here.
418
419 - --reset-cmd=_cmd_
420
421     Command that resets the target.
422
423 ## Interaction with the bootloader on the target
424
425 - --uboot\[=_prompt_\]
426
427     Interact with uBoot bootloader to boot the thing described in the
428     novaboot script. _prompt_ specifies the U-Boot's prompt (default is
429     "=> ", other common prompts are "U-Boot> " or "U-Boot# ").
430     Implementation of this option is currently tied to a particular board
431     that we use. It may be subject to changes in the future!
432
433 - --uboot-init
434
435     Command(s) to send the U-Boot bootloader before loading the images and
436     booting them. This option can be given multiple times. After sending
437     commands from each option novaboot waits for U-Boot _prompt_.
438
439     If the command contains string _$NB\_MYIP_ then this string is
440     replaced by IPv4 address of eth0 interface.
441
442 ## Target interaction phase
443
444 In this phase, target's serial output is redirected to stdout and if
445 stdin is a TTY, it is redirected to the target's serial input allowing
446 interactive work with the target.
447
448 - --exiton=_string_
449
450     When _string_ is sent by the target, novaboot exits. This option can
451     be specified multiple times.
452
453     If _string_ is `-re`, then the next **--exiton**'s _string_ is
454     treated as regular expression. For example:
455
456         --exiton -re --exiton 'error:.*failed'
457
458 - -i, --interactive
459
460     Setup things for interactive use of target. Your terminal will be
461     switched to raw mode. In raw mode, your system does not process input
462     in any way (no echoing of entered characters, no interpretation
463     special characters). This, among others, means that Ctrl-C is passed
464     to the target and does no longer interrupt novaboot. Use "~~."
465     sequence to exit novaboot.
466
467 - --expect=_string_
468
469     When _string_ is received from the target, send the string specified
470     with the subsequent **--send\*** option to the target.
471
472 - --expect-re=_regex_
473
474     When target's output matches regular expression _regex_, send the
475     string specified with the subsequent **--send\*** option to the target.
476
477 - --expect-raw=_perl-code_
478
479     Provides direct control over Perl's Expect module.
480
481 - --send=_string_
482
483     Send _string_ to the target after the previously specified
484     **--expect\*** was matched in the target's output. The _string_ may
485     contain escape sequences such as "\\n".
486
487     Note that _string_ is actually interpreted by Perl, so it can contain
488     much more that escape sequences. This behavior may change in the
489     future.
490
491     Example: `--expect='login: ' --send='root\n'`
492
493 - --sendcont=_string_
494
495     Similar to **--send** but continue expecting more input.
496
497     Example: `--expect='Continue?' --sendcont='yes\n'`
498
499 # NOVABOOT SCRIPT SYNTAX
500
501 The syntax tries to mimic POSIX shell syntax. The syntax is defined
502 with the following rules.
503
504 Lines starting with "#" and empty lines are ignored.
505
506 Lines that end with "\\" are concatenated with the following line after
507 removal of the final "\\" and leading whitespace of the following line.
508
509 Lines of the form _VARIABLE=..._ (i.e. matching '^\[A-Z\_\]+=' regular
510 expression) assign values to internal variables. See ["VARIABLES"](#variables)
511 section.
512
513 Lines starting with `load` keyword represent modules to boot. The
514 word after `load` is a file name (relative to the build directory
515 (see **--build-dir**) of the module to load and the remaining words are
516 passed to it as the command line parameters.
517
518 When the `load` line ends with "<<WORD" then the subsequent lines
519 until the line containing solely WORD are copied literally to the file
520 named on that line. This is similar to shell's heredoc feature.
521
522 When the `load` line ends with "< CMD" then command CMD is executed
523 with `/bin/sh` and its standard output is stored in the file named on
524 that line. The SRCDIR variable in CMD's environment is set to the
525 absolute path of the directory containing the interpreted novaboot
526 script.
527
528 Lines starting with `run` keyword contain shell commands that are run
529 during file generation phase. This is the same as the "< CMD" syntax
530 for `load` keyboard except that the command's output is not
531 redirected to a file. The ordering of commands is the same as they
532 appear in the novaboot script.
533
534 Example (Linux):
535
536     #!/usr/bin/env novaboot
537     load bzImage console=ttyS0,115200
538     run  make -C buildroot
539     load rootfs.cpio < gen_cpio buildroot/images/rootfs.cpio "myapp->/etc/init.d/S99myapp"
540
541 Example (NOVA User Land - NUL):
542
543     #!/usr/bin/env novaboot
544     WVDESC=Example program
545     load bin/apps/sigma0.nul S0_DEFAULT script_start:1,1 \
546                              verbose hostkeyb:0,0x60,1,12,2
547     load bin/apps/hello.nul
548     load hello.nulconfig <<EOF
549     sigma0::mem:16 name::/s0/log name::/s0/timer name::/s0/fs/rom ||
550     rom://bin/apps/hello.nul
551     EOF
552
553 This example will load three modules: `sigma0.nul`, `hello.nul` and
554 `hello.nulconfig`. sigma0 receives some command line parameters and
555 `hello.nulconfig` file is generated on the fly from the lines between
556 `<<EOF` and `EOF`.
557
558 ## VARIABLES
559
560 The following variables are interpreted in the novaboot script:
561
562 - BUILDDIR
563
564     Novaboot chdir()s to this directory before file generation phase. The
565     directory name specified here is relative to the build directory
566     specified by other means (see ["--build-dir"](#build-dir)).
567
568 - EXITON
569
570     Assigning this variable has the same effect as specifying ["--exiton"](#exiton)
571     option.
572
573 - HYPERVISOR\_PARAMS
574
575     Parameters passed to hypervisor. The default value is "serial", unless
576     overridden in configuration file.
577
578 - KERNEL
579
580     The kernel to use instead of the hypervisor specified in the
581     configuration file with the `$hypervisor` variable. The value should
582     contain the name of the kernel image as well as its command line
583     parameters. If this variable is defined and non-empty, the variable
584     HYPERVISOR\_PARAMS is not used.
585
586 - QEMU
587
588     Use a specific qemu binary (can be overridden with **-Q**) and flags
589     when booting this script under qemu. If QEMU\_FLAGS variable is also
590     specified flags specified in QEMU variable are replaced by those in
591     QEMU\_FLAGS.
592
593 - QEMU\_FLAGS
594
595     Use specific qemu flags (can be overridden with **-q**).
596
597 - WVDESC
598
599     Description of the wvtest-compliant program.
600
601 - WVTEST\_TIMEOUT
602
603     The timeout in seconds for WvTest harness. If no complete line appears
604     in the test output within the time specified here, the test fails. It
605     is necessary to specify this for long running tests that produce no
606     intermediate output.
607
608 # CONFIGURATION FILE
609
610 Novaboot can read its configuration from one or more files. By
611 default, novaboot looks for files named `.novaboot` as described in
612 ["Configuration reading phase"](#configuration-reading-phase). Alternatively, configuration file
613 location can be specified with the **-c** switch or with the
614 NOVABOOT\_CONFIG environment variable. The configuration file has perl
615 syntax and should set values of certain Perl variables. The current
616 configuration can be dumped with the **--dump-config** switch. Some
617 configuration variables can be overridden by environment variables
618 (see below) or by command line switches.
619
620 Supported configuration variables include:
621
622 - $builddir
623
624     Build directory location relative to the location of the configuration
625     file.
626
627 - $default\_target
628
629     Default target (see below) to use when no target is explicitly
630     specified on command line with the **--target** option.
631
632 - %targets
633
634     Hash of target definitions to be used with the **--target** option. The
635     key is the identifier of the target, the value is the string with
636     command line options. For instance, if the configuration file contains:
637
638         $targets{'mybox'} = '--server=boot:/tftproot --serial=/dev/ttyUSB0 --grub',
639
640     then the following two commands are equivalent:
641
642         ./script --server=boot:/tftproot --serial=/dev/ttyUSB0 --grub
643         ./script -t mybox
644
645 # ENVIRONMENT VARIABLES
646
647 Some options can be specified not only via config file or command line
648 but also through environment variables. Environment variables override
649 the values from configuration file and command line parameters
650 override the environment variables.
651
652 - NOVABOOT\_CONFIG
653
654     Name of the novaboot configuration file to use instead of the default
655     one(s).
656
657 - NOVABOOT\_CONFIG\_DIR
658
659     Name of the novaboot configuration directory. When not specified
660     `/etc/novaboot.d` is used.
661
662 - NOVABOOT\_BENDER
663
664     Defining this variable has the same meaning as **--bender** option.
665
666 # AUTHORS
667
668 Michal Sojka <sojka@os.inf.tu-dresden.de>