Updated on 2025-05-08 GMT+08:00

Configuring the VM

Install Native Xen and KVM Drivers

Ubuntu 20.04 is used as an example to illustrate the driver installation. For other OS types, see Installing Native Xen and KVM Drivers on a Xen ECS.

  1. Open the modules file.

    vi /etc/initramfs-tools/modules

  2. Press i to enter the editing mode and add native Xen (xen-pv) and KVM (VirtIO) drivers to the /etc/initramfs-tools/modules file (the format depends on the OS requirements).
    [root@CTU10000xxxxx ~]#vi /etc/initramfs-tools/modules 
    ...
    # Examples: 
    # 
    # raid1 
    # sd_mOd 
    xen-blkfront 
    xen-netfront 
    virtio_blk 
    virtio_scsi 
    virtio_net 
    virtio_pci 
    virtio_ring 
    virtio  
  3. Press Esc, enter :wq, and press Enter to save the settings and exit the vi editor.
  4. Generate initramfs or initrd again.

    update-initramfs -u

  5. Check whether native Xen and KVM drivers are installed.

    lsinitramfs /boot/initrd.img-`uname -r` |grep xen

    lsinitramfs /boot/initrd.img-`uname -r` |grep virtio

    [root@ CTU10000xxxxx home]# lsinitramfs /boot/initrd.img-`uname -r` |grep xen 
    lib/modules/3.5.0-23-generic/kernel/drivers/net/ethernet/qlogic/netxen 
    lib/modules/3.5.0-23-generic/kernel/drivers/net/ethernet/qlogic/netxen/netxen_nic.ko 
    lib/modules/3.5.0-23-generic/kernel/drivers/net/xen-netback 
    lib/modules/3.5.0-23-generic/kernel/drivers/net/xen-netback/xen-netback.ko 
    lib/modules/3.5.0-23-generic/kernel/drivers/block/xen-blkback 
    lib/modules/3.5.0-23-generic/kernel/drivers/block/xen-blkback/xen-blkback.ko 
     
    [root@ CTU10000xxxxx home]# lsinitramfs /boot/initrd.img-`uname -r` |grep virtio 
    lib/modules/3.5.0-23-generic/kernel/drivers/scsi/virtio_scsi.ko

    If you add built-in drivers to the initrd or initramfs file, the VM will not be affected but such drivers cannot be shown by running the lsinitrd command. You can run the following commands to check whether there are built-in drivers in the kernel:

    [root@ CTU10000xxxxx home]# cat /boot/config-`uname -r` | grep CONFIG_VIRTIO | grep y
    CONFIG_VIRTIO_BLK=y
    CONFIG_VIRTIO_NET=y
    CONFIG_VIRTIO=y
    CONFIG_VIRTIO_RING=y
    CONFIG_VIRTIO_PCI=y
    CONFIG_VIRTIO_MMIO_CMDLINE_DEVICES=y
    [root@ CTU10000xxxxx home]# cat /boot/config-`uname -r` | grep CONFIG_XEN | grep y
    CONFIG_XEN_BLKDEV_FRONTEND=y
    CONFIG_XEN_NETDEV_FRONTEND=y

Change Disk Identifiers in the GRUB Configuration File to the UUID Format

Take Ubuntu 20.04 as an example. Run blkid to obtain the UUID of the root partition. Modify the /boot/grub/grub.cfg file and use this UUID to configure the boot item. If the root partition is already using UUID, no modification is required. The procedure is as follows:
  1. Log in to the VM as root.
  2. List all types of mounted file systems and their device UUIDs:

    blkid

    The following information is displayed:

    /dev/xvda1: UUID="ec51d860-34bf-4374-ad46-a0c3e337fd34" TYPE="ext3"
    /dev/xvda5: UUID="7a44a9ce-9281-4740-b95f-c8de33ae5c11" TYPE="swap"
  1. Display the grub.cfg file content.

    cat /boot/grub/grub.cfg

    The following information is displayed:

    ......menuentry 'Ubuntu Linux, with Linux 3.13.0-24-generic' --class ubuntu --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.13.0-24-generic-advanced-ec51d860-34bf-4374-ad46-a0c3e337fd34' {
    recordfail
    load_video
    gfxmode $linux_gfx_mode
    insmod gzio
    insmod part_msdos
    insmod ext2
    if [ x$feature_platform_search_hint = xy ]; then
    search --no-floppy --fs-uuid --set=root ec51d860-34bf-4374-ad46-a0c3e337fd34
    else
    search --no-floppy --fs-uuid --set=root ec51d860-34bf-4374-ad46-a0c3e337fd34
    fi
    echo 'Loading Linux 3.13.0-24-generic ...'
    linux /boot/vmlinuz-3.13.0-24-generic root=/dev/xvda1 ro 
    echo 'Loading initial ramdisk ...'
    initrd /boot/initrd.img-3.13.0-24-generic 
    }
  1. Check whether the /boot/grub/grub.cfg configuration file contains root=/dev/xvda1 or root=UUID=ec51d860-34bf-4374-ad46-a0c3e337fd34.
    • If root=UUID=ec51d860-34bf-4374-ad46-a0c3e337fd34 is contained, the root partition is in UUID format and no further action is required.
    • If root=/dev/xvda1 is contained, the root partition is represented by a device name. Go to 5.
  1. Obtain the UUID of the root partition based on root=/dev/xvda1 and information obtained by running the blkid command.
  2. Open the grub.cfg file.

    vi /boot/grub/grub.cfg

  3. Press i to enter the editing mode. Change the identifier of the root partition to the UUID format. For example, change root=/dev/xvda1 to root=UUID=ec51d860-34bf-4374-ad46-a0c3e337fd34.
  4. Press Esc, enter :wq, and press Enter to save the settings and exit the vi editor.
  5. Verify the change.

    cat /boot/grub/grub.cfg

    The change is successful if information similar to the following is displayed:

    ......menuentry 'Ubuntu Linux, with Linux 3.13.0-24-generic' --class ubuntu --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.13.0-24-generic-advanced-ec51d860-34bf-4374-ad46-a0c3e337fd34' {
    recordfail
    load_video
    gfxmode $linux_gfx_mode
    insmod gzio
    insmod part_msdos
    insmod ext2
    if [ x$feature_platform_search_hint = xy ]; then
    search --no-floppy --fs-uuid --set=root ec51d860-34bf-4374-ad46-a0c3e337fd34
    else
    search --no-floppy --fs-uuid --set=root ec51d860-34bf-4374-ad46-a0c3e337fd34
    fi
    echo 'Loading Linux 3.13.0-24-generic ...'
    linux /boot/vmlinuz-3.13.0-24-generic root=UUID=ec51d860-34bf-4374-ad46-a0c3e337fd34 ro
    echo 'Loading initial ramdisk ...'
    initrd /boot/initrd.img-3.13.0-24-generic
    }

Change Disk Identifiers in the fstab File to the UUID Format

Take Ubuntu 20.04 as an example. Run blkid to obtain the UUIDs of all partitions. Modify the /etc/fstab file and use the partition UUIDs to configure automatic partition mounting.

  1. List all types of mounted file systems and their device UUIDs:

    blkid

    The following information is displayed:

    /dev/xvda2: UUID="4eb40294-4c6f-4384-bbb6-b8795bbb1130" TYPE="xfs"  
    /dev/xvda1: UUID="2de37c6b-2648-43b4-a4f5-40162154e135" TYPE="swap"
  2. Display the fstab file content.

    cat /etc/fstab

    The following information is displayed:

    [root@CTU1000028010 ~]# cat /etc/fstab  
    /dev/xvda2  /       xfs     defaults    0 0 
    /dev/xvda1  swap    swap    defaults    0 0     
  3. Check whether disk identifiers in the fstab file are device names or UUIDs.
    • If they are UUIDs, no further action is required.
    • If they are device names, go to 4.
  4. Open the fstab file.

    vi /etc/fstab

  5. Press i to enter the editing mode and change disk identifiers to the UUID format.
  6. Press Esc, enter :wq, and press Enter to save the settings and exit the vi editor.

(Optional) Install and Configuring Cloud-Init

To ensure that you can inject custom information (for example, the login password) into ECSs created from the image, you are advised to install Cloud-Init on the VM that is used as the image source.

(Optional) Install the One-Click Password Reset Plug-In

To ensure that you can reset the password of each ECS created from the image with a few clicks, you are advised to install the one-click password reset plug-in (CloudResetPwdAgent) on the VM that is used as the image source.

  1. Download the CloudResetPwdAgent (one-click password reset plug-in) package.

    The one-click password reset plug-in can be automatically updated only if an EIP is bound to the VM.

    You can download the CloudResetPwdAgent.zip package from:

    For 32-bit OSs: http://ap-southeast-1-cloud-reset-pwd.obs.ap-southeast-1.myhuaweicloud.com/linux/32/reset_pwd_agent/CloudResetPwdAgent.zip

    For 64-bit OSs: http://ap-southeast-1-cloud-reset-pwd.obs.ap-southeast-1.myhuaweicloud.com/linux/64/reset_pwd_agent/CloudResetPwdAgent.zip

  2. Decompress CloudResetPwdAgent.zip.

    unzip -o -d output-directory CloudResetPwdAgent.zip

    There is no special requirement for the directory that stores the decompressed CloudResetPwdAgent.zip. You can choose a directory as you need. If the directory is /home/PwdAgent/test, the command is as follows:

    unzip -o -d /home/PwdAgent/test CloudResetPwdAgent.zip

  3. Install the one-click password reset plug-in.
    1. Open the CloudResetPwdAgent.Linux file.

      cd CloudResetPwdAgent/CloudResetPwdAgent.Linux

    2. Add the execute permission for the setup.sh file.

      chmod +x setup.sh

    3. Install the plug-in.

      sudo sh setup.sh

      If "cloudResetPwdAgent install successfully" is displayed and "Failed to start service cloudResetPwdAgent" is not displayed, the installation is successful.

      If the installation failed, check whether the installation environment meets the requirements and install the plug-in again.

Configure NetworkManager

Linux allows you to use NetworkManager to automatically configure the VM network. You are advised to use NetworkManager for new OS versions. Alternatively, you can use the native network service of the OS.