/one-context

OpenNebula contextualization scripts for Alpine Linux and Gentoo

Primary LanguageShellMIT LicenseMIT

OpenNebula Contextualization / OpenRC

This project provides “contextualization” scripts for Alpine Linux virtual machines running on OpenNebula.

The scripts are inspired by the official scripts from addon-context-linux, but rewritten from scratch to be more readable, robust and fully POSIX compatible. This is not yet another fork of these poor official scripts.

NOTE: Support for Gentoo has been removed in version 0.8.0. If you miss it, please let me know in the issues.

Scripts

Configures network interfaces (via /etc/network/interfaces) and (re)starts the networking service, if $NETWORK is YES. It supports the following variables:

  • $DNS — DNS servers (as space-separated addressess).

  • $SEARCH_DOMAIN — The domain search list.

  • $ETH<n>_MAC — Used to find the correct interface by MAC address.

  • $ETH<n>_IP — IPv4 address for the interface.

  • $ETH<n>_MASK — IPv4 network mask for the interface.

  • $ETH<n>_GATEWAY — Default IPv4 gateway for the interface.

  • $ETH<n>_IP6 (or legacy $ETH<n>_IPV6) — IPv6 address for the interface.

  • $ETH<n>_IP6_GATEWAY (or legacy $ETH<n>_GATEWAY6) — Default IPv6 gateway for the interface.

  • $ETH<n>_DNS — DNS servers for the network (as space-separated addressess).

  • $ETH<n>_SEARCH_DOMAIN — The domain search list for the network.

Sets the hostname to $SET_HOSTNAME, if provided. It should contain only alphanumeric ASCII characters and a hyphen ([a-zA-Z0-9-]), all other characters will be replaced with a hyphen (-).

Adds the following lines to /etc/hosts:

127.0.0.1  <fqdn> <hostname> localhost
::1        <fqdn> <hostname> localhost

<fqdn> is $SET_FQDN or, if not provided, $SET_HOSTNAME. It should contain only alphanumeric characters, a hyphen and a period ([a-zA-Z0-9.-]), all other characters will be replaced with a hyphen (-).

<hostname> is the system’s hostname (previously set to $SET_HOSTNAME).

Adds NTP servers specified in $NTP (as space-seperated addressess) to either /etc/ntpd.conf (OpenNTPD) or /etc/ntp.conf (ISC ntp), if $NTP is provided.

Changes the system timezone to $TIMEZONE (e.g. Europe/Prague, UTC), if provided.

Creates an user account named $USERNAME with primary group users, secondary group wheel, and shell $USERNAME_SHELL (defaults to /bin/sh). If $USERNAME_SUDO isn’t provided or it’s YES, it also creates a doas or sudo (if doas is not installed) rule in /etc/doas.d/wheel.conf or /etc/sudoers.d/wheel, respectively, to permit the created user to run any command as any user (i.e. gives them the root access).

If $USERNAME is not provided, this script is skipped.

Adds an SSH public key provided in $SSH_PUBLIC_KEY to authorized_keys of the user specified by $USERNAME (or root if not set), if $SSH_PUBLIC_KEY is provided.

Extends all mounted filesystems to the maximum disk capacity, unless $GROWFS_DISABLE is YES. Only ext3, ext4, and btrfs are currently supported.

If the filesystem resides on a partition (GPT or DOS) and it’s the last partition, it will be expanded before resizing the filesystem.

Note: It’s completely unnecessary and pointless to use partitions on virtual disks, it just adds more complexity and complications, but some broken platforms and tools require it.

Updates /etc/ssmtp/ssmtp.conf, if exists:

  • Root to $ROOT_EMAIL (if provided)

  • Mailhub to $SMTP (if provided)

Executes the script provided in $START_SCRIPT_BASE64 (base64-encoded) or $START_SCRIPT. If the script doesn’t start with a shebang, it’s executed with /bin/sh.

Requirements

  • POSIX-compatible shell (e.g. ash, bash, dash)

  • core *nix utils (awk, grep, sed…​)

  • OpenRC

  • blkid from util-linux (for OpenRC runscript)

  • btrfs utility and/or resize2fs from e2fsprogs (only for growfs script)

  • partx and sfdisk from util-linux (only for grow-fs script if you use partitions)

  • ifup (only for network scripts)

  • kernel with support for mounting CD-ROM with ISO 9660 filesystem [1]

Installation

Alpine Linux

  1. Install one-context from the Alpine’s main repository:

    apk add one-context

Manually

  1. Clone this repository and jump in:

    git clone https://github.com/jirutka/one-context.git
    cd one-context
  2. Install init script, contextualization scripts and symlinks (you may need to run this with sudo)…

    make install

    You may use variables DESTDIR and PREFIX to specify the target directories.

  3. rc-update add vmcontext boot

Directory Structure

The scripts are installed into /usr/share/one-context/scripts (depends on DESTDIR and PREFIX variables, see above) and symlinked into /etc/one-context.d with a numeric prefix to specify the execution order. The runscript is installed into /etc/init.d/vmcontext.

License

This project is licensed under MIT License.


1. This is the way how OpenNebula passes configuration variables into VM.