3.7. Preparing a virtual machine for Azure deployment
To ensure that the VM have compatibility and can operate in the Azure environment, perform the configuration changes before deploying a custom base image.
Prerequisites
- You have installed the Hyper-V device drivers.
Procedure
Log in and register the VM to enable the Red Hat Enterprise Linux (RHEL) repository:
# subscription-manager register Installed Product Current Status: Product Name: Red Hat Enterprise Linux for x86_64 Status: SubscribedInstall the
cloud-initandhyperv-daemonspackages:# dnf install cloud-init hyperv-daemons -yCreate the
cloud-initconfiguration files and edit them to offer integration with Azure services:To enable logging to the Hyper-V Data Exchange Service (KVP), edit the
/etc/cloud/cloud.cfg.d/10-azure-kvp.cfgfile and append the following lines:reporting: logging: type: log telemetry: type: hypervTo add the Azure datasource, edit the
/etc/cloud/cloud.cfg.d/91-azure_datasource.cfgfile and append the following lines:datasource_list: [ Azure ] datasource: Azure: apply_network_config: FalseTo configure swap space on the ephemeral disk, create the
/etc/cloud/cloud.cfg.d/00-azure-swap.cfgconfiguration file and add the following lines to that file.重要The ephemeral disk is temporary storage. Therefore, data stored on it, including swap space, is lost when the VM is deallocated or moved. Use the ephemeral disk only for temporary data such as swap space.
#cloud-config disk_setup: ephemeral0: table_type: gpt 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,nofail,x-systemd.requires=cloud-init.service", "0", "0"]
To block automatic loading of specific kernel modules, edit the
/etc/modprobe.d/blocklist.conffile and append the following lines:blacklist nouveau blacklist lbm-nouveau blacklist floppy blacklist amdgpu blacklist skx_edac blacklist intel_cstateModify
udevnetwork device rules:If present, remove the following persistent network device rules:
# rm -f /etc/udev/rules.d/70-persistent-net.rules # rm -f /etc/udev/rules.d/75-persistent-net-generator.rules # rm -f /etc/udev/rules.d/80-net-name-slot-rulesTo ensure working of accelerated networking on Azure, edit the
/etc/udev/rules.d/68-azure-sriov-nm-unmanaged.rulesnew network device rule and append the following line:SUBSYSTEM=="net", DRIVERS=="hv_pci", ACTION=="add", ENV{NM_UNMANAGED}="1"
Set the
sshdservice to start automatically:# systemctl enable sshd # systemctl is-enabled sshdModify kernel boot parameters:
Update the
GRUB_TIMEOUTparameter value in the/etc/default/grubfile:GRUB_TIMEOUT=10Remove the following option from the end of the
GRUB_CMDLINE_LINUXline, if present:rhgb quietUpdate the
/etc/default/grubfile with the following configuration details:GRUB_CMDLINE_LINUX="loglevel=3 crashkernel=auto console=tty1 console=ttyS0 earlyprintk=ttyS0 rootdelay=300" GRUB_TIMEOUT_STYLE=countdown GRUB_TERMINAL="serial console" GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"注意By adding the
elevator=noneoption to the end of theGRUB_CMDLINE_LINUXline disables the I/O scheduler entirely. This option processes I/O requests according to the order of execution, without optimizing disk performance. Withelevator=noneon:- Hard disk drive (HDD): Performance and throughput decreases, therefore not suitable for running workloads.
- Solid state drive (SSD): High performance and low latency, therefore suitable for running workloads.
Regenerate the
grub.cfgfile:On a BIOS-based machine:
# grub2-mkconfig -o /boot/grub2/grub.cfg --update-bls-cmdlineOn a UEFI-based machine:
# grub2-mkconfig -o /boot/grub2/grub.cfg --update-bls-cmdline警告The path to rebuild
grub.cfgis same for both BIOS and UEFI based machines. Originalgrub.cfgis present at BIOS path only. The UEFI path has a stub file that must not be modified or recreated usinggrub2-mkconfigcommand.If your system uses a non-default location for
grub.cfg, adjust the command accordingly.
Configure the Windows Azure Linux Agent (
WALinuxAgent):Install and enable the
WALinuxAgentpackage:# dnf install WALinuxAgent -y # systemctl enable waagentTo disable swap configuration in WALinuxAgent (required when using cloud-init to manage swap), edit the following lines in the
/etc/waagent.conffile:Provisioning.DeleteRootPassword=y ResourceDisk.Format=n ResourceDisk.EnableSwap=n ResourceDisk.SwapSizeMB=0注意By disabling swap in WALinuxAgent, you enable
cloud-initto manage the swap configuration on the ephemeral disk.
Prepare the VM for Azure provisioning:
Unregister the VM from Red Hat Subscription Manager:
# subscription-manager unregisterClean up the existing provisioning details:
# waagent -force -deprovision注意This command generates warnings as Azure automatically handles the VM provisioning.
Clear the shell history and shut down the VM:
# export HISTSIZE=0 # poweroff
Next steps
- To upload the RHEL image to Azure cloud, convert it to Azure disk image format.