This section shows you how to use KVM to prepare RHEL 7 to upload to Azure.
Download the RHEL 7 KVM image of from the Red Hat website.
Set a root password.
Generate an encrypted password, and copy the output of the command:
sudo openssl passwd -1 changeme
Set a root password with guestfish:
sudo guestfish --rw -a <image-name>
> <fs> run
> <fs> list-filesystems
> <fs> mount /dev/sda1 /
> <fs> vi /etc/shadow
> <fs> exit
Change the second field for the root
user from !!
to the encrypted password.
Create a VM 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 VM and sign in as root.
Create or edit the /etc/sysconfig/network
file, and add the following text:
NETWORKING=yes
HOSTNAME=localhost.localdomain
Create or edit the /etc/sysconfig/network-scripts/ifcfg-eth0
file, and add the following text:
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=dhcp
TYPE=Ethernet
USERCTL=no
PEERDNS=yes
IPV6INIT=no
PERSISTENT_DHCLIENT=yes
NM_CONTROLLED=yes
Note
When you use Accelerated Networking, the synthetic interface that's created must be configured to be unmanaged by using a udev rule. This action prevents NetworkManager
from assigning the same IP to it as the primary interface.
To apply it:
sudo tee <<EOF /etc/udev/rules.d/68-azure-sriov-nm-unmanaged.rules > /dev/null
SUBSYSTEM=="net", DRIVERS=="hv_pci", ACTION!="remove", ENV{NM_UNMANAGED}="1"
EOF
Ensure that the network service starts at boot time:
sudo systemctl enable network
Register your Red Hat subscription to enable installation of packages from the RHEL 7 repository:
sudo subscription-manager register --auto-attach --username=XXX --password=XXX
Modify the kernel boot line in your grub configuration to include more kernel parameters for Azure. To do this configuration, open /etc/default/grub
in a text editor and edit the GRUB_CMDLINE_LINUX
parameter. For example:
GRUB_CMDLINE_LINUX="console=ttyS0 earlyprintk=ttyS0 net.ifnames=0"
This command also ensures that all console messages are sent to the first serial port, which can assist Azure support with debugging issues. The command also turns off the new naming conventions for NICs. We also recommend that you remove the following parameters:
rhgb quiet crashkernel=auto
Graphical and quiet boots aren't useful in a cloud environment where you want all the logs to be sent to the serial port. You can leave the crashkernel
option configured if you want. This parameter reduces the amount of available memory in the VM by 128 MB or more, which might be a problem for smaller VM sizes.
After you're finished editing /etc/default/grub
, run the following command to rebuild the grub configuration:
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
Add Hyper-V modules into initramfs.
Edit /etc/dracut.conf
and add content:
add_drivers+=" hv_vmbus hv_netvsc hv_storvsc "
Rebuild initramfs:
sudo dracut -f -v
Uninstall cloud-init
:
sudo yum remove cloud-init
Ensure that the SSH server is installed and configured to start at boot time:
sudo systemctl enable sshd
Modify /etc/ssh/sshd_config
to include the following lines:
PasswordAuthentication yes
ClientAliveInterval 180
The WALinuxAgent package, WALinuxAgent-<version>
, has been pushed to the Red Hat extras repository. Enable the extras repository:
sudo subscription-manager repos --enable=rhel-7-server-extras-rpms
Install the Azure Linux agent:
sudo yum install WALinuxAgent
Enable the waagent
service:
sudo systemctl enable waagent.service
Install cloud-init
.
Follow the steps in "Prepare a RHEL 7 VM from Hyper-V Manager," step 12, "Install cloud-init
to handle the provisioning."
Swap configuration:
- Don't create swap space on the operating system disk.
- Follow the steps in "Prepare a VM from Hyper-V Manager," step 13, "Swap configuration."
Unregister the subscription (if necessary):
sudo subscription-manager unregister
Deprovision by following the steps in "Prepare a VM from Hyper-V Manager," step 15, "Deprovision."
Shut down the VM in KVM.
Convert the qcow2 image to the VHD format.
Note
There's a known bug in qemu-img versions >=2.2.1 that results in an improperly formatted VHD. The issue has been fixed in QEMU 2.6. We recommend that you use either qemu-img 2.2.0 or lower, or update to 2.6 or higher. For more information, see this website.
First convert the image to raw format:
sudo qemu-img convert -f qcow2 -O raw rhel-7.4.qcow2 rhel-7.4.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.4.raw" | \
gawk 'match($0, /"virtual-size": ([0-9]+),/, val) {print val[1]}')
rounded_size=$((($size/$MB + 1)*$MB))
sudo qemu-img resize rhel-7.4.raw $rounded_size
Convert the raw disk to a fixed-size VHD:
sudo qemu-img convert -f raw -o subformat=fixed -O vpc rhel-7.4.raw rhel-7.4.vhd
Or, with qemu version 1.6+, include the force_size
option:
sudo qemu-img convert -f raw -o subformat=fixed,force_size -O vpc rhel-7.4.raw rhel-7.4.vhd