You are on page 1of 26

Running Red Hat

on Microsoft Azure
Running Red Hat on Microsoft Azure
Hybrid cloud technologies can help you achieve greater business agility, efficiency, and competitive
advantage by unifying heterogeneous IT environments. As a result, 71% of cloud adopters use hybrid
cloud technologies to move their business forward1. Interoperability and portability across environ-
ments are key to successful hybrid cloud implementations. Workloads must be able to run on multiple
platforms and be moved as needs change. Management should be simple and unified. Application
development needs to span physical, virtual, and private and public cloud infrastructures.

CREATE A UNIFIED ENVIRONMENT WITH RED HAT AND MICROSOFT

Together, industry leaders Red Hat and Microsoft give you more choice and flexibility for hybrid cloud
deployments. The companies are committed to delivering enterprise-class operating systems, rigorous
security standards, and an integrated support experience. Through their partnership, Red Hat and
Microsoft:

Deliver and support Red Hat technologies on Microsoft Azure, making Red Hat Enterprise Linux
the preferred choice for production-grade Linux on Azure.

Unify management for environments containing Windows and Linux workloads.

Merge the Microsoft .NET and Linux development and application environments.

As a result, you can:

Deploy applications, workloads, and containers based on Red Hat Enterprise Linux in a Microsoft
Azure cloud environment.

Simply manage your entire hybrid environment and application and container portability from a
single interface.

Easily develop applications that run in both Windows and Linux environments.

The Red Hat and Microsoft partnership offers many customer benefits for both end-users and inde-
pendent software vendors (ISVs).

ENTERPRISE-GRADE SUPPORT

32% of cloud adopters cite a lack of resources and experience to be a challenge in cloud deployment2.
Red Hat and Microsoft deliver comprehensive, integrated, global support across hybrid environments.
Take advantage of a consistent support experience, regardless of whether you run Red Hat products
on premise or in a Microsoft Azure cloud environment. Contact either company for support Red
Hat and Microsoft work together to determine where the issue resides and resolve the problem quick-
ly and efficiently.

Lets have a look now, how to deploy and manage Red Hat-based virtual machines on Azure.

1 RightScale, RightScale 2016 State of the Cloud Report, January 2016

2 RightScale, RightScale 2016 State of the Cloud Report, January 2016.

Running Red Hat on Microsoft Azure 2


How to start with Red Hat on Azure
There are generally 2 options on how to deploy Red Hat on Azure:

1. Go to Azure Marketplace and deploy validated Red Hat images in several clicks. The process is
very simple, everything is self-explanatory in the Marketplace environment and therefore, we will
not cover these details in this technical guide. This option may be good for you in case you want
to run new VMs on Azure that are not covered by your existing licensing agreement with the Red
Hat. Please note, that in this scenario, in addition to the cost of running Linux-type virtual machine
Azure (called Azure infrastructure costs), you will be charged an extra Red Hat licensing fee.

1. You may bring to Azure your own VMs, that are already licensed directly from Red Hat (as per
Red Hat Cloud Access program). For this you will need to do certain actions to prepare your
VM images to be deployed, managed and updated in Azure environment. This eBook will guide
you through step by step, with a lot of technical details and will provide you with examples of
commands. So, lets get started!

Prepare a Red Hat-based virtual


machine for Azure
First in this guide, you will learn how to prepare a Red Hat Enterprise Linux (RHEL) virtual machine
for use in Azure. Versions of RHEL that are covered in this guide are 6.7, 7.1 and 7.2. Hypervisors for
preparation that are covered in this document are Hyper-V, Kernel-based Virtual Machine (KVM), and
VMware. For more information on eligibility requirements for participating in Red Hats Cloud Access
program, see Red Hats Cloud Access website and Running RHEL on Azure.

Prepare a Red Hat-based virtual


machine from Hyper-V Manager
Prerequisites
This section assumes that you have already installed a RHEL image (from an ISO file that you obtained
from Red Hats website) to a virtual hard disk (VHD). For more details on how to use Hyper-V Manager
to install an operating system image, see Install the Hyper-V Role and Configure a Virtual Machine.+

RHEL installation notes


Please see also General Linux Installation Notes for more tips on preparing Linux for Azure.

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

VHDs must be created as fixed--dynamic VHDs are not supported.

When youre installing the Linux system, we recommend 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.

Running Red Hat on Microsoft Azure 3


Do not configure a swap partition on the OS disk. You can configure the Linux agent to create
a swap file on the temporary resource disk. More information about this is available in the steps
below.

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

When you use qemu-img to convert disk images to VHD format, note that there is a known bug
in qemu-img versions 2.2.1 or later. This bug results in an improperly formatted VHD. The issue is
intended to be fixed in an upcoming release of qemu-img. For now, we recommend that you use
qemu-img version 2.2.0 or earlier.

Prepare a RHEL 6.7 virtual machine from Hyper-V Manager


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

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

3. Uninstall NetworkManager by running the following command:

sudo rpm -e --nodeps NetworkManager

Note that 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 IP-


V6INIT=no

6. Move (or remove) udev rules to avoid generating static rules for the Ethernet interface. These rules
cause problems when you clone 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/

7. Ensure that the network service will start at boot time by running the following command:

sudo chkconfig network on

8. Register your Red Hat subscription to enable the installation of packages from the RHEL repository
by running the following command:

sudo subscription-manager register --auto-attach --username=XXX --password=XXX

9. The WALinuxAgent package WALinuxAgent-<version> has been pushed to the Red Hat extras
repository. Enable the extras repository by running the following command:

subscription-manager repos --enable=rhel-6-server-extras-rpms

10. 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 default kernel
includes the following parameters:

console=ttyS0 earlyprintk=ttyS0 rootdelay=300 numa=off

Running Red Hat on Microsoft Azure 4


This will also ensure that 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
that is used by RHEL 6.

In addition to the above action, we recommend that you 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 can be left configured if desired, but note that this parameter will reduce
the amount of available memory in the VM by 128 MB or more. This might be problematic on
smaller VM sizes.

11. Ensure that the SSH server is installed and configured to start at boot time. This is usually the de-
fault. Modify /etc/ssh/sshd_config to include the following line:

ClientAliveInterval 180

12. Install the Azure Linux Agent by running the following command:

sudo yum install WALinuxAgent

sudo chkconfig waagent on

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

13. Do not create swap space on the OS disk. The Azure Linux Agent can automatically configure swap
space by using the local resource disk that is attached to the VM after the VM is provisioned on
Azure. Note that the local resource disk is a temporary disk, and might be emptied when the VM is
deprovisioned. After you install the Azure Linux Agent (see the previous step), modify the follow-
ing 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.

14. Unregister the subscription (if necessary) by running the following command:

sudo subscription-manager unregister

15. Run the following commands to deprovision the virtual machine and prepare it for provisioning on
Azure:

sudo waagent -force -deprovision

export HISTSIZE=0

logout
16. Click Action > Shut Down in Hyper-V Manager. Your Linux VHD is now ready to be uploaded to
Azure.

Prepare a RHEL 7.1/7.2 virtual machine from Hyper-V Manager


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

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

Running Red Hat on Microsoft Azure 5


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 IP-


V6INIT=no

5. Ensure that the network service will start at boot time by running the following command:

sudo chkconfig network on

6. Register your Red Hat subscription to enable the installation of packages from the RHEL repository
by running the following command:

sudo subscription-manager register --auto-attach --username=XXX --password=XXX

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

This will also ensure that all console messages are sent to the first serial port, which can assist
Azure support with debugging issues. In addition to the above action, we recommend that you
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 can be left configured if desired, but note that this
parameter will reduce the amount of available memory in the VM by 128 MB or more. This might
be problematic on smaller VM sizes.

8. After you are done editing /etc/default/grub, run the following command to rebuild the grub con-
figuration:

sudo grub2-mkconfig -o /boot/grub2/grub.cfg

9. Ensure that the SSH server is installed and configured to start at boot time. This is usually the de-
fault. Modify /etc/ssh/sshd_config to include the following line:

ClientAliveInterval 180

10. The WALinuxAgent package WALinuxAgent-<version> has been pushed to the Red Hat extras
repository. Enable the extras repository by running the following command:

subscription-manager repos --enable=rhel-7-server-extras-rpms

11. Install the Azure Linux Agent by running the following command:

sudo yum install WALinuxAgent

sudo systemctl enable waagent.service

Running Red Hat on Microsoft Azure 6


12. Do not create swap space on the OS disk. The Azure Linux Agent can automatically configure swap
space by using the local resource disk that is attached to the VM after the VM is provisioned on
Azure. Note that the local resource disk is a temporary disk, and might be emptied when the VM is
deprovisioned. After you install the Azure Linux Agent (see the previous step), modify the follow-
ing 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. If you want to unregister the subscription, run the following command:

sudo subscription-manager unregister

14. Run the following commands to deprovision the virtual machine and prepare it for provisioning on
Azure:

sudo waagent -force -deprovision

export HISTSIZE=0

logout
15. Click Action > Shut Down in Hyper-V Manager. Your Linux VHD is now ready to be uploaded to
Azure.

Prepare a Red Hat-based


virtual machine from KVM
Prepare a RHEL 6.7 virtual machine from KVM
1. Download the KVM image of RHEL 6.7 from Red Hats website.

2. Set a root password.

Generate an encrypted password and copy the output of the command:

openssl passwd -1 changeme

Set a root password with guestfish:

guestfish --rw -a

run list-filesystems mount /dev/sda1 / vi /etc/shadow exit

Change the second field of the root user from !! to the encrypted password.

3. Create a virtual machine in KVM from the qcow2 image, set the disk type to qcow2, and set the
virtual network interface device model to virtio. Then start the virtual machine and sign in as root.

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 IP-


V6INIT=no

Running Red Hat on Microsoft Azure 7


6. Move (or remove) the udev rules to avoid generating static rules for the Ethernet interface. These
rules cause problems when you clone a virtual machine in Microsoft Azure or Hyper-V:

mkdir -m 0700 /var/lib/waagent

mv /lib/udev/rules.d/75-persistent-net-generator.rules /var/lib/waagent/

mv /etc/udev/rules.d/70-persistent-net.rules /var/lib/waagent/

7. Ensure that the network service will start at boot time by running the following command:

chkconfig network on

8. Register your Red Hat subscription to enable the installation of packages from the RHEL repository
by running the following command:

subscription-manager register --auto-attach --username=XXX --password=XXX

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 default kernel
includes the following parameters:

console=ttyS0 earlyprintk=ttyS0 rootdelay=300 numa=off

This will also ensure that 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
that is used by RHEL 6.

In addition to the above action, we recommend that you 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 128 MB or more. This might
be problematic on smaller VM sizes.

10. Add Hyper-V modules into initramfs:

Edit /etc/dracut.conf and add content: add_drivers+=hv_vmbus hv_netvsc hv_storvsc

Rebuild initramfs:

# dracut f -v

11. Uninstall cloud-init:

yum remove cloud-init

12. Ensure that the SSH server is installed and configured to start at boot time:

chkconfig sshd on

Modify /etc/ssh/sshd_config to include the following lines:

PasswordAuthentication yes ClientAliveInterval 180

Restart sshd:

service sshd restart

Running Red Hat on Microsoft Azure 8


13. The WALinuxAgent package WALinuxAgent-<version> has been pushed to the Red Hat extras
repository. Enable the extras repository by running the following command:

subscription-manager repos --enable=rhel-6-server-extras-rpms

14. Install the Azure Linux Agent by running the following command:

yum install WALinuxAgent

chkconfig waagent on

15. The Azure Linux Agent can automatically configure swap space by using the local resource disk
that is attached to the VM after the VM is provisioned on Azure. Note that the local resource disk
is a temporary disk, and might be emptied when the VM is deprovisioned. After you install the
Azure Linux Agent (see the 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.

16. Unregister the subscription (if necessary) by running the following command:

subscription-manager unregister

17. Run the following commands to deprovision the virtual machine and prepare it for provisioning on
Azure:

waagent -force -deprovision

export HISTSIZE=0

logout
18. Shut down the VM in KVM.

19. Convert the qcow2 image to VHD format. First convert the image to raw format:

qemu-img convert -f qcow2 O raw rhel-6.7.qcow2 rhel-6.7.raw

Make sure that the size of the raw image is aligned with 1 MB. Otherwise, round up the size to
align with 1 MB:

MB=$((1024*1024))

size=$(qemu-img info -f raw --output json rhel-6.7.raw | \

gawk match($0, /virtual-size: ([0-9]+),/, val) {print val[1]})

rounded_size=$((($size/$MB + 1)*$MB))

qemu-img resize rhel-6.7.raw $rounded_size

Convert the raw disk to a fixed-sized VHD:

qemu-img convert -f raw -o subformat=fixed -O vpc rhel-6.7.raw rhel-6.7.vhd

Running Red Hat on Microsoft Azure 9


Prepare a RHEL 7.1/7.2 virtual machine from KVM
1. Download the KVM image of RHEL 7.1 (or 7.2) from the Red Hat website. We will use RHEL 7.1 as
the example here.

2. Set a root password.

Generate an encrypted password, and copy the output of the command:

openssl passwd -1 changeme

Set a root password with guestfish.

guestfish --rw -a

run list-filesystems mount /dev/sda1 / vi /etc/shadow exit

Change the second field of root user from !! to the encrypted password.

3. Create a virtual machine in KVM from the qcow2 image, set the disk type to qcow2, and set the
virtual network interface device model to virtio. Then start the virtual machine and sign in as root.

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 IP-


V6INIT=no

6. Ensure that the network service will start at boot time by running the following command:

chkconfig network on

7. Register your Red Hat subscription to enable installation of packages from the RHEL repository by
running the following command:

subscription-manager register --auto-attach --username=XXX --password=XXX

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

This will also ensure that all console messages are sent to the first serial port, which can assist
Azure support with debugging issues. In addition to the above action, we recommend that you
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 can be left configured if desired, but note that this
parameter will reduce the amount of available memory in the VM by 128 MB or more. This might
be problematic on smaller VM sizes.

Running Red Hat on Microsoft Azure 10


9. After you are done editing /etc/default/grub, run the following command to rebuild the grub con-
figuration:

grub2-mkconfig -o /boot/grub2/grub.cfg

10. Add Hyper-V modules into initramfs:

Edit /etc/dracut.conf and add content:

add_drivers+=hv_vmbus hv_netvsc hv_storvsc

Rebuild initramfs:

dracut f -v

11. Uninstall cloud-init:

yum remove cloud-init

12. Ensure that the SSH server is installed and configured to start at boot time:

systemctl enable sshd

Modify /etc/ssh/sshd_config to include the following lines:

PasswordAuthentication yes ClientAliveInterval 180

Restart sshd:

systemctl restart sshd

13. The WALinuxAgent package WALinuxAgent-<version> has been pushed to the Red Hat extras
repository. Enable the extras repository by running the following command:

subscription-manager repos --enable=rhel-7-server-extras-rpms

14. Install the Azure Linux Agent by running the following command:

yum install WALinuxAgent

Enable the waagent service:

systemctl enable waagent.service

15. Do not create swap space on the OS disk. The Azure Linux Agent can automatically configure swap
space by using the local resource disk that is attached to the VM after the VM is provisioned on
Azure. Note that the local resource disk is a temporary disk, and might be emptied when the VM is
deprovisioned. After you install the Azure Linux Agent (see the previous step), modify the follow-
ing 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.

16. Unregister the subscription (if necessary) by running the following command:

subscription-manager unregister

Running Red Hat on Microsoft Azure 11


17. Run the following commands to deprovision the virtual machine and prepare it for provisioning on
Azure:

sudo waagent -force -deprovision

export HISTSIZE=0

logout
18. Shut down the virtual machine in KVM.

19. Convert the qcow2 image to VHD format.

First convert the image to raw format:

qemu-img convert -f qcow2 O raw rhel-7.1.qcow2 rhel-7.1.raw

Make sure that the size of the raw image is aligned with 1 MB. Otherwise, round up the size to
align with 1 MB:

MB=$((1024*1024))

size=$(qemu-img info -f raw --output json rhel-7.1.raw | \

gawk match($0, /virtual-size: ([0-9]+),/, val) {print val[1]})

rounded_size=$((($size/$MB + 1)*$MB))

qemu-img resize rhel-7.1.raw $rounded_size

Convert the raw disk to a fixed-sized VHD:

qemu-img convert -f raw -o subformat=fixed -O vpc rhel-7.1.raw rhel-7.1.vhd

Prepare a Red Hat-based virtual


machine from VMware
Prerequisites
This section assumes that you have already installed a RHEL virtual machine in VMware. For details on
how to install an operating system in VMware, see VMware Guest Operating System Installation Guide.

When you install the Linux operating system, we recommend 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 troubleshoot-
ing. LVM or RAID can be used on data disks if preferred.

Do not configure a swap partition on the OS disk. You can configure the Linux agent to create a
swap file on the temporary resource disk. You can find more information about this in the steps
below.

When you create the virtual hard disk, select Store virtual disk as a single file.

Running Red Hat on Microsoft Azure 12


Prepare a RHEL 6.7 virtual machine from VMware
1. Uninstall NetworkManager by running the following command:

sudo rpm -e --nodeps NetworkManager

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

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

NETWORKING=yes HOSTNAME=localhost.localdomain

3. 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 IP-


V6INIT=no

4. Move (or remove) the udev rules to avoid generating static rules for the Ethernet interface. These
rules cause problems when you clone 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/

5. Ensure that the network service will start at boot time by running the following command:

sudo chkconfig network on

6. Register your Red Hat subscription to enable the installation of packages from the RHEL repository
by running the following command:

sudo subscription-manager register --auto-attach --username=XXX --password=XXX

7. The WALinuxAgent package WALinuxAgent-<version> has been pushed to the Red Hat extras
repository. Enable the extras repository by running the following command:

subscription-manager repos --enable=rhel-6-server-extras-rpms

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 in a text editor and ensure that the default kernel
includes the following parameters:

console=ttyS0 earlyprintk=ttyS0 rootdelay=300 numa=off

This will also ensure that 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
that is used by RHEL 6. In addition to the above action, we recommend that you remove the fol-
lowing 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 can be left configured if desired, but note that this
parameter will reduce the amount of available memory in the VM by 128 MB or more. This might
be problematic on smaller VM sizes.

Running Red Hat on Microsoft Azure 13


9. Add Hyper-V modules into initramfs:

Edit /etc/dracut.conf and add content:

add_drivers+=hv_vmbus hv_netvsc hv_storvsc

Rebuild initramfs:

# dracut f -v

10. Ensure that the SSH server is installed and configured to start at boot time. This is usually the de-
fault. Modify /etc/ssh/sshd_config to include the following line:

ClientAliveInterval 180

11. Install the Azure Linux Agent by running the following command:

sudo yum install WALinuxAgent

sudo chkconfig waagent on

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

The Azure Linux Agent can automatically configure swap space by using the local resource disk
that is attached to the VM after the VM is provisioned on Azure. Note that the local resource disk
is a temporary disk, and might be emptied when the VM is deprovisioned. After you install the
Azure Linux Agent (see the 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. Unregister the subscription (if necessary) by running the following command:

sudo subscription-manager unregister

14. Run the following commands to deprovision the virtual machine and prepare it for provisioning on
Azure:

sudo waagent -force -deprovision

export HISTSIZE=0

logout

Running Red Hat on Microsoft Azure 14


15. Shut down the VM, and convert the VMDK file to a .vhd file.

First convert the image to raw format:

qemu-img convert -f vmdk O raw rhel-6.7.vmdk rhel-6.7.raw

Make sure that the size of the raw image is aligned with 1 MB. Otherwise, round up the size to
align with 1 MB:

MB=$((1024*1024))

size=$(qemu-img info -f raw --output json rhel-6.7.raw | \

gawk match($0, /virtual-size: ([0-9]+),/, val) {print val[1]})

rounded_size=$((($size/$MB + 1)*$MB))

qemu-img resize rhel-6.7.raw $rounded_size

Convert the raw disk to a fixed-sized VHD:

qemu-img convert -f raw -o subformat=fixed -O vpc rhel-6.7.raw rhel-6.7.vhd

Prepare a RHEL 7.1/7.2 virtual machine from VMware

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

NETWORKING=yes HOSTNAME=localhost.localdomain

2. 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 IP-


V6INIT=no

3. Ensure that the network service will start at boot time by running the following command:

sudo chkconfig network on

4. Register your Red Hat subscription to enable the installation of packages from the RHEL repository
by running the following command:

sudo subscription-manager register --auto-attach --username=XXX --password=XXX

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

This will also ensure that all console messages are sent to the first serial port, which can assist
Azure support with debugging issues. In addition to the above action, we recommend that you
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 can be left configured if desired, but note that this
parameter will reduce the amount of available memory in the VM by 128 MB or more. This might
be problematic on smaller VM sizes.

Running Red Hat on Microsoft Azure 15


6. After you are done editing /etc/default/grub, run the following command to rebuild the grub con-
figuration:

sudo grub2-mkconfig -o /boot/grub2/grub.cfg

7. Add Hyper-V modules into initramfs:

Edit /etc/dracut.conf, add content:

add_drivers+=hv_vmbus hv_netvsc hv_storvsc

Rebuild initramfs:

dracut f -v

8. Ensure that the SSH server is installed and configured to start at boot time. This is usually the de-
fault. Modify /etc/ssh/sshd_config to include the following line:

ClientAliveInterval 180

9. The WALinuxAgent package WALinuxAgent-<version> has been pushed to the Red Hat extras
repository. Enable the extras repository by running the following command:

subscription-manager repos --enable=rhel-7-server-extras-rpms

10. Install the Azure Linux Agent by running the following command:

sudo yum install WALinuxAgent

sudo systemctl enable waagent.service

11. Do not create swap space on the OS disk. The Azure Linux Agent can automatically configure swap
space by using the local resource disk that is attached to the VM after the VM is provisioned on
Azure. Note that the local resource disk is a temporary disk, and might be emptied when the VM is
deprovisioned. After you install the Azure Linux Agent (see the previous step), modify the follow-
ing 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.

12. If you want to unregister the subscription, run the following command:

sudo subscription-manager unregister

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

Running Red Hat on Microsoft Azure 16


14. Shut down the VM, and convert the VMDK file to VHD format.

First convert the image to raw format:

qemu-img convert -f vmdk O raw rhel-7.1.vmdk rhel-7.1.raw

Make sure that the size of the raw image is aligned with 1 MB. Otherwise, round up the size to
align with 1 MB:

MB=$((1024*1024))

size=$(qemu-img info -f raw --output json rhel-7.1.raw | \

gawk match($0, /virtual-size: ([0-9]+),/, val) {print val[1]})

rounded_size=$((($size/$MB + 1)*$MB))

qemu-img resize rhel-7.1.raw $rounded_size

Convert the raw disk to a fixed-sized VHD:

qemu-img convert -f raw -o subformat=fixed -O vpc rhel-7.1.raw rhel-7.1.vhd

Prepare a Red Hat-based virtual machine from


an ISO by using a kickstart file automatically
Prepare a RHEL 7.1/7.2 virtual machine from a kickstart file
1. Create a kickstart file with the content below, and save the file. For details about kickstart installa-
tion, see the Kickstart Installation Guide.

# Kickstart for provisioning a RHEL 7 Azure VM

# System authorization information


auth --enableshadow --passalgo=sha512

# Use graphical install


text

# Do not run the Setup Agent on first boot


firstboot --disable

# Keyboard layouts
keyboard --vckeymap=us --xlayouts=us

# System language
lang en_US.UTF-8

# Network information
network --bootproto=dhcp

# Root password
rootpw --plaintext to_be_disabled

Running Red Hat on Microsoft Azure 17


# System services
services --enabled=sshd,waagent,NetworkManager

# System timezone
timezone Etc/UTC --isUtc --ntpservers 0.rhel.pool.ntp.org,1.rhel.pool.ntp.org,2.rhel.pool.ntp.org,3.
rhel.pool.ntp.org

# Partition clearing information


clearpart --all --initlabel

# Clear the MBR


zerombr

# Disk partitioning information


part /boot --fstype=xfs --size=500
part / --fstyp=xfs --size=1 --grow --asprimary

# System bootloader configuration


bootloader --location=mbr

# Firewall configuration
firewall --disabled

# Enable SELinux
selinux --enforcing

# Dont configure X
skipx

# Power down the machine after install


poweroff

%packages
@base
@console-internet
chrony
sudo
parted
-dracut-config-rescue

%end

%post --log=/var/log/anaconda/post-install.log

#!/bin/bash

# Register Red Hat Subscription


subscription-manager register --username=XXX --password=XXX --auto-attach --force

# Install latest repo update


yum update -y

# Enable extras repo


subscription-manager repos --enable=rhel-7-server-extras-rpms

# Install WALinuxAgent
yum install -y WALinuxAgent

# Unregister Red Hat subscription


subscription-manager unregister

# Enable waaagent at boot-up

Running Red Hat on Microsoft Azure 18


systemctl enable waagent

# Disable the root account


usermod root -p !!

# Configure swap in WALinuxAgent


sed -i s/^\(ResourceDisk\.EnableSwap\)=[Nn]$/\1=y/g /etc/waagent.conf
sed -i s/^\(ResourceDisk\.SwapSizeMB\)=[0-9]*$/\1=2048/g /etc/waagent.conf

# Set the cmdline


sed -i s/^\(GRUB_CMDLINE_LINUX\)=.*$/\1=console=tty1 console=ttyS0 earlyprintk=ttyS0
rootdelay=300/g /etc/default/grub

# Enable SSH keepalive


sed -i s/^#\(ClientAliveInterval\).*$/\1 180/g /etc/ssh/sshd_config

# Build the grub cfg


grub2-mkconfig -o /boot/grub2/grub.cfg

# Configure network
cat << EOF > /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=dhcp
TYPE=Ethernet
USERCTL=no
PEERDNS=yes
IPV6INIT=no
NM_CONTROLLED=yes
EOF

# Deprovision and prepare for Azure


waagent -force -deprovision

%end

2. Place the kickstart file in a place that is accessible from the installation system.

3. In Hyper-V Manager, create a new VM. On the Connect Virtual Hard Disk page, select Attach a
virtual hard disk later, and complete the New Virtual Machine Wizard.

4. Open the VM settings: a. Attach a new virtual hard disk to the VM. Make sure to select VHD For-
mat and Fixed Size. b. Attach the installation ISO to the DVD drive. c. Set the BIOS to boot from
CD.

5. Start the VM. When the installation guide appears, press Tab to configure the boot options.

6. Enter inst.ks=<the location of the kickstart file> at the end of the boot options, and press Enter.

7. Wait for the installation to finish. When its finished, the VM will be shut down automatically. Your
Linux VHD is now ready to be uploaded to Azure.

Running Red Hat on Microsoft Azure 19


Known issues
There are known issues when you are using RHEL 7.1 in Hyper-V and Azure.

Disk I/O freeze


This issue might occur during frequent storage disk I/O activities with RHEL 7.1 in Hyper-V and Azure.

Repro rate:

This issue is intermittent. However, it occurs more frequently during frequent disk I/O operations in
Hyper-V and Azure.

[AZURE.NOTE] This known issue has already been addressed by Red Hat. To install the associated fixes,
run the following command:
# sudo yum update

The Hyper-V driver could not be included in the initial RAM disk when using a non-Hyper-V hypervi-
sor

In some cases, Linux installers might not include the drivers for Hyper-V in the initial RAM disk (initrd
or initramfs) unless it detects that it is running in a Hyper-V environment.

When youre using a different virtualization system (i.e. Virtualbox, Xen, etc.) to prepare your Linux
image, you might need to rebuild initrd to ensure that at least the hv_vmbus and hv_storvsc kernel
modules are available on the initial RAM disk. This is a known issue at least on systems based on the
upstream Red Hat distribution.

To resolve this issue, you need to add Hyper-V modules into initramfs and rebuild it:

Edit /etc/dracut.conf and add content:


add_drivers+=hv_vmbus hv_netvsc hv_storvsc

Rebuild initramfs:

# dracut f -v
For more details, see the information about rebuilding initramfs.

Next steps

Youre now ready to use your Red Hat Enterprise Linux virtual hard disk to create new virtual machines
in Azure. If this is the first time that youre uploading the .vhd file to Azure, see steps 2 and 3 in Creat-
ing and uploading a virtual hard disk that contains the Linux operating system.

For more details about the hypervisors that are certified to run Red Hat Enterprise Linux, see the Red
Hat website.

Running Red Hat on Microsoft Azure 20


Red Hat Update Infrastructure (RHUI) for on-
demand Red Hat Enterprise Linux VMs in Azure
Virtual machines created from the on-demand Red Hat Enterprise Linux (RHEL) images available in
Azure Marketplace are registered to access the Red Hat Update Infrastructure (RHUI) deployed in
Azure. The on-demand RHEL instances have access to a regional yum repository and able to receive
incremental updates.

The yum repository list, which is managed by RHUI, is configured in your RHEL instance during provi-
sioning. You dont need to do any additional configuration - run yum update after your RHEL instance
is ready to get the latest updates.

Note

Azure RHUI infrastructure has been recently updated (September 2016) and requires changes in the
configuration of your existing RHEL instances for uninterrupted access to the Azure RHUI. Refer to the
RHUI Azure Infrastructure Update section for details.

RHUI Azure Infrastructure Update


As of September 2016, Azure has a new set of Red Hat Update Infrastructure (RHUI) servers. These
servers are deployed with Azure Traffic Manager so that a single endpoint (rhui-1.micrsoft.com) can
be used by any VM regardless of region. They also use an SSL cert that is chained to a well-known
Certificate Authority (Baltimore root). Making this update automatic would be dangerous for some
customers that have ACLs or custom routing tables for the RHUI update servers, so this update is
opt-in. Manual steps for onboarding to these new servers are available on this page, and a complete
script for onboarding in an automated fashion (upon verification of the individual steps). The new
RHEL PAYG images in the Azure Marketplace (versions dated September 2016 or later) will automati-
cally point to the new Azure RHUI servers and do not require any additional action.

The new Azure RHUI infrastructure onboarding timeline

Date Note

September 22, RHUI servers and install directions available for use. VMs deployed using
2016 the new (September 2016 dated) RHEL PAYG marketplace images will
automatically use the new RHUI servers, but existing VMs are opt-in

November 1, Legacy RHEL PAYG VM images (which use the old Azure RHUI servers)
2016 will be removed from the Azure Marketplace gallery

January 16, 2017 The old Azure RHUI servers will be decommissioned. Update all of your
affected PAYG RHEL VMs by this time to maintain access to Azure RHUI

Running Red Hat on Microsoft Azure 21


The IPs for the new RHUI content delivery servers are

# Azure Global
13.91.47.76
40.85.190.91
52.187.75.218
52.174.163.213

# Azure US Government
13.72.186.193

# Azure Germany
51.5.243.77
51.4.228.145

Manual update procedure to use the new Azure RHUI servers

Download (via curl) the public key signature


curl -o RPM-GPG-KEY-microsoft-azure-release https://download.microsoft.com/download/9/
D/9/9d945f05-541d-494f-9977-289b3ce8e774/microsoft-sign-public.asc
Verify the downloaded key
gpg --list-packets --verbose < RPM-GPG-KEY-microsoft-azure-release
Check the output, verify keyid and user ID packet:+
Version: GnuPG v1.4.7 (GNU/Linux)
:public key packet:
version 4, algo 1, created 1446074508, expires 0
pkey[0]: [2048 bits]
pkey[1]: [17 bits]
keyid: EB3E94ADBE1229CF
:user ID packet: Microsoft (Release signing) <gpgsecurity@microsoft.com>
:signature packet: algo 1, keyid EB3E94ADBE1229CF
version 4, created 1446074508, md5len 0, sigclass 0x13
digest algo 2, begin of digest 1a 9b
hashed subpkt 2 len 4 (sig created 2015-10-28)
hashed subpkt 27 len 1 (key flags: 03)
hashed subpkt 11 len 5 (pref-sym-algos: 9 8 7 3 2)
hashed subpkt 21 len 3 (pref-hash-algos: 2 8 3)
hashed subpkt 22 len 2 (pref-zip-algos: 2 1)
hashed subpkt 30 len 1 (features: 01)
hashed subpkt 23 len 1 (key server preferences: 80)
subpkt 16 len 8 (issuer key ID EB3E94ADBE1229CF)
data: [2047 bits]

Install the public key

sudo install -o root -g root -m 644 RPM-GPG-KEY-microsoft-azure-release /etc/pki/rpm-gpg


sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-microsoft-azure-release

Download, Verify, and Install Client RPM

Running Red Hat on Microsoft Azure 22


Download: For RHEL 6
curl -o azureclient.rpm https://rhui-1.microsoft.com/pulp/repos/microsoft-azure-rhel6/rhui-azure-
rhel6-2.0-2.noarch.rpm

For RHEL 7
curl -o azureclient.rpm https://rhui-1.microsoft.com/pulp/repos/microsoft-azure-rhel7/rhui-azure-
rhel7-2.0-2.noarch.rpm

Verify:
rpm -Kv azureclient.rpm

Check in output that signature of the package is OK


azureclient.rpm:
Header V3 RSA/SHA256 Signature, key ID be1229cf: OK
Header SHA1 digest: OK (927a3b548146c95a3f6c1a5d5ae52258a8859ab3)
V3 RSA/SHA256 Signature, key ID be1229cf: OK
MD5 digest: OK (c04ff605f82f4be8c96020bf5c23b86c)

Install the RPM


sudo rpm -U azureclient.rpm
Upon completion, verify that you can access Azure RHUI form the VM

All-in-one script for automating the above task

Use the following script as needed to automate the task of updating affected VMs to the new Azure
RHUI servers.
# Download key
curl -o RPM-GPG-KEY-microsoft-azure-release https://download.microsoft.com/download/9/
D/9/9d945f05-541d-494f-9977-289b3ce8e774/microsoft-sign-public.asc

# Validate key
if ! gpg --list-packets --verbose < RPM-GPG-KEY-microsoft-azure-release | grep -q keyid: EB3E94AD-
BE1229CF; then
echo Keyfile azure.asc NOT valid. Exiting.
exit 1
fi

# Install Key
sudo install -o root -g root -m 644 RPM-GPG-KEY-microsoft-azure-release /etc/pki/rpm-gpg
sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-microsoft-azure-release

# Download RPM package


if grep -q release 7 /etc/redhat-release; then
ver=7
elif grep -q release 6 /etc/redhat-release; then
ver=6
else
echo Version not supported, exiting
exit 1
fi

Running Red Hat on Microsoft Azure 23


url=https://rhui-1.microsoft.com/pulp/repos/microsoft-azure-rhel$ver/rhui-azure-rhel$ver-2.0-2.
noarch.rpm
curl -o azureclient.rpm $url

# Verify package
if ! rpm -Kv azureclient.rpm | grep -q key ID be1229cf: OK; then
echo RPM failed validation ($url)
exit 1
fi

# Install package
sudo rpm -U azureclient.rpm

RHUI overview
Red Hat Update Infrastructure offers a highly scalable solution to manage yum repository content for
Red Hat Enterprise Linux cloud instances that are hosted by Red Hat-certified cloud providers. Based
on the upstream Pulp project, RHUI allows cloud providers to locally mirror Red Hat-hosted repository
content, create custom repositories with their own content, and make those repositories available to a
large group of end users through a load-balanced content delivery system.

Regions where RHUI is available


RHUI is available in all regions where RHEL on-demand images are available. It currently includes all
public regions listed on the Azure status dashboard page, Azure US Government and Azure Germany
regions. RHUI access for VMs provisioned from RHEL on-demand images is included in their price.
Additional regional/national cloud availability will be updated as we expand RHEL on-demand avail-
ability in the future.

Note

Access to Azure-hosted RHUI is limited to the VMs within Microsoft Azure Datacenter IP ranges.+

Get updates from another update repository


If you need to get updates from a different update repository (instead of Azure-hosted RHUI) you will
need to unregister your instances from RHUI and re-register them with the desired update infrastruc-
ture (such as Red Hat Satellite or Red Hat Customer Portal CDN). You will need appropriate Red Hat
subscriptions for these services and registration for Red Hat Cloud Access in Azure.

To unregister RHUI and reregister to your update infrastructure follow the below steps.
1. Edit /etc/yum.repos.d/rh-cloud.repo and change all enabled=1 to enabled=0. For example:

sed -i s/enabled=1/enabled=0/g /etc/yum.repos.d/rh-cloud.repo

2. Edit /etc/yum/pluginconf.d/rhnplugin.conf and change enabled=0 to enabled=1.

3. Then register with the desired infrastructure, such as Red Hat Customer Portal. Follow Red Hat
solution guide on how to register and subscribe a system to the Red Hat Customer Portal.

Running Red Hat on Microsoft Azure 24


Note

Access to the Azure-hosted RHUI is included in the RHEL Pay-As-You-Go (PAYG) image price. Unregis-
tering a PAYG RHEL VM from the Azure-hosted RHUI does not convert the virtual machine into Bring-
Your-Own-License (BYOL) type VM and hence you may be incurring double charges if you register the
same VM with another source of updates.

If you consistently need to use an update infrastructure other than Azure-hosted RHUI consider cre-
ating and deploying your own (BYOL-type) images as described in Create and Upload Red Hat-based
virtual machine for Azure article.

Next steps

To create a Red Hat Enterprise Linux VM from Azure Marketplace Pay-As-You-Go image and leverage
Azure-hosted RHUI go to Azure Marketplace. You will be able to use yum update in your RHEL in-
stance without any additional setup.

Running Red Hat on Microsoft Azure 25


Running Red Hat
on Microsoft Azure

You might also like