Alibaba Cloud Linux 2 images are available in various formats and have cloud-init built in. This topic describes how to use Alibaba Cloud Linux 2 images in an on-premises environment.
Background information
Alibaba Cloud Linux 2 images can run only on kernel-based virtual machines (KVMs). Alibaba Cloud Linux 3 images cannot directly start KVMs. You must configure a boot image. In this topic, the on-premises operating system is Anolis OS. Alibaba Cloud Linux 2 is used to create a KVM, and cloud-init is used to initialize the system settings of the KVM. To download Anolis OS, go to the OpenAnolis website. For more information about cloud-init, see Cloud-init documentation on the official cloud-init website. The NoCloud data source is used to create on-premises configuration files. After the configuration files are attached to the KVM as virtual disks, the KVM can be started.
This topic is intended for users who are familiar with KVMs.
Step 1: Download an Alibaba Cloud Linux 2 image to your computer
You can download an Alibaba Cloud Linux 2 image to your computer from the Alibaba Cloud Linux 2 On-premise Image page. Alibaba Cloud Linux 2 images are available in the VHD or QCOW2 format.
Step 2: Obtain the seed.img boot image from your computer
You can use one of the following methods to obtain the seed.img image:
- Go to the Alibaba Cloud Linux 2 On-premise Image page and click seed.img to download the seed.img image.
The configurations in this image cannot be modified, which makes it less ideal for some scenarios. Make sure that you are familiar with the image before you use it.
- Perform the following operations to manually generate the seed.img image based on the NoCloud data source:
- In an on-premises directory, create two configuration files named
meta-data
anduser-data
. - Install the
cloud-utils
software package on your computer.yum install -y cloud-utils
- In the
seed
directory, run the following command to generate theseed.img
image:cloud-localds seed.img user-data meta-data
Step 3: Start the KVM
Use one of the following methods to start the KVM. Then, use the account information in the user-data
configuration file to log on to the KVM.
- Use libvirt to start the KVM.
- Create a configuration file in the XML format on your computer. The sample file is named
alinux2.xml
and contains the following content. You can modify this file based on your requirements.<domain type='kvm'> <name>alinux2</name> <memory>1048576</memory> <!-- 1 GB memory --> <vcpu>1</vcpu> <os> <type arch='x86_64'>hvm</type> <boot dev='hd'/> </os> <clock sync="localtime"/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>restart</on_crash> <devices> <emulator>/usr/bin/qemu-kvm</emulator><!-- Configure a KVM path based on the operating system. For example, the KVM path for Ubuntu is /usr/bin/kvm. --> <disk type='file' device='disk'><!-- Specify the type parameter based on the image format. Set type to qcow2 if the image is in the QCOW2 format, and set type to vpc if the image is in the VHD format. --> -- If you want to create a snapshot in the QCOW2 format, you must disable dataplane. --> <source file='path'/> <!-- Enter the absolute path of the Alibaba Cloud Linux 2 image. --> <target dev='vda' bus='virtio'/> </disk> -- Add the information of seed.img. --> <disk type='file' device='disk'> <driver name='qemu' type='raw'/> <source file='/path/to/your/seed.img'/> <!-- Enter the absolute path of seed.img. -->. <target dev='vdb' bus='virtio'/> </disk> <interface type='network'> <source network='default'/> <model type='virtio'/> </interface> <console type='pty'> <target type='virtio' port='0'/> </console> <video> <model type='cirrus' vram='9216' heads='1'/> <alias name='video0'/> </video> <input type='tablet' bus='usb'/> <input type='mouse' bus='ps2'/> <graphics type='vnc' port='-1' autoport='yes'/> </devices> </domain>
- Run the
virsh
command to start the KVM.Note By default, libvirt is started by a common user. Make sure that common users have the permissions to manage image files and their paths.virsh define alinux2.xml virsh start KVMName # Enter the name of the KVM.
- Create a configuration file in the XML format on your computer. The sample file is named
- Run the
qemu-kvm
command to start the KVM. You must append the following parameter information to the command. Set thefile
parameter to the actual absolute path of the seed.img image.
For more information about how to use the libvirt and qemu-kvm commands, see Installing Virtualization Packages Manually.-drive file=/path/to/your/seed.img,if=virtio,format=raw
- Use the graphical interface (virt-manager) to start the KVM. Before you start the KVM, find the configuration file of the KVM on your computer and add the absolute path of the seed.img image to the configuration file.