Installing Custom CentOS 7 On Oracle Cloud

I jumped on the Oracle Cloud free offer, but couldn’t see a way to do a custom CentOS install. There could be many reasons not to use Oracle’s CentOS image. Creating a LUKS-encrypted partition, just for example. Here’s one way to get there by using VirtualBox.

1. Create a new CentOS 7 VM in VirtualBox.

  • In Settings->System, make sure “Enable EFI” is checked
  • In Settings->Serial ports, check “Enable serial port”, and have the COM1 port mode set to Disconnected.
  • When creating a virtual disk, be sure to use VMDK format and don’t segment it. Keep the size small, e.g. 5 GB.

2. Install CentOS 7

Nothing special, just make sure you’ve got an unecrypted /boot and /boot/efi partition.

3. Boot the new VM

Set it up for console access. As root:
echo 'GRUB_SERIAL_COMMAND="serial --unit=0 --speed=115200"' >> /etc/default/grub
echo 'GRUB_TERMINAL="serial console"' >> /etc/default/grub
sed -i "s/^\(GRUB_CMDLINE_LINUX.*\).$/\1 console=tty1 console=ttyS0,115200\"/" /etc/default/grub
grub2-mkconfig -o /boot/grub2/grub.cfg

Then:
cp -p /boot/efi/EFI/centos/grubx64.efi /boot/efi/EFI/BOOT/
cp /etc/sysconfig/network-scripts/ifcfg-enp0s3 /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i "s/UUID/#UUID/" /etc/sysconfig/network-scripts/ifcfg-eth0

You might need to replace the adapter name to match your system; just make sure you have an ifcfg-eth0 file using DHCP with ONBOOT=yes.

4. Halt the VM and upload the VMDK file.

In the Oracle Cloud console, go to Object Storage -> Object Storage, create a bucket if none exists, then click “Upload objects” and upload the VMDK file.

5. Create an image

After the VMDK object has been uploaded, click “View object details” and copy the URI.

Go to Compute -> Custom images, click “Import image”, in the “Object storage URL” field paste the URI. Be sure VMDK format and Paravirtualized mode are selected, then click “Import image”.

When complete (takes a few minutes) click “Edit Details” and check the VM.Standard.E2.1.Micro shape.

6. Create VM

Once the custom image exists, it is simply a matter of “Create Instance”. Nothing much should need to be done after it starts, except for expanding the partition.

2 Likes

I can’t even get past “Out of host capacity” :rofl:

If you try to create a free VM outside your home region, or more than 2 VMs of any shape inside any region, you get that error. If this doesn’t apply, then keep trying!

Awesome! Thanks for the guide, I’m sure it’ll help some peeps here :slight_smile:

I wonder if something similar can be done for Debian installs since only Ubuntu is listed.

Had a reason to revisit this. Most Linux versions seem to follow a very similar process, with the biggest hassle associated with getting the serial console working. I did Alpine today, and needed:

sed -i "s/^\(GRUB_CMDLINE_LINUX.*\).$/\1 console=ttyS0,115200\"/" /etc/default/grub
sed -i -e "s/^#ttyS0/ttyS0/" /etc/inittab
echo ttyS0 >> /etc/securetty
1 Like