Press "Enter" to skip to content

Create a custom image for OCI-Classic on macOS

This short article describes how to create a custom image for a server that can be deployed as a “private image” on OCI Classic (formerly known as OPC, or Oracle Public Cloud). This is not really security-related but may still be helpful for someone.

The first step is to use Oracle’s free VirtualBox virtualization app to create a new VM image. Download VirtualBox if you don’t have it and then create a new image.  In my case, I’m creating a FreeBSD VM by first booting from a FreeBSD “boot only” ISO image. I create the VM with two virtual CPUs (vCPUs), 7.5GB of RAM and 50GB of disk since that is the default shape of the smallest image on the Oracle Public Cloud (OPC).

By default VirtualBox creates the VM with VMDK disk files. This doesn’t work with OPC so we need to convert the disk image to an .img format. The easiest way is to follow a two-step procedure, starting with a command line utility that gets installed on the Mac when you first installed VirtualBox. Navigate to the directory for your VM and issue the following command in a terminal window:

VBoxManage clonehd /path/to/MyVMfile.vmdk --format VDI /path/to/MyVMfile.vdi

The next step is to convert the VDI image into an IMG file. Note that this will be a huge file, in this case 50GB with lots of empty space inside, so make sure you have enough space before proceeding:

VBoxManage internalcommands converttoraw /path/to/MyVMfile.vdi /path/to/MyVMfile.img

On Linux and Windows, we would then create a sparse copy of this file to significantly reduced its size. Unfortunately, Mac is based on BSD and their HFS+ filesystem does not support sparse files. Your options are to either copy the file into Linux or Windows and perform a sparse copy before creating a compressed tarball to upload to OPC, or just suck it up and use the massive 50GB file.

Finally, we’ll tar/gzip it up before uploading to Oracle Public Cloud:

tar -czSf /path/to/MyVMfile_sparse.tar.gz /path/to/MyVMfile_sparse.img

You might as well delete the huge .img file now to save space.

Now you can upload this file to the Storage side of OPC using a container named compute_images, then register the image and finally deploy a new instance using your new private image.

If you have any problems, leave a comment here or email me and I’ll see if I can help you out.

Kelly

2 Comments

  1. Harry
    Harry November 16, 2018

    Hi Kelly, I’ve tried following these steps with a pfSense install however I’m running in to issues with the network configuration. Did you encounter any issues with the FreeBSD networking? I’m wondering if my issues are being caused by the interface name difference between OCI and my Virtualbox machine (OCI:eth0 and VB:em0). Due to the lack of console access to the VM in OCI I’m finding it difficult to troubleshoot. Any thoughts you can share would be much appreciated.

  2. Kelly Martin
    Kelly Martin December 7, 2018

    Hi Harry,

    Yes I did have some network issues but was able to resolve them. First off I’ve abandoned OCI-Classic and have moved to OCI instead.

    I installed a fresh copy of FreeBSD into a VM and just uploaded the VMDK file into OCI object storage. Then I created a custom image from that using VMDK emulation mode.

    Before doing that, however, the two networking changes I made were (1) nameservers and (2) use a static route. First I put external nameservers into my /etc/resolv.conf, in my case I used Google’s 8.8.8.8 and 8.8.4.4. Then I made sure the defaultrouter in /etc/rc.conf matched my VCN’s default route in OCI. After that I had no problem.

    By the way, I got console access working with FreeBSD in OCI. Just create a console connection for the instance and connect to it with VNC instead of SSH. The commands provided create a nice SSH tunnel, then you just point your VNC viewer to 127.0.0.1 on port 5900 and it should work.

Leave a Reply

Your email address will not be published.