Oracle Linux Image Tools is a sample project to build small or customized Oracle Linux Cloud images in a repeatable way.
It provides a bash modular framework which uses HashiCorp Packer to build images in Oracle VM VirtualBox. Images are then converted to an appropriate format depending on the Cloud provider.
This article shows you how to build the sample images from this repository and how to use the framework to build custom images.
The framework is based around two concepts: Distribution and Cloud modules.
A Distribution module is responsible for the installation and configuration of Oracle Linux as well as the packages needed for your project. The sample ol7-slim distribution provides an Oracle Linux 7 image with a minimalist set of packages (about 250 packages – smaller than an Oracle Linux 7 Minimal Install).
A Cloud module ensures that the image is properly configured and packaged for a particular cloud provider. The following modules are currently available:
A Linux environment is required for building images. The project is developed and tested with Oracle Linux 7, but should run on most Linux distribution. If your environment is a virtual machine, it must support nested virtualization.
The build tool needs root privileges to mount the generated images. Ensure sudo is properly configured for the user running the build.
You will need the following software installed:
yum --enablerepo=ol7_developer install packer VirtualBox-6.0
yum install kpartx qemu-img
You will need at least twice the size of your images as free disk space. That is: building a 30GB image will require 60GB of free space.
Building the images from the project is straightforward.
Build configuration is done by editing the env.properties file (or better, a copy of it).
Options are documented in the property file, but at the very least you must provide:
The following env.properties.oci property file is used to build a minimal OL7 image for the Oracle Cloud Infrastructure, using all default parameters:
WORKSPACE="/data/workspace" ISO_URL="http://my.mirror.example.com/iso/ol7/OracleLinux-R7-U7-Server-x86_64-dvd.iso" ISO_SHA1_CHECKSUM="3ef94628cf1025dab5f10bbc1ed2005ca0cb0933" DISTR="ol7-slim" CLOUD="oci"
Run the script:
$ ./bin/build-image.sh --env env.properties.oci +++ build-image.sh: Parse arguments +++ build-image.sh: Load environment +++ build-image.sh: Stage Packer files +++ build-image.sh: Stage kickstart file +++ build-image.sh: Generate Packer configuration file +++ build-image.sh: Run Packer build-image.sh: Spawn HTTP server build-image.sh: Invoke Packer ... build-image.sh: Package image +++ build-image.sh: Cleanup Workspace +++ build-image.sh: All done +++ build-image.sh: Image available in /data/workspace/OL7U7_x86_64-oci-b0 $
The /data/workspace/OL7U7_x86_64-oci-b0 directory now contains OL7U7_x86_64-oci-b0.qcow, a QCOW2 file which can be imported and run on OCI.
Each Distribution module is represented by a subdirectory of the distr directory.
Each Cloud module is represented by a subdirectory of the cloud directory.
Additionally, Cloud actions for a specific Distribution can be defined in the cloud/<cloud>/<distr> directory.
Any element not necessary can be omitted – e.g. the none cloud module only provides a packaging function.
All the env.properties files are merged and made available to the scripts at runtime. They define parameters with default values which can be overridden by the user in the global env.properties file in the project base directory.
To add a new distribution, create a directory in distr/ with the following files:
The process is similar to the distribution: create a directory in cloud/ with the following files:
If some cloud actions are specific to a particular distribution, they can be specified in the <cloud>/<distr> subdirectory.
If a cloud_distr::image_package function is provided it will override the cloud::image_package one.
The complete build flow is illustrated hereunder:
The builder goes through the following steps: