How to Add Custom Oracle Linux Images to Google Cloud (GCP)

Google Cloud doesn’t ship Oracle Linux by default, so you have to roll up your sleeves and do it yourself.


GCP Compute Engine & Images: A Quick Intro

Google Cloud’s Compute Engine is a powerful virtual machine (VM) hosting service that lets you spin up instances in the blink of an eye. Normally, you choose from Google’s prebuilt images—Ubuntu, Debian, Red Hat, etc.—but Oracle Linux? Not in the default lineup.

That’s where custom images come in. They allow you to bring your own OS configurations into GCP, ensuring consistency across environments. The process involves:

  1. Getting an Oracle Linux image (OVA format).
  2. Uploading it to Google Cloud Storage.
  3. Importing it into Compute Engine.
  4. Creating a reusable image from it.

Now, let’s get to the fun part—actually doing it.


Step 1: Get Your Oracle Linux OVA Image

Oracle conveniently provides ready-to-use images for Oracle Linux. You can download them from:

Oracle Linux Templates

For this example, we’ll use Oracle Linux 9.5:

wget https://yum.oracle.com/templates/OracleLinux/OL9/u5/x86_64/OL9U5_x86_64-olvm-b253.ova

This OVA file is basically a pre-packaged VM image, containing everything needed to run Oracle Linux in a virtualized environment.

Step 2: Upload the Image to Google Cloud Storage

Before you can use the image in GCP, you need to upload it to a Cloud Storage bucket.

You can check your buckets with

gsutil ls

You can use gcloud in case you need to switch the project

gcloud config set 

If you don’t have a bucket ready yet, create it:

gsutil mb gs://my-oracle-linux-bucket`

Now, upload the OVA file:

gsutil cp OL9U5_x86_64-olvm-b253.ova gs://my-oracle-linux-bucket/

Depending on your internet speed, you might want to grab a coffee. Or two.

Step 3: Import the Image into Compute Engine

Once the OVA file is in Google Cloud Storage, we can import it as a Compute Engine VM. Google’s gcloud CLI makes this process easy:

Documentation: gcloud

gcloud compute instances import oracle-linux-9 \
  --source-uri=gs://my-oracle-linux-bucket/OL9U5_x86_64-olvm-b253.ova \
  --os=rhel-9-byol \
  --project=<gcp_project> \
  --subnet=default \
  --zone=europe-west1-b \
  --machine-type=e2-standard-2

Some important flags here:

  • --project=<gcp_project>: Adjust to your project id
  • --source-uri: The location of your OVA file.
  • --os=rhel-9-byol: Google doesn’t have an oracle-linux flag, but since Oracle Linux is binary-compatible with RHEL, this works just fine.
  • --machine-type: Adjust this if required, but the system will be deleted after we captured the image.
  • --subnet and --zone: Might by different in your environment. Check on existing VMs if you are not sure.

This step might take a few minutes while Google processes and imports the image—perfect time for a quick shower! 😉

Step 4: Shut Down the VM

Once your VM is up and running, you can make any necessary modifications before shutting it down to convert its disk into a reusable image.

Documentation: gcloud

gcloud compute instances stop oracle-linux-9 \
  --project=<gcp_project> \
  --zone=europe-west1-b

Step 5: Create a Custom Image from the Disk

Now comes the grand finale: turning the VM’s disk into a reusable custom image.

Documentation: gcloud

gcloud compute images create oracle-linux-9 \
  --project=<gcp_project> \
  --family=oracle-linux-9 \
  --source-disk=oracle-linux-9 \
  --source-disk-zone=europe-west1-b \
  --storage-location=eu \
  --description="Custom Oracle Linux image"

Once completed, this custom image can be used to launch new instances on GCP anytime, without having to re-import the OVA.

Step 6: Copy the Image to a Different Project (optional)

If you need to use your custom Oracle Linux image in another Google Cloud project, you can easily copy it over. This ensures consistency across environments without having to repeat the import process.

Run the following command to duplicate the image into a different project:

gcloud compute --project=<destination_project> images create oracle-linux-9 \
  --family=oracle-linux-9 \
  --source-image=oracle-linux-9 \
  --source-image-project=<source_project>

Once completed, the image will be available in the destination project, ready to launch instances just like in the original project.

Final Thoughts

Congratulations! You’ve successfully imported an Oracle Linux image into Google Cloud and created a reusable VM image. Now you can spin up Oracle Linux instances whenever you need, all while enjoying the flexibility and scalability of GCP.

This post is licensed under CC BY 4.0 by the author.