This topic describes how to migrate physical hosts from on-premises data centers to Alibaba Cloud or migrate virtual machines (VMs) from classic virtualization platforms to Alibaba Cloud. In this topic, a Red Hat Enterprise Linux (RHEL) 7 server is used.

Background information

You can migrate physical servers or VMs to Alibaba Cloud.
  • Migrate physical servers to Alibaba Cloud ECS (P2V and V2V)

    You can use Server Migration Center (SMC) to migrate the operating system images of physical servers to Alibaba Cloud Elastic Compute Service (ECS). After the images are imported to ECS, you can use the imported images to create instances.

  • Migrate VMs to Alibaba Cloud ECS (V2V)

    You can create VM images supported by Alibaba Cloud on on-premises physical servers. You can perform the operations described in this topic or use SMC to migrate VMs to Alibaba Cloud ECS.

For more information about the migration procedure in SMC, see Migration process.

Migrate a VM to Alibaba Cloud ECS

Perform the following steps to migrate a VM to Alibaba Cloud ECS:
  1. Step 1: Prepare a physical RHEL 7 server
  2. Step 2: Create a VM
  3. Step 3: Configure the guest operating system
  4. Step 4: Create a VM image
Note If a VM that meets the requirements described in Step 1: Prepare a physical RHEL 7 server is already running on the RHEL 7 server, you can start from Step 3: Configure the guest operating system.

Step 1: Prepare a physical RHEL 7 server

  1. Log on to the physical RHEL 7 server.
  2. Make sure that all the packages listed in the following table are installed on the RHEL server.
    You can run the yum info Package name command to view the installed packages.
    Package Repository Description
    libvirt rhel-7-server-rpms An open source API, daemon, and management tool for managing platform virtualization.
    virt-manager rhel-7-server-rpms A desktop tool for managing VMs.
    libguestfs rhel-7-server-rpms A set of tools for accessing and modifying VM disk images.
    libguestfs-tools rhel-7-server-rpms A set of system management tools for VMs, including guestfish.
    qemu-img rhel-7-server-rpms A tool for converting VM disk images from one format to another.

Step 2: Create a VM

  1. Click Red Hat to download the latest Red Hat Enterprise Linux 7.5 Update KVM Guest Image or Red Hat Enterprise Linux 7.4 Update KVM Guest Image.
    Note We recommend that you download RHEL 7.5 that has more comprehensive features than RHEL 7.4.
  2. Save the image to the RHEL physical server prepared in Step 1.
  3. Move the image to the /var/lib/libvirt/images directory.
  4. In the Virtual Machine Manager window, click the Create VM icon icon to create a VM.
    Create a VM
  5. Complete the configurations in the Create a virtual machine wizard.
    1. Select Import existing disk image to install the guest operating system. Then, click Forward.
      Import an existing image
    2. Browse the /var/lib/libvirt/images directory and select the KVM guest image in the QCOW2 format.
      Select a QCOW2 image
    3. Set the memory size and the number of CPU cores for the new VM.
      Set memory and CPU
    4. Check the configurations of the new VM, specify a name for the VM, and then select Customize configuration before install.
      Customize configuration
    5. In the left-side pane of the Custom configuration dialog box, click NIC and set Device model to virtio.
    6. Click Begin Installation.
      The VM begins to be created. During this process, the VM console appears and boots to a logon prompt.
    7. When the logon prompt appears, shut down the VM.
  6. Run the following command to set a password for the root user of the VM:
    virt-customize -a /var/lib/libvirt/images/rhel-server-7.5-x86_64-kvm.qcow2 --root-password password:<password>
    In this example, the password for the root user of the VM is set to redhat!. Sample command:
     # virt-customize -a /var/lib/libvirt/images/rhel-server-7.5-x86_64-kvm.qcow2 --root-password password:redhat!
     [   0.0] Examining the guest ...
     [ 103.0] Setting a random seed
     [ 103.0] Setting passwords
     [ 112.0] Finishing off
  7. Start the RHEL VM and log on as the root user.

Step 3: Configure the guest operating system

