Skip to content

Instantly share code, notes, and snippets.

@zackbradys
Created June 5, 2023 18:09
Show Gist options
  • Save zackbradys/2f5c07114905c4dc6a7e0e3e2e4cac53 to your computer and use it in GitHub Desktop.
Save zackbradys/2f5c07114905c4dc6a7e0e3e2e4cac53 to your computer and use it in GitHub Desktop.
# RUN THIS ON LINUX! Below is using an Ubuntu VM to build your qcow
# Install 'libguestfs-tools' to get 'virt-customize'
apt-get install -y libguestfs-tools # ubuntu
# yum install -y libguestfs-tools # rhel
# Download the latest cloud-enabled Rocky image
wget -O /tmp/rocky-cloud.qcow2 https://download.rockylinux.org/pub/rocky/8/images/x86_64/Rocky-8-GenericCloud-LVM.latest.x86_64.qcow2 # LVM
# wget -O /tmp/rocky-cloud.qcow2 https://download.rockylinux.org/pub/rocky/8/images/x86_64/Rocky-8-GenericCloud-Base.latest.x86_64.qcow2 # Base
# Add commands (add whatever else you need here, but make sure to leave the last 'echo' line!)
cat <<EOT > /tmp/commands
# Run a script from the host
run /tmp/example-script.sh
# Run commands directly
run-command yum install -y ca-certificates cloud-init qemu-guest-agent
run-command mkdir -p /etc/pki/ca-trust/source/anchors
# Copy files from host into image, like a CA for instance
copy-in /tmp/example-ca.pem:/etc/pki/ca-trust/source/anchors
# Commands run sequentially, so this will update the CA after it was copied in
run-command update-ca-trust
# DO NOT DELETE THIS, REQUIRED
run-command echo -n > /etc/machine-id
EOT
# Customize the qcow2 with the updated commands above
virt-customize -a /tmp/rocky-cloud.qcow2 --commands-from-file /tmp/commands
echo "Done! Upload 'rocky-cloud.qcow2' to your Harvester images."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment