Step by Step-Prepare a CentOS-Based Virtual Machine for Azure

Prerequisites CentOS Installation Notes

  • The newer VHDX format is not supported in Azure. You can convert the disk to VHD format using Hyper-V Manager or the convert-vhd cmdlet.

  • 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.

  • NUMA is not supported for larger VM sizes due to a bug in Linux kernel versions below 2.6.37. This issue primarily impacts distributions using the upstream Red Hat 2.6.32 kernel. Manual installation of the Azure Linux agent (waagent) will automatically disable NUMA in the GRUB configuration for the Linux kernel. More information about this can be found in the steps below.

  • Do not configure a swap partition on the OS disk. The Linux agent can be configured to create a swap file on the temporary resource disk. More information about this can be found in the steps below.

  • All of the VHDs must have sizes that are multiples of 1 MB.

Prepare CentOS 6.x based virtual machine for Azure. This step only for 6.x version. CentOS 6.3 and CentOS 7.x is not proper below step.

1. Install the python-pyasn1 package by running the following command:
# sudo yum install python-pyasn1


2. If you would like to use the OpenLogic mirrors that are hosted within the Azure datacenters, then replace the /etc/yum.repos.d/CentOS-Base.repo file with the following repositories. This will also add the [openlogic] repository that includes packages for the Azure Linux agent:
name=CentOS-$releasever - openlogic packages for $basearch
name=CentOS-$releasever - Base
#released updates
name=CentOS-$releasever - Updates
#additional packages that may be useful
name=CentOS-$releasever - Extras
#additional packages that extend functionality of existing packages
name=CentOS-$releasever - Plus
#contrib - packages by Centos Users
name=CentOS-$releasever - Contrib

Note: The rest of this guide will assume you are using at least the [openlogic] repo, which will be used to install the Azure Linux agent below.


3. Add the following line to /etc/yum.conf
vi /etc/yum.conf


4. Add under [main] type the following


5. Disable the yum module "fastestmirror" by editing the file "/etc/yum/pluginconf.d/fastestmirror.conf"
vi /etc/yum/pluginconf.d/fastestmirror.conf


6. Add under [main] type the following
set enabled=0


7. Run the following command to clear the current yum metadata:
# yum clean all


8. Modify the kernel boot line in your grub configuration to include additional kernel parameters for Azure. To do this open "/boot/grub/menu.lst":
vi /boot/grub/menu.lst


9. In menu.lst and ensure that the default kernel includes the following parameters:
console=ttyS0 earlyprintk=ttyS0 rootdelay=300 numa=off

This will also ensure all console messages are sent to the first serial port, which can assist Azure support with debugging issues. This will disable NUMA due to a bug in the kernel version used by CentOS 6.

In addition to the above, it is recommended to remove the following parameters:
rhgb quiet crashkernel=auto

Red need Add
Blue need Delete


10. Final edit result in menu.lst


11. Install the Azure Linux Agent by running the following command, and will be get error that installing the WALinuxAgent package will need remove the NetworkManager and NetworkManager-gnome packages before. Following next step.
# sudo yum install WALinuxAgent


12. 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.


13. Create a file named network in the /etc/sysconfig/ directory.
vi /etc/sysconfig/network


14. Add contains the following text:


15. Create a file named ifcfg-eth0 in the /etc/sysconfig/network-scripts/ directory.
vi /etc/sysconfig/network-scripts/ifcfg-eth0


16. Add contains the following text:


17. Move (or remove) udev rules to avoid generating static rules for the Ethernet interface. These rules cause problems when cloning a virtual machine in Microsoft Azure or Hyper-V:
# sudo mkdir -m 0700 /var/lib/waagent
# sudo mv /lib/udev/rules.d/75-persistent-net-generator.rules /var/lib/waagent/
# sudo mv /etc/udev/rules.d/70-persistent-net.rules /var/lib/waagent/


18. Ensure the network service will start at boot time by running the following command:
# sudo chkconfig network on


19. Install the Azure Linux Agent again by running the following command:
# sudo yum install WALinuxAgent


20. 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:
vi /etc/waagent.conf


21. modify the following parameters in /etc/waagent.conf appropriately:
ResourceDisk.SwapSizeMB=2048 ## NOTE: set this to whatever you need it to be.


22. Run the following commands to deprovision the virtual machine and prepare it for provisioning on Azure:
# sudo waagent -force -deprovision
# export HISTSIZE=0
# logout


23. Shut Down the virtual machine. Now ready to be uploaded to Azure.



Create WIMBoot Images