The latest cloud infrastructure announcements, technical solutions, and enterprise cloud insights.

Using Packer and VirtualBox to bring your own image into Oracle Cloud Infrastructure

Zeke Kaufman
Solution Architect

Oracle Cloud Infrastructure (OCI) offers a wide variety of operating systems that suit the needs of most large enterprises and customers. However, a company might require a specific or specially customized operating system that’s not native to the underlying infrastructure. Businesses looking to migrate from on-premises to the cloud, but have strict operating system requirements that prevent them from using a native platform image, still can bring your own image (BYOI) into OCI.

This blog provides solution architects and cloud engineers with an automated and easily configurable way to BYOI into Oracle Cloud. It uses VirtualBox as the virtualization environment and Packer to do the heavy lifting. With the execution of a single command, you can go from any Linux distribution installation media to a fully customized instance running in OCI.

Only use this method when the native platform images don’t satisfy some strict set of requirements, such as an OS platform requirement, Linux kernel version, and so on. You always get better support and improved performance when using native platform images.

Let’s look at how you can import your own customized image into OCI.


You also need to create a Cloud Profile in VirtualBox to link it with your OCI account. You can find instructions in this technical brief.

Packer templates

An in-depth description of Packer is outside the scope of this blog post. For this tutorial, a Packer configuration file, also called a template, is a JSON object with a set of keys configuring various components of Packer. Our Packer file has two main components:

A screenshot of the example Packer file running in the terminal.

  • Builders: The builders section contains all the code responsible for creating, installing, and configuring the OS in VirtualBox. Builders contain information like the disk size, memory, and shape of the virtual machine (VM). In our case, the builders section also contains a link to the Linux ISO distribution media and a pointer to a preconfiguration file for automating the OS installation.

  • Provisioners: The provisioners section contains a list of provisioners that Packer uses to perform any other OS configuration and install any additional software. Packer has many provisioner types. In this example, we use the 'shell' type, which enables us to run a series of scripts. The OCI.sh script performs the necessary configuration to make the image compatible within OCI, namely, adding kernel boot parameters and renaming the VNIC. The cleanup.sh performs some basic actions related to cleaning up the image and reducing its size for upload.

If you start with this code as a template for your workflows, insert another script in the provisioners section. The added script is responsible for downloading and installing any additional software you want to test.

Build the image

To build the image, run the packer build command in the top-level directory of the GitHub repo:

packer build <json_template>

When the build process is complete, issue the following command. It uploads the image into Oracle Cloud Object Storage, creates a custom image, and deploys an instance. Replace the following arguments with values specific to your environment:

VBoxManage export debian-10.6-1299708... \   
      --output OCI:// \                   
      --cloud 0 \
      --vmname debian-10.6_packer \      
      --cloudprofile DEFAULT \      
      --cloudbucket vbox-upload \   
      --cloudlaunchmode PARAVIRTUALIZED \
      --cloudshape VM.Standard2.1 \
      --clouddomain IYfK:US-ASHBURN-AD-1 \
      --clouddisksize 120 \
      --cloudocivcn ocid1.vcn.oc1.iad.amaaa... \     
      --cloudocisubnet ocid1.subnet.oc1.iad.aaaaa... \  
      --cloudkeepobject true \
      --cloudlaunchinstance true \
      --cloudpublicip true

Now begins the part when you start testing in OCI. Log in to the tenancy where the instance was launched, and get its public IP address. You can now SSH into the instance using the public IP and the username and password specified in the preseed file.

A screenshot of the Packer file running in Oracle Cloud Infrastructure.

ssh opc@

Other considerations

You have a few other considerations to take into account before using this workflow in your environment:

  • Ensure that your custom image follows the requirements specified in the Importing Custom Linux Images documentation.

  • You can add a Vagrant post-processor to the packer template if your company already uses Vagrant boxes for building and managing VM environments. Having a Vagrant box eases the burden of making modifications and maintaining an existing custom image.

In closing...

Hopefully, you have successfully tested your application within Oracle Cloud Infrastructure. If the application being tested is a business product with customers, consider adding it to Oracle Marketplace. Creating a listing in Marketplace widens your potential customer base and creates more exposure for your business offerings. The same automated workflow outlined in this post to test your application can be refined to test future versions of your application and test against alternate operating systems. When plugged into a DevOps development framework, maintaining your Marketplace Listings with CI/CD with up-to-date versions of your products is a piece of cake!

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha