Sysresccd-manual-en Run your own scripts with autorun
The autorun feature allows you to run scripts automatically at startup of the system. Each autorun script can manage a task. For example, you can create a backup script that makes a backup of a database, another for cleaning a system, ...
By default, the autorun script(s) may be copied in the root of the CDRom, outside of the compressed loop image file (sysrcd.dat), but other sources are available : floppy disk, HD partition, network share, a web server.
The script may be named
autorun if alone. If many scripts have to be chained, you may name them
autorun1,... . In this case, specific autorun scripts may be allowed with an
autoruns= startup option given at boot time prompt. For example, you may type
If you want to use floppy or network source for autorun files, you will have to specify the source using the
ar_source boot option. More on this in next section.
Autorun has been rewritten in SystemRescueCd-1.0.0 so that it supports new autorun sources. You can have more details about the changes in the page about autorun in the news section.
You can use autorun to perform completely automatic tasks using SystemRescueCd. There is a dedicated chapter that explains How to use autorun to manage server that are in a remote datacenter.
Options provided by the autorun
These options may be used at boot time, on the boot command line.
- ar_source=xxx: place where the autoruns are stored. It may be the root directory of a partition (
/dev/sda1), an nfs share (
nfs://192.168.1.1:/path/to/scripts), a samba share (
smb://192.168.1.1/path/to/scripts), or an http directory (
- autoruns=[0-9]: comma separated list of the autorun scripts that have to be run. For instance if you use
autoruns=0,2,7then the following autorun scripts will be executed:
autoruns=noto disable all the autorun scripts with a number.
- ar_nowait: do not wait for a keypress after the autorun scripts have been executed.
The following autorun boot options have been introduced in SystemRescueCd-1.0.0:
- ar_ignorefail: continue to execute the scripts chain even if a script failed (returned a non-zero status)
- ar_nodel: do not delete the temporary copy of the autorun scripts located in
- ar_disable: completely disable autorun, the simple
autorunscript will not be executed
Summary of scripts execution rules
At startup, a list of locations is checked against the presence of autorun files. They are, successively:
- if the ar_source= parameter was passed at startup, the root directory of the given location. Devices are mounted to
/mnt/autorun, allowing writing data into them if the device is not write-protected.
- Floppy disks:
- Hard disk:
rescuecd ar_source=/dev/hda2(autorun scripts in 2nd partition of 1st IDE hard disk)
- NFS shares:
- Samba shares:
rescuecd ar_source=//samba-server/share(recommended without user/password).
- Http server:
rescuecd ar_source=http://web-server/adminscripts/(requires SystemRescueCd-1.0.0 or newer)
- Floppy disks:
- the root directory of the CD-ROM
- the superuser home directory (/root)
- the /usr/share/sys.autorun directory
If autorun files are found in some location, they are run and the process ends. Last two locations require rebuilding of SystemRescueCd and are to be used for advanced or test purposes.
In each source location, there are two possible modes of operation :
- simple one : if a shell script named
autorunis found, it is run
- more flexible : if
autorun#scripts are found (# is a digit from 0 to 9) and either
autoruns=boot parameter was NOT specified, or
autoruns=boot parameter value contains #
In this example, only
autorun0, autorun1 or autorun4 scripts may be run if present. Other scripts, such as autorun2, autorun3 and autorun5, will be ignored, then authorized scripts are run in alphanumeric order. Whenever a script returns a non-zero code, the processing stops and next scripts are not run. You can prevent any "autorun#" execution with an autorun= boot parameter without any digit, ex:
autoruns=no. This has no effect on
Although it is possible to put both
autorun# scripts, this should probably be avoided.
The script has to be any valid shell script. Perl, python, ... etc. scripts are not supported at this time. Windows end-of-line terminators are translated to allow running shell scripts written with a MS editor.
Examples of autorun scripts
#!/bin/bash ( ifconfig eth0 | head -n 3 fdisk -l /dev/hda ) | tee -a /mnt/autorun/report sync exit 0
In this script we assume that we have passed the floppy-disk as the source of autorun with
ar_source=fd0 boot-parameter. It will accumulate infos about eth0 network interface and disk partitions into a file named
report on the first floppy drive. The BIOS boot sequence must specify the CD first, the diskette must be write-enabled, the CD and diskette must be inserted at startup time.
Hint: The parameter
-a after the command
tee has the following effect: the file is not overwritten but the output is appended.
If network is automatically configured at boot (DHCP), you may send infos through an NFS or a samba share for example.
Don't forget to give the autorun location at startup. Say that you share through NFS a writeable directory named
/nfs/backup on host myserver, you have to specify:
at SystemRescueCd boot prompt and to put in the shared directory an
autorun script such as this one :
#!/bin/bash date=$(date +%Y%m%d) cat /dev/hda | gzip > /mnt/autorun/$date.hda.gz && exit 0 echo $date hda backup error exit 1
If sufficient space is provided in the NFS share, a compressed image of your first IDE disk will be copied there. Be aware that there may be a 2GB maximum file size when copying across the network or to a FAT filesystem.
You must ensure that name resolution works if you intend to access the NFS server by its name instead of its IP address.