Skip to content

Commit ba7a14e

Browse files
Merge pull request #131 from AmedeeBulle/libguestfs
refactor(olit): ♻️ libvirt/libguestfs refactor
2 parents 216a175 + 3669eaf commit ba7a14e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+2921
-2893
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Allow opening any 'source'd file, even if not specified as input
2+
external-sources=true
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Release Notes
2+
3+
## March, 2024
4+
5+
Major refactoring of the scripts, reducing dependencies on third parties.
6+
The build tools mainly rely on [`qemu-kvm`](http://www.qemu.org/), using [`libvirt`](https://libvirt.org/) and [`libguestfs`](https://libguestfs.org/).
7+
8+
As it is a breaking change, previous version has been archived under the `olit-legacy` branch (unmaintained).
9+
10+
### Refactor
11+
12+
The overall build process has been changed. In previous releases we had:
13+
14+
1. Create image from distribution ISO and a kickstart file
15+
1. Customize the image by running provision scripts inside the running VM
16+
1. Cleanup the environment by mounting the image filesystems on the host;
17+
the outcome is a raw disk image
18+
1. Package the image for the target cloud
19+
20+
As of this release, we have:
21+
22+
1. Create image: unchanged
23+
1. Use [`virt-customize`](customize) to run the provisioning scripts
24+
1. Use [`virt-sysprep`](https://libguestfs.org/virt-sysprep.1.html)/[`virt-sparsify`](https://libguestfs.org/virt-sparsify.1.html) for the cleanup;
25+
the outcome is a compressed qcow2 image
26+
1. Package image: unchanged
27+
28+
Notable code changes:
29+
30+
- Drop support for [VirtualBox](https://www.virtualbox.org/) as **builder** (you can still create Vagrant VirtualBox **images**)
31+
- `image-scripts.sh` `::seal()` functions obsolete; code moved to `provision.sh` `::cleanup()` functions.
32+
We don't need anymore a separate _offline_ cleanup as `virt-customize` doesn't actually run the built VM.
33+
- Simplify `provision.sh` `::cleanup()` functions as most parts are now handled by `virt-sysprep` operations.
34+
- Add `image-scripts.sh` `::customize_args()` and `::sysprep_args()` hooks to inject command line parameters for `virt-customize` and `virt-sysprep`.
35+
- Root privileges are no longer required on the build host.
36+
- Root access to the image VM is no longer needed at built time. Root password and/or ssh public key can still be set for the image; parameters have been renamed to ensure configuration is secure by default.
37+
- Move common code to the `common.sh` and `provision-common.sh` libraries.
38+
- QCOW2 image files now have the `qcow2` extension instead of `qcow`.
39+
40+
### Configuration variables
41+
42+
Changes to the configuration variables.
43+
See the corresponding `env.properties` files for more details.
44+
45+
New variables
46+
47+
- Generic
48+
- `INSTALL_WAIT_TIME`: configurable timeout for initial image creation
49+
- `OS_VARIANT` (optional): OS variant used when creating the image
50+
- `BOOT_MODE`: OS boot mode (`bios` or `efi`)
51+
- `BOOT_COMMAND_SERIAL_CONSOLE`: kernel parameters to enable serial console
52+
- `BOOT_LOCATION`(optional): kernel and initrd location on the distribution media
53+
- `ROOT_PASSWORD` (optional, default: locked): password for the root account in the generated image
54+
- `ROOT_SSH_KEY` (optional): public ssh key the root account in the generated image
55+
- `PERMIT_ROOT_LOGIN` (Default: prohibit-password): default policy for ssh root login
56+
- `CACHE_DIR` (Default: `.cache` in workspace directory): location of ISO images cache
57+
- utm cloud
58+
- `OPC_PASSWORD`: password for the `opc` user for UTM builds
59+
60+
Changed variables
61+
62+
- `DISTR`: is now mandatory
63+
- `ISO_LABEL`: is now optional
64+
- `BOOT_COMMAND`: array of kernel parameters instead of a string
65+
66+
Obsolete variables
67+
68+
- `LOCK_ROOT`, `SSH_KEY_FILE`, `SSH_PASSWORD`: root access to the image is not needed anymore, see new `ROOT_PASSWORD`, `ROOT_SSH_KEY` if root access to the generated image is needed
69+
- `X2APIC`
70+
- `PACKER`, `PACKER_BUILD_OPTIONS`, `PACKER_BUILDER`
71+
- `QEMU_BINARY`
72+
73+
### New features
74+
75+
- sshd `PermitRootLogin` parameter is now `prohibit-password` by default for all images (instead of `yes` for OL7/OL8)
76+
- update azure cloud for OL9
77+
78+
### Bug fixes
79+
80+
- Wrong pattern matching in bash regular expressions when validating variables
81+
- TERM variable in serial console configuration for OVM not escaped properly
82+
- Wrong swap page size for aarch64 builds when host is running UEK6 kernel
83+
- Workaround for OL8 cloud-init issue in OCI
84+
- Setup OCI yum mirrors for OCI images
85+
86+
### Documentation
87+
88+
README file updated

oracle-linux-image-tools/README.md

Lines changed: 78 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -4,87 +4,101 @@
44

55
This repository provides tools to build Oracle Linux images for cloud deployment.
66

7-
The images built by these tools are based on distribution flavours and target packages.
8-
Image building is accomplished using Packer to build images from the Oracle Linux ISO using Oracle VM VirtualBox or QEMU/KVM builders.
7+
__Note__: as of March 2024 the scripts have been refactored and introduce breaking changes. See [CHANGELOG](CHANGELOG.md) for details.
98

10-
The tool currently supports:
9+
The tools are architected around _distribution flavours_ and _target clouds_.
10+
They currently support:
1111

1212
- Distributions:
13-
- Oracle Linux 7 update 9 -- Slim (x86_64)
14-
- Oracle Linux 8 update 9 -- Slim (x86_64 and aarch64)
15-
__Note__: for aarch64, only Generic, OCI and UTM clouds are supported
16-
- Oracle Linux 9 update 3 -- Slim (x86_64 and aarch64)
17-
__Note__: for aarch64, only Generic, OCI and UTM clouds are supported
13+
- Oracle Linux 7 update 9 -- Slim (x86_64 only)
14+
- Oracle Linux 8 update 9 -- Slim (x86_64 and aarch64)
15+
- Oracle Linux 9 update 3 -- Slim (x86_64 and aarch64)
1816
- Clouds:
19-
- Microsoft Azure cloud
17+
- Microsoft Azure cloud (x86_64)
2018
Target packages: WALinuxAgent
2119
Image format: VHD
22-
- Oracle Cloud Infrastructure (OCI)
20+
- Oracle Cloud Infrastructure (OCI) (x86_64 and aarch64)
2321
Target packages: qemu-guest-agent / cloud-init
2422
Image format: QCOW2
2523
__Note__: no specific OCI tools are actually installed; this image can be used in any cloud-init based environment.
26-
- Oracle Linux Virtualization Manager (OLVM)
24+
- Oracle Linux Virtualization Manager (OLVM) (x86_64)
2725
Target packages: qemu-guest-agent / cloud-init
2826
Image format: OLVM OVA
29-
- Oracle VM Server (OVM)
27+
- Oracle VM Server (OVM) (x86_64)
3028
Target packages: oracle-template-config + vmapi
3129
Image format: OVM OVA
32-
- Vagrant (VirtualBox provider - requires VirtualBox for the build)
30+
- Vagrant (VirtualBox provider) (x86_64)
3331
Target packages: VirtualBox guest additions
3432
Image format: box
35-
- Vagrant (libvirt provider)
33+
- Vagrant (libvirt provider) (x86_64)
3634
Target packages: nfs-utils
3735
Image format: box
38-
- UTM ([UTM for macOS](https://mac.getutm.app/))
36+
- UTM ([UTM for macOS](https://mac.getutm.app/)) (aarch64)
3937
Target packages: none
4038
Image format: utm
4139
__Note__: only for aarch64 distributions
42-
- Generic (No cloud setup)
40+
- Generic (No cloud setup) (x86_64 and aarch64)
4341
Target packages: none
4442
Image format: VirtualBox OVA or QCOW2 (depending on the builder used)
4543

46-
Additional information is available in the [Building (Small) Oracle Linux Images For The Cloud](https://blogs.oracle.com/linux/post/building-small-oracle-linux-images-for-the-cloud) blog post.
44+
## Requirements
45+
46+
### Overview
47+
48+
The tools require a Linux host supporting [KVM](https://linux-kvm.org) virtualization with the following installed:
49+
50+
- [`qemu-kvm`](http://www.qemu.org/) (Including `qemu-img`)
51+
- [`libvirt`](https://libvirt.org/)
52+
- [`virt-install`](https://virt-manager.org/)
53+
- [`libguestfs`](https://libguestfs.org/) (including tools)
54+
55+
Additionally:
56+
57+
- the host architecture must match the architecture of the target image (e.g.: an `aarch64` host is needed to build `aarch64` images)
58+
- the host kernel must support the filesystem used in the guest (e.g.: the host kernel must support `btrfs` to build an image with a `btrfs` filesystem)
59+
60+
For building [HashiCorp Vagrant](https://vagrantup.com/) boxes for the libvirt provider, download the [`create_box.sh`](https://github.com/vagrant-libvirt/vagrant-libvirt/blob/master/tools/create_box.sh) third party script from the [`vagrant-libvirt`](https://github.com/vagrant-libvirt/vagrant-libvirt) project or install [Vagrant](https://vagrantup.com/) and the [`vagrant-libvirt`](https://github.com/vagrant-libvirt/vagrant-libvirt) plugin.
61+
62+
### Oracle Linux 8
63+
64+
```shell
65+
dnf module install virt
66+
dnf install qemu-img libguestfs-tools virt-install
67+
dnf install zip # For UTM images
68+
```
69+
70+
### Oracle Linux 9
71+
72+
```shell
73+
dnf install libvirt qemu-kvm libguestfs
74+
dnf install qemu-img guestfs-tools virt-install
75+
dnf install zip # For UTM images
76+
```
4777

4878
## Build instructions
4979

50-
The build script requires a Linux environment and has been tested on Oracle Linux 7 and 8.
51-
52-
1. Install either QEMU or VirtualBox (VirtualBox required for Vagrant VirtualBox images):
53-
- Oracle Linux 7:
54-
`yum --enablerepo=ol7_kvm_utils group install "Virtualization Host"`
55-
or
56-
`yum --enablerepo=ol7_developer install VirtualBox-7.0`
57-
- Oracle Linux 8:
58-
`dnf module install virt`
59-
or
60-
`dnf --enablerepo=ol8_developer install VirtualBox-7.0`
61-
1. Install `kpartx` and `qemu-img` to manipulate the artifacts
62-
- Oracle Linux 7:
63-
`yum --enablerepo=ol7_kvm_utils install kpartx qemu-img`
64-
- Oracle Linux 8:
65-
`dnf install kpartx qemu-img`
66-
1. Install packer:
67-
- Oracle Linux 7:
68-
`yum --enablerepo=ol7_developer install packer`
69-
- Oracle Linux 8: Download and install Packer from [HashiCorp](https://www.packer.io/downloads/)
70-
1. Cloud specific requirements:
71-
- For `Vagrant` box (VirtualBox provider), install [HashiCorp Vagrant](https://vagrantup.com/)
72-
- For `Vagrant` box (libvirt provider), download the [`create_box.sh`](https://github.com/vagrant-libvirt/vagrant-libvirt/blob/master/tools/create_box.sh) third party script from the [`vagrant-libvirt`](https://github.com/vagrant-libvirt/vagrant-libvirt) project or install [HashiCorp Vagrant](https://vagrantup.com/) and the [`vagrant-libvirt`](https://github.com/vagrant-libvirt/vagrant-libvirt) plugin
73-
1. Clone this repo:
74-
`git clone https://github.com/oracle/oracle-linux.git`
75-
1. The build script need root privileges during the build.
76-
Ensure `sudo` is properly configured for your build user
80+
The image builder does not require system privileges and should not be run as root.
81+
82+
1. Clone this repo:
83+
84+
```shell
85+
git clone https://github.com/oracle/oracle-linux.git
86+
```
87+
7788
1. Set up a separate workspace directory where the image will be built.
7889
Ensure there is enough free space in the workspace partition, the builder will need up the two times the image size.
7990
1. Configure your build environment in the `env.properties` file (or in a copy).
8091
Minimal configuration:
8192
- `WORKSPACE`: path of your workspace directory
8293
- `ISO_URL`: location of the Oracle Linux distribution ISO
83-
- `ISO_CHECKSUM`: checksum for the ISO file. As from packer 1.6.0, you can prepend the checksum type (see [packer documentation](https://www.packer.io/docs/builders/virtualbox/iso#iso_checksum))
84-
- `CLOUD`: cloud target (azure, oci, olvm, ovm or none)
85-
- `PACKER_BUILDER`: builder used by packer (virtualbox-iso.x86-64 or qemu.x86-64)
86-
1. Run the builder:
87-
`./bin/build-image.sh --env ENV_PROPERTY_FILE`
94+
- `ISO_CHECKSUM`: checksum for the ISO file
95+
Checksums files are available on the [Verify Oracle Linux Downloads](https://linux.oracle.com/security/gpg/) page
96+
- `CLOUD`: cloud target (azure, oci, olvm, ovm, utm, vagrant-libvirt, vagrant-virtualbox or none)
97+
1. Run the builder as a non-privileged user:
98+
99+
```shell
100+
./bin/build-image.sh --env ENV_PROPERTY_FILE`
101+
```
88102

89103
## Advanced configuration
90104

@@ -96,7 +110,7 @@ In that case, you will have to provide an URL to an installation tree and option
96110
Example for an Oracle Linux 9 using the UEK boot ISO:
97111

98112
```Shell
99-
ISO_URL="https://yum.oracle.com/ISOS/OracleLinux/OL9/u2/x86_64/OracleLinux-R9-U2-x86_64-boot-uek.iso"
113+
ISO_URL="https://yum.oracle.com/ISOS/OracleLinux/OL9/u3/x86_64/OracleLinux-R9-U3-x86_64-boot-uek.iso"
100114
REPO_URL="https://yum.oracle.com/repo/OracleLinux/OL9/baseos/latest/x86_64"
101115
REPO[AppStream]="https://yum.oracle.com/repo/OracleLinux/OL9/appstream/x86_64"
102116
REPO[ol9_UEKR7]="https://yum.oracle.com/repo/OracleLinux/OL9/UEKR7/x86_64"
@@ -127,8 +141,10 @@ For a given Oracle Linux distribution and target Cloud, the following properties
127141
- Local `env.properties` file (passed as parameter to the builder)
128142
129143
Files are processed in that order.
130-
Changes should be made to a local env.properties file which can override any definition made in an upstream property file.
131-
Relevant parameters are documented in the distributed [`env.properties`](env.properties) file.
144+
Changes should be made to the local env.properties file which will override any definition made in an upstream property file.
145+
Relevant parameters are documented in the distributed [`env.properties`](env.properties) sample file.
146+
147+
![File layout and process](images/olit.png)
132148
133149
## Cloud specific notes
134150
@@ -140,11 +156,11 @@ This can be done from the Console, or using the [Command Line Interface (CLI)](h
140156
```shell
141157
# Upload in the Object Storage Bucket
142158
oci os object put -bn my_bucket \
143-
--file /workspace/OL7U9_x86_64-oci-b0/OL7U9_x86_64-oci-b0.qcow
159+
--file /workspace/OL7U9_x86_64-oci-b0/OL7U9_x86_64-oci-b0.qcow2
144160
# Import as Custom image
145161
oci compute image import from-object -bn my_bucket \
146162
--namespace my_namespace \
147-
--name OL7U9_x86_64-oci-b0.qcow \
163+
--name OL7U9_x86_64-oci-b0.qcow2 \
148164
--display-name MyImage \
149165
--launch-mode PARAVIRTUALIZED \
150166
--source-image-type QCOW2
@@ -171,7 +187,7 @@ For cloud-init support, you will need to specify `CLOUD_INIT="Yes"` in your `env
171187
172188
The `build-image` script relies on the following directory structure:
173189
174-
- distr: directory for all Oracle Linux distribution
190+
- distr: directory for all Oracle Linux distributions
175191
- _distribution name_
176192
- env.properties: distribution parameters
177193
- _name_-ks.cfg: kickstart file for the distribution
@@ -203,13 +219,11 @@ The builder will process the directories in the following order:
203219
- distr::kickstart
204220
- cloud_distr::kickstart
205221
- custom::kickstart
206-
1. Select a packer configuration file and customise it. The following hooks are called if defined:
207-
- distr::packer_conf
208-
- cloud_distr::packer_conf
209-
- custom::packer_conf
210-
1. Stage files from the _files_ directories. These files are copied during provisioning in `/tmp/packer_files` in the VM.
211-
1. Run packer to provision the VM image.
212-
During provisioning the `provision.sh` scripts run in the following order:
222+
1. Stage files from the _files_ directories. These files are copied during provisioning in `PROVISION_DIR` in the VM.
223+
1. Run `virt-install` to create the image as described in the kickstart file.
224+
1. Run `virt-customize` to actually provision the image.
225+
The optional `::customize_args` hooks in the `image_scripts.sh` files are invoked to provide additional arguments to `virt-customize`.
226+
The `provision.sh` scripts run in the following order:
213227
- distr::provision
214228
- cloud::provision
215229
- cloud_distr::provision
@@ -218,23 +232,14 @@ The builder will process the directories in the following order:
218232
- cloud_distr::cleanup
219233
- cloud::cleanup
220234
- distr::cleanup
221-
- distr::seal[^1]
222-
1. Image cleanup: the generated image is mounted on the host and the `image-scripts` scripts are run[^1]:
223-
- custom::cleanup
224-
- cloud_distr::cleanup
225-
- cloud::cleanup
226-
- distr::cleanup
235+
1. Run `virt-sysprep` to _seal_ the image (final cleanup).
236+
The optional `::sysprep_args` hooks in the `image_scripts.sh` files are invoked to provide additional arguments to `virt-sysprep`.
227237
1. Image packaging: the generated image is packaged in its final format.
228238
Only the first script found is executed:
229239
- custom::image_package
230240
- cloud_distr::image_package
231241
- cloud::image_package
232242
233-
[^1]: `provision` `seal` vs. `image-scripts` `cleanup`.
234-
These functions have the same purpose: _seal_ the image before packaging.
235-
The difference is that the former runs in the VM while the latter runs on the host.
236-
Sealing on the host might be more efficient, but when it is not possible to mount the image disk on the host, in-VM sealing can be used. When no `image-scripts` `cleanup` are defined, no attempt will be made to mount the filesystem on the host.
237-
238243
## Feedback
239244
240245
Please provide feedback of any kind via GitHub issues on this repository.

0 commit comments

Comments
 (0)