After you log on to the VM, you must configure the guest operating system.

  1. Make sure that the guest operating system of the RHEL VM meets the specified requirements.
    For more information, see the "Requirements for ECS instances and RHEL custom images" section in Overview.
    The following table describes the requirements for the guest operating system.
    Item Description
    /etc/shadow /etc/shadow is unlocked by running the chattr command.
    qemu-ga qemu-ga is uninstalled.
    Network The network manager is disabled or uninstalled, and network services are enabled.
    ssh The SSH service is enabled and PermitRootLogin is not set.
    Firewall Firewalls are disabled.
    File system The xfs, ext3, or ext4 file system is used. Do not use the 64-bit ext4 file system.
    passwd passwd is installed.
    Partition The Master Boot Record (MBR) or GUID Partition Table (GPT) partitioning format is used.
    Logical Volume Manager (LVM) LVM is not used.
    /lib Relative paths can be used only for /lib and /lib64.
    cloud-init cloud-init is installed in the guest operating system.
    Note By default, cloud-init disables password-based logon. If you want to enable password-based logon, see Step 6 of the "(Optional) Install the native cloud-init" section in Install cloud-init. This step shows you how to modify the content that precedes cloud_init_modules in the /etc/cloud/cloud.cfg configuration file.
  2. Configure the ntp.conf file.
    Perform the following steps to configure the ntp.conf file that is located in the /etc/ntp.conf directory:
    1. Run the following command to back up the ntp.conf file as ntp.conf.bk:
       cp /etc/ntp.conf /etc/ntp.conf.bk
    2. Edit the /etc/ntp.conf file by replacing its content with the following content:
       driftfile  /var/lib/ntp/drift
       pidfile    /var/run/ntpd.pid
       logfile    /var/log/ntp.log
       # Access Control Support
       restrict    default kod nomodify notrap nopeer noquery
       restrict -6 default kod nomodify notrap nopeer noquery
       restrict 127.0.0.1
       restrict 192.168.0.0 mask 255.255.0.0 nomodify notrap nopeer noquery
       restrict 172.16.0.0 mask 255.240.0.0 nomodify notrap nopeer noquery
       restrict 100.64.XX.XX mask 255.192.0.0 nomodify notrap nopeer noquery
       restrict 10.0.0.0 mask 255.0.0.0 nomodify notrap nopeer noquery
       # local clock
       server 127.127.1.0
       fudge  127.127.1.0 stratum 10
       restrict ntp1.aliyun.com nomodify notrap nopeer noquery
       restrict ntp1.cloud.aliyuncs.com nomodify notrap nopeer noquery
       restrict ntp10.cloud.aliyuncs.com nomodify notrap nopeer noquery
       restrict ntp11.cloud.aliyuncs.com nomodify notrap nopeer noquery
       restrict ntp12.cloud.aliyuncs.com nomodify notrap nopeer noquery
       restrict ntp2.aliyun.com nomodify notrap nopeer noquery
       restrict ntp2.cloud.aliyuncs.com nomodify notrap nopeer noquery
       restrict ntp3.aliyun.com nomodify notrap nopeer noquery
       restrict ntp3.cloud.aliyuncs.com nomodify notrap nopeer noquery
       restrict ntp4.aliyun.com nomodify notrap nopeer noquery
       restrict ntp4.cloud.aliyuncs.com nomodify notrap nopeer noquery
       restrict ntp5.aliyun.com nomodify notrap nopeer noquery
       restrict ntp5.cloud.aliyuncs.com nomodify notrap nopeer noquery
       restrict ntp6.aliyun.com nomodify notrap nopeer noquery
       restrict ntp6.cloud.aliyuncs.com nomodify notrap nopeer noquery
       restrict ntp7.cloud.aliyuncs.com nomodify notrap nopeer noquery
       restrict ntp8.cloud.aliyuncs.com nomodify notrap nopeer noquery
       restrict ntp9.cloud.aliyuncs.com nomodify notrap nopeer noquery
       server ntp1.aliyun.com iburst minpoll 4 maxpoll 10
       server ntp1.cloud.aliyuncs.com iburst minpoll 4 maxpoll 10
       server ntp10.cloud.aliyuncs.com iburst minpoll 4 maxpoll 10
       server ntp11.cloud.aliyuncs.com iburst minpoll 4 maxpoll 10
       server ntp12.cloud.aliyuncs.com iburst minpoll 4 maxpoll 10
       server ntp2.aliyun.com iburst minpoll 4 maxpoll 10
       server ntp2.cloud.aliyuncs.com iburst minpoll 4 maxpoll 10
       server ntp3.aliyun.com iburst minpoll 4 maxpoll 10
       server ntp3.cloud.aliyuncs.com iburst minpoll 4 maxpoll 10
       server ntp4.aliyun.com iburst minpoll 4 maxpoll 10
       server ntp4.cloud.aliyuncs.com iburst minpoll 4 maxpoll 10
       server ntp5.aliyun.com iburst minpoll 4 maxpoll 10
       server ntp5.cloud.aliyuncs.com iburst minpoll 4 maxpoll 10
       server ntp6.aliyun.com iburst minpoll 4 maxpoll 10
       server ntp6.cloud.aliyuncs.com iburst minpoll 4 maxpoll 10
       server ntp7.cloud.aliyuncs.com iburst minpoll 4 maxpoll 10
       server ntp8.cloud.aliyuncs.com iburst minpoll 4 maxpoll 10
       server ntp9.cloud.aliyuncs.com iburst minpoll 4 maxpoll 10

      After you make the modification, press the Esc key, enter :wq, and press the Enter key to save the modification and exit.

      You can create a VM image after you complete the configurations for the guest operating system. You can also use SMC provided by Alibaba Cloud to create and import VM images. For more information, see What is SMC?

Step 4: Create a VM image

  1. On the menu bar of the RHEL VM, choose View > Snapshots.
  2. Click the + icon to create a snapshot.
    After the snapshot is created, a VM image is created. The VM image is in the QCOW2 format.

What to do next

Step 3: (Optional) Convert the image to a supported format