Search This Blog

Monday, January 4, 2016

Create Red Hat Base Image to Upload to Microsoft Azure

Microsoft has recently announced support Red Hat distro support on Microsoft Azure, which enable us to run Red Hat Virtual Machine. At the moment of writing this post, the VM gallery still not ready to deploy Red Hat images. If you would like to run Red Hat, you can create own base images and upload to Azure. To do so,

1. Use Microsoft Hyper-V
2. Create a virtual machine using VHD disk format.
3. Get Red Hat installer media and create a base image. Supported linux version is RHEL 6.6/6.7 and 7.0/7.1. You can download free 30 days evaluation from https://access.redhat.com/products/red-hat-enterprise-linux/evaluation

[Installation]

Here is the screenshot of the installation and some configuration that you need to take note during base image preparation:-

Create Storage Partition. Select manual configuration



Select Standard Partition rather than LVM


Create 
/boot - 500 MB
/ - remaining disk
Do not create /swap partition. 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


When the installation process complete, click Reboot. The installation will take roughly 30 minutes.

[ Post Configuration ]
Note:- Check port SSH is running as we are to use it after upload to Azure. Type service sshd status


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

NETWORKING=yes
HOSTNAME=localhost.localdomain

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
Ensure the network service will start at boot time by running the following command:

# sudo chkconfig network on
Register your Red Hat subscription to enable installation of packages from the RHEL repository by running the following command:

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

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

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

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

ClientAliveInterval 180

The WALinuxAgent package WALinuxAgent-<version> has been pushed to the Fedora EPEL 6 repository. Enable the epel repository by running the following command:

# wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
# rpm -ivh epel-release-7-5.noarch.rpm

Install the Azure Linux Agent by running the following command:

# sudo yum install WALinuxAgent
# sudo systemctl enable waagent.service 

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.
If you want to unregister the subscription, run the following command:

# sudo subscription-manager unregister

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

# sudo waagent -force -deprovision
# export HISTSIZE=0# logout

Use Hyper-V Manager to shutdown the virtual machine and now your base image is ready to upload to Microsoft Azure.

Upload to Azure Storage
Add-AzureVhd -Destination https://ms4uvmstorage01.blob.core.windows.net/vhds/webrh.vhd -LocalFilePath E:\VM\RH.vhd


Create VM Images from base disk that you've uploaded
Use Azure Management Portal to create VM images. Click on Virtual Machines | Images | Create an Image |
Last but not least, we can start to provision Red Hat virtual machine from Azure Management Portal.
Click +NEW | Compute | Virtual Machine | From Gallery

Enjoy!