Prepare an Oracle Linux virtual machine for Azure

Applies to: ✔️ Linux VMs ✔️ Flexible scale sets

This article assumes that you have already installed an Oracle Linux operating system to a virtual hard disk. Multiple tools exist to create .vhd files, for example a virtualization solution such as Hyper-V. For instructions, see Install the Hyper-V Role and Configure a Virtual Machine.

Oracle Linux installation notes

  • Please see also General Linux Installation Notes for more tips on preparing Linux for Azure.
  • Hyper-V and Azure support Oracle Linux with either the Unbreakable Enterprise Kernel (UEK) or the Red Hat Compatible Kernel.
  • Oracle's UEK2 is not supported on Hyper-V and Azure as it does not include the required drivers.
  • The VHDX format is not supported in Azure, only fixed VHD. You can convert the disk to VHD format using Hyper-V Manager or the convert-vhd cmdlet.
  • Kernel support for mounting UDF file systems is required. At first boot on Azure the provisioning configuration is passed to the Linux VM via UDF-formatted media that is attached to the guest. The Azure Linux agent must be able to mount the UDF file system to read its configuration and provision the VM.
  • When installing the Linux system it is recommended that you use standard partitions rather than LVM (often the default for many installations). This will avoid LVM name conflicts with cloned VMs, particularly if an OS disk ever needs to be attached to another VM for troubleshooting. LVM or RAID may be used on data disks if preferred.
  • Linux kernel versions earlier than 2.6.37 don't support NUMA on Hyper-V with larger VM sizes. This issue primarily impacts older distributions using the upstream Red Hat 2.6.32 kernel, and was fixed in Oracle Linux 6.6 and later
  • Do not configure a swap partition on the OS disk. More information about this can be found in the steps below.
  • All VHDs on Azure must have a virtual size aligned to 1MB. When converting from a raw disk to VHD you must ensure that the raw disk size is a multiple of 1MB before conversion. See Linux Installation Notes for more information.
  • Make sure that the Addons repository is enabled. Edit the file /etc/yum.repos.d/public-yum-ol6.repo(Oracle Linux 6) or /etc/yum.repos.d/public-yum-ol7.repo(Oracle Linux 7), and change the line enabled=0 to enabled=1 under [ol6_addons] or [ol7_addons] in this file.

Oracle Linux 6.4 and later

You must complete specific configuration steps in the operating system for the virtual machine to run in Azure.

  1. In the center pane of Hyper-V Manager, select the virtual machine.

  2. Click Connect to open the window for the virtual machine.

  3. Uninstall NetworkManager by running the following command:

    # sudo rpm -e --nodeps NetworkManager
    

    Note: If the package is not already installed, this command will fail with an error message. This is expected.

  4. Create a file named network in the /etc/sysconfig/ directory that contains the following text:

    NETWORKING=yes
    HOSTNAME=localhost.localdomain
    
  5. Create a file named ifcfg-eth0 in the /etc/sysconfig/network-scripts/ directory that contains the following text:

    DEVICE=eth0
    ONBOOT=yes
    BOOTPROTO=dhcp
    TYPE=Ethernet
    USERCTL=no
    PEERDNS=yes
    IPV6INIT=no
    
  6. Modify udev rules to avoid generating static rules for the Ethernet interface(s). These rules can cause problems when cloning a virtual machine in Microsoft Azure or Hyper-V:

    # sudo ln -s /dev/null /etc/udev/rules.d/75-persistent-net-generator.rules
    # sudo rm -f /etc/udev/rules.d/70-persistent-net.rules
    
  7. Ensure the network service will start at boot time by running the following command:

    # chkconfig network on
    
  8. Install python-pyasn1 by running the following command:

    # sudo yum install python-pyasn1
    
  9. Modify the kernel boot line in your grub configuration to include additional kernel parameters for Azure. To do this open "/boot/grub/menu.lst" in a text editor and ensure that the kernel includes the following parameters:

    console=ttyS0 earlyprintk=ttyS0 rootdelay=300
    

    This will ensure all console messages are sent to the first serial port, which can assist Azure support with debugging issues.

    In addition to the above, it is recommended to remove the following parameters:

    rhgb quiet crashkernel=auto
    

    Graphical and quiet boot are not useful in a cloud environment where we want all the logs to be sent to the serial port.

    The crashkernel option may be left configured if desired, but note that this parameter will reduce the amount of available memory in the VM by 128MB or more, which may be problematic on the smaller VM sizes.

  10. Ensure that the SSH server is installed and configured to start at boot time. This is usually the default.

  11. Install the Azure Linux Agent by running the following command. The latest version is 2.0.15.

    # sudo yum install WALinuxAgent
    

    Note that installing the WALinuxAgent package will remove the NetworkManager and NetworkManager-gnome packages if they were not already removed as described in step 2.

  12. Do not create swap space on the OS disk.

    The Azure Linux Agent can automatically configure swap space using the local resource disk that is attached to the VM after provisioning on Azure. Note that the local resource disk is a temporary disk, and might be emptied when the VM is deprovisioned. After installing the Azure Linux Agent (see previous step), modify the following parameters in /etc/waagent.conf appropriately:

    ResourceDisk.Format=y
    ResourceDisk.Filesystem=ext4
    ResourceDisk.MountPoint=/mnt/resource
    ResourceDisk.EnableSwap=y
    ResourceDisk.SwapSizeMB=2048    ## NOTE: set this to whatever you need it to be.
    
  13. Run the following commands to deprovision the virtual machine and prepare it for provisioning on Azure:

    # sudo waagent -force -deprovision
    # export HISTSIZE=0
    # logout
    
  14. Click Action -> Shut Down in Hyper-V Manager. Your Linux VHD is now ready to be uploaded to Azure.


Oracle Linux 7.0 and later

Changes in Oracle Linux 7

Preparing an Oracle Linux 7 virtual machine for Azure is very similar to Oracle Linux 6, however there are several important differences worth noting:

  • Azure supports Oracle Linux with either the Unbreakable Enterprise Kernel (UEK) or the Red Hat Compatible Kernel. Oracle Linux with UEK is recommended.
  • The NetworkManager package no longer conflicts with the Azure Linux agent. This package is installed by default and we recommend that it is not removed.
  • GRUB2 is now used as the default bootloader, so the procedure for editing kernel parameters has changed (see below).
  • XFS is now the default file system. The ext4 file system can still be used if desired.

Configuration steps

  1. In Hyper-V Manager, select the virtual machine.

  2. Click Connect to open a console window for the virtual machine.

  3. Create a file named network in the /etc/sysconfig/ directory that contains the following text:

    NETWORKING=yes
    HOSTNAME=localhost.localdomain
    
  4. Create a file named ifcfg-eth0 in the /etc/sysconfig/network-scripts/ directory that contains the following text:

    DEVICE=eth0
    ONBOOT=yes
    BOOTPROTO=dhcp
    TYPE=Ethernet
    USERCTL=no
    PEERDNS=yes
    IPV6INIT=no
    
  5. Modify udev rules to avoid generating static rules for the Ethernet interface(s). These rules can cause problems when cloning a virtual machine in Microsoft Azure or Hyper-V:

    # sudo ln -s /dev/null /etc/udev/rules.d/75-persistent-net-generator.rules
    
  6. Ensure the network service will start at boot time by running the following command:

    # sudo chkconfig network on
    
  7. Install the python-pyasn1 package by running the following command:

    # sudo yum install python-pyasn1
    
  8. Run the following command to clear the current yum metadata and install any updates:

    # sudo yum clean all
    # sudo yum -y update
    
  9. Modify the kernel boot line in your grub configuration to include additional kernel parameters for Azure. To do this open "/etc/default/grub" in a text editor and edit the GRUB_CMDLINE_LINUX parameter, for example:

    GRUB_CMDLINE_LINUX="rootdelay=300 console=ttyS0 earlyprintk=ttyS0 net.ifnames=0"
    

    This will also ensure all console messages are sent to the first serial port, which can assist Azure support with debugging issues. It also turns off the naming conventions for NICs in Oracle Linux 7 with the Unbreakable Enterprise Kernel. In addition to the above, it is recommended to remove the following parameters:

       rhgb quiet crashkernel=auto
    

    Graphical and quiet boot are not useful in a cloud environment where we want all the logs to be sent to the serial port.

    The crashkernel option may be left configured if desired, but note that this parameter will reduce the amount of available memory in the VM by 128MB or more, which may be problematic on the smaller VM sizes.

  10. Once you are done editing "/etc/default/grub" per above, run the following command to rebuild the grub configuration:

    # sudo grub2-mkconfig -o /boot/grub2/grub.cfg
    
  11. Ensure that the SSH server is installed and configured to start at boot time. This is usually the default.

  12. Install the Azure Linux Agent and dependencies:

    sudo yum install WALinuxAgent
    sudo systemctl enable waagent
    
  13. Install cloud-init to handle the provisioning

    yum install -y cloud-init cloud-utils-growpart gdisk hyperv-daemons
    
    # Configure waagent for cloud-init
    sed -i 's/Provisioning.UseCloudInit=n/Provisioning.UseCloudInit=y/g' /etc/waagent.conf
    sed -i 's/Provisioning.Enabled=y/Provisioning.Enabled=n/g' /etc/waagent.conf
    
    
    echo "Adding mounts and disk_setup to init stage"
    sed -i '/ - mounts/d' /etc/cloud/cloud.cfg
    sed -i '/ - disk_setup/d' /etc/cloud/cloud.cfg
    sed -i '/cloud_init_modules/a\\ - mounts' /etc/cloud/cloud.cfg
    sed -i '/cloud_init_modules/a\\ - disk_setup' /etc/cloud/cloud.cfg
    
    echo "Allow only Azure datasource, disable fetching network setting via IMDS"
    cat > /etc/cloud/cloud.cfg.d/91-azure_datasource.cfg <<EOF
    datasource_list: [ Azure ]
    datasource:
        Azure:
            apply_network_config: False
    EOF
    
    if [[ -f /mnt/resource/swapfile ]]; then
    echo Removing swapfile - RHEL uses a swapfile by default
    swapoff /mnt/resource/swapfile
    rm /mnt/resource/swapfile -f
    fi
    
    echo "Add console log file"
    cat >> /etc/cloud/cloud.cfg.d/05_logging.cfg <<EOF
    
    # This tells cloud-init to redirect its stdout and stderr to
    # 'tee -a /var/log/cloud-init-output.log' so the user can see output
    # there without needing to look on the console.
    output: {all: '| tee -a /var/log/cloud-init-output.log'}
    EOF
    
    
  14. Swap configuration Do not create swap space on the operating system disk.

    Previously, the Azure Linux Agent was used automatically configure swap space by using the local resource disk that is attached to the virtual machine after the virtual machine is provisioned on Azure. However this is now handled by cloud-init, you must not use the Linux Agent to format the resource disk create the swap file, modify the following parameters in /etc/waagent.conf appropriately:

    sed -i 's/ResourceDisk.Format=y/ResourceDisk.Format=n/g' /etc/waagent.conf
    sed -i 's/ResourceDisk.EnableSwap=y/ResourceDisk.EnableSwap=n/g' /etc/waagent.conf
    

    If you want mount, format and create swap you can either:

    • Pass this in as a cloud-init config every time you create a VM

    • Use a cloud-init directive baked into the image that will do this every time the VM is created:

      cat > /etc/cloud/cloud.cfg.d/00-azure-swap.cfg << EOF
      #cloud-config
      # Generated by Azure cloud image build
      disk_setup:
        ephemeral0:
          table_type: mbr
          layout: [66, [33, 82]]
          overwrite: True
      fs_setup:
        - device: ephemeral0.1
          filesystem: ext4
        - device: ephemeral0.2
          filesystem: swap
      mounts:
        - ["ephemeral0.1", "/mnt"]
        - ["ephemeral0.2", "none", "swap", "sw", "0", "0"]
      EOF
      
  15. Run the following commands to deprovision the virtual machine and prepare it for provisioning on Azure:

    # Note: if you are migrating a specific virtual machine and do not wish to create a generalized image,
    # skip the deprovision step
    # sudo rm -rf /var/lib/waagent/
    # sudo rm -f /var/log/waagent.log
    
    # waagent -force -deprovision+user
    # rm -f ~/.bash_history
    
    
    # export HISTSIZE=0
    
    # logout
    
  16. Click Action -> Shut Down in Hyper-V Manager. Your Linux VHD is now ready to be uploaded to Azure.

Next steps

You're now ready to use your Oracle Linux .vhd to create new virtual machines in Azure. If this is the first time that you're uploading the .vhd file to Azure, see Create a Linux VM from a custom disk.