FAI (Fully Automatic Installation)

repository·master·Indexed 19 days ago

https://github.com/faiproject/fai

A system for the unattended mass deployment and configuration of Linux distributions on physical and virtual hardware. Includes a suite of CLI tools such as 'fai' for system installations and updates, 'fai-cd' for creating bootable ISOs or squashfs images, 'fai-chboot' for managing PXE network boot configurations, 'dhcp-edit' for managing dhcpd.conf entries, and 'ainsl' for conditional file appending.

Tokens
35.4K
Snippets
114
Records
160
Agent score
61%

What's inside FAI

  1. Overview of FAI (Fully Automatic Installation)

    master

    FAI (Fully Automatic Installation) is a tool designed for the unattended mass deployment of Linux systems. It automates the installation and configuration of operating systems and software packages on physical computers and virtual machines.

    Key capabilities include:

    • Unattended Deployment: Systems can be fully installed and configured from a 'virgin' state without user interaction.
    • Scalability: Suitable for environments ranging from small labs to large-scale clusters and cloud platforms.
    • Multi-Distribution Support: While optimized for Debian, it supports Debian, Ubuntu, Rocky Linux, CentOS, RHEL, and SUSE.
    • Extensible Configuration: OS configuration can be managed via shell scripts, Perl scripts, or other configuration management software.
  2. Handle symlinks with -H and -l

    master

    The fcopy tool provides two specific ways to handle symbolic links:

    1. Recreate symlinks (-H): If the source file is a symbolic link, the destination will also be created as a symbolic link pointing to the same target. This is useful for preserving link structures.
    2. Prevent symlink copying (-l): If the destination file already exists as a symbolic link, fcopy will issue a warning and skip the copy for that file.
  3. How fai-monitor handles client variable requests

    master

    The fai-monitor daemon can respond to requests from install clients regarding FAI variables. It reads variables from /var/log/fai/variables (formatted as key=value pairs).

    Request Format: Clients send a message in the format: VARIABLE <VARNAME>

    Response Formats:

    • If the variable exists: OK <VALUE> (e.g., OK 4.5.6)
    • If the variable does not exist: UNKNOWN <VARNAME> (e.g., UNKNOWN FAI_VERSION)
  4. How fai-do-scripts executes configuration scripts

    master

    The fai-do-scripts command is used to execute configuration scripts within a specified directory. It identifies scripts based on whether they belong to a defined class.

    If a class name is a directory, fai-do-scripts will execute all scripts within that directory that match the pattern <CLASSNAME>/^[0-9][0-9].* (i.e., scripts starting with two digits).

    This mechanism allows for multiple script types (such as shell, python, ruby, or cfengine) to be executed for a single class.

    # Example usage within FAI
    fai-do-scripts /fai/scripts
  5. How dirinstall works and how to define classes for it

    master

    The dirinstall [DIR] action is used to install an operating system into a specific directory rather than onto physical hardware. It functions similarly to the install action but skips the partitioning and filesystem creation steps.

    To define classes for a dirinstall run, you can:

    1. Use the -c option to specify comma-separated classes.
    2. Use the -u or --hostname option to provide a hostname, combined with the -N (or --new) option to enable automatic definition of classes from hostname-based scripts.

    Note: Without the -N option, class scripts are not executed during dirinstall.

    Example

    To install into /srv/etchroot using a local configuration directory and specific classes:

    fai -v -s file:///srv/fai/config -cDEFAULT,FAIBASE dirinstall /srv/etchroot
  6. Use fai-debconf to set debconf values using classes

    master

    The fai-debconf command is an internal FAI utility used to apply debconf settings based on defined FAI classes. It reads files in a specified DIRECTORY that match defined class names. These files must follow the debconf-get-selections(1) format.

    Once the values are read, fai-debconf calls debconf-set-selections(1) to update the database. If the $ROOTCMD environment variable is set, these operations are performed within the specified chroot environment. After updating the database, the command automatically triggers dpkg-reconfigure(8) for every installed package whose debconf data was modified.

  7. Use preinst and postinst scripts with fcopy

    master

    If the source directory contains executable scripts named preinst or postinst, fcopy executes them as part of the lifecycle:

    preinst (Pre-installation)

    Executed before the file is copied to the destination.

    1. A temporary copy of the file for the specific class is created.
    2. preinst is called with two arguments: the used class and the full pathname to the temporary copy.
    3. You can perform in-place substitutions or modifications on this temporary copy.
    4. The modified copy is compared to the destination. It only replaces the destination if there are differences and the preinst script exits with code 0.

    postinst (Post-installation)

    Executed after a successful copy.

    • It is called with two parameters: the class being used and the full pathname to the target file.
    • The environment variable ROOTCMD is set, which you can prepend to commands intended to run in the newly installed system.
  8. Configure template substitutions in fai-chboot

    master

    When using the -c <TEMPLATE> <HOST> command to copy a configuration template, fai-chboot performs variable substitutions within the template file.

    Supported variables:

    • $IP: The assigned IP address in dotted decimal format.
    • $HOST: The assigned hostname.
    # Copy 'lenny64' template to 'host01'
    # The template file should be located at /srv/tftp/fai/pxelinux.cfg/lenny64.tmpl
    fai-chboot -c lenny64 host01
  9. Configure debconf via FAI classes

    master

    To use fai-debconf, organize your debconf selection data into a directory structure that matches your FAI classes. The tool iterates through the provided directory and looks for files or subdirectories matching the defined $classes.

    Data Organization:

    • Files: If a file name matches a class name, its contents are treated as debconf selections.
    • Directories: If a directory name matches a class name, the tool will scan the directory for files (matching the pattern ^[[:alnum:]/_.-]+$) and add them as debconf data.

    Example Structure: If you have a class named webserver, you can provide selections in:

    • /path/to/debconf/webserver (a file)
    • /path/to/debconf/webserver/package_settings (a file inside a directory)

    Note: The tool requires the environment variable $classes to be defined to know which directories/files to process.

  10. Understand fai-do-scripts logging and output

    master

    The execution of scripts via fai-do-scripts is logged as follows:

    • Standard Output: Script output is written to $LOGDIR/scripts.log.
    • Execution Status: A list of all executed scripts and their success/failure status is maintained in $LOGDIR/status.log.
    • Legacy Logging: If the environment variable FAI_USE_OLD_SCRIPT_LOGS is set to 1, the system uses old-style log file names (where every script type has a different filename). Note that this legacy behavior may be removed in future versions.
  11. Copy files using classes with fcopy

    master

    The fcopy command copies files from a source directory to a target destination based on defined 'classes'. Each source argument is a directory containing template files. fcopy selects exactly one file from the source directory based on the highest priority matching class and copies it to the target filename (which is the name of the source directory).

    Priority Logic:

    1. fcopy looks for files matching the defined classes.
    2. The class with the highest priority that matches an existing file name is selected.
    3. In FAI, the class list typically starts with DEFAULT and ends with the hostname. DEFAULT is only used if no other class matches.

    Exit Codes:

    • 0: All files copied successfully.
    • >0: An error occurred.

    Note: Do not create a DEFAULT file if a reasonable default configuration cannot be provided; it is safer to let the command fail than to deploy an incorrect configuration.

    # Example: Copying a configuration file
    # If /files/etc/X11/xorg.conf contains: CAD, DEFAULT, LAB, MACH64, server1, ant04
    # And classes are: DEFAULT, CAD, server1
    # fcopy will select 'server1' because it is the highest priority match.
    
    fcopy -s /files -t /target /etc/X11/xorg.conf
  12. Configure FAI via configuration files

    master

    The fai-setup script relies on two primary configuration files located in the directory specified by the -C flag (defaulting to /etc/fai). These files are sourced during execution:

    1. fai.conf: Contains general FAI settings.
    2. nfsroot.conf: Contains settings specific to the NFS root environment, such as NFSROOT, TFTPROOT, SERVERINTERFACE, and FAI_CONFIGDIR.

    Key environment variables used or influenced by these files:

    • LOGUSER: The system user used for remote logging and SSH/RSH authentication.
    • FAI_LOGPROTO: The protocol used for logging (defaults to ssh).
    • FAI_CONFIGDIR: The directory where FAI configuration files are stored (must be set in nfsroot.conf).
    • SERVERINTERFACE: The network interface used for NFS exports (if not set, the script attempts to detect an active interface).