下载镜像文件
下载链接:https://mirrors.aliyun.com/alinux/image/?spm=a2c4g.11186623.0.0.79ed5af6pehv54
下载文件:aliyun_3_x64_20G_nocloud_alibase_20230727.qcow2
部署KVM虚拟化环境
yum -y install qemu libvirt rr-testsuite
systemctl start libvirtd
systemctl enable libvirtd
准备镜像文件
将aliyun_3_x64_20G_nocloud_alibase_20230727.qcow2拷贝到镜像文件目录,一般默认/var/lib/libvirt/images/disks/
本地生成seed.img引导镜像
1、在镜像文件同一级目录下,创建meta-data和user-data两个配置文件。
cd /var/lib/libvirt/images/disks/
mkdir seed
cd seed
vi meta-data
#cloud-config
#vim:syntax=yaml
local-hostname: alinux-host
vi user-data
#cloud-config
#vim:syntax=yaml
# 添加一个名为alinux的账号,并且可以执行sudo命令。
users:
- default
- name: alinux
sudo: ['ALL=(ALL) ALL']
plain_text_passwd: aliyun
lock_passwd: false
# 添加Alibaba Cloud Linux 3的YUM源。
yum_repos:
alinux3-module:
name: alinux3-module
baseurl: https://mirrors.aliyun.com/alinux/$releasever/module/$basearch/
enabled: 1
gpgcheck: 1
gpgkey: https://mirrors.aliyun.com/alinux/$releasever/RPM-GPG-KEY-ALINUX-3
alinux3-updates:
name: alinux3-updates
baseurl: https://mirrors.aliyun.com/alinux/$releasever/updates/$basearch/
enabled: 1
gpgcheck: 1
gpgkey: https://mirrors.aliyun.com/alinux/$releasever/RPM-GPG-KEY-ALINUX-3
alinux3-plus:
name: alinux3-plus
baseurl: https://mirrors.aliyun.com/alinux/$releasever/plus/$basearch/
enabled: 1
gpgcheck: 1
gpgkey: https://mirrors.aliyun.com/alinux/$releasever/RPM-GPG-KEY-ALINUX-3
alinux3-powertools:
name: alinux3-powertools
baseurl: https://mirrors.aliyun.com/alinux/$releasever/powertools/$basearch/
gpgcheck: 1
enabled: 1
gpgkey: https://mirrors.aliyun.com/alinux/$releasever/RPM-GPG-KEY-ALINUX-3
alinux3-os:
name: alinux3-os
baseurl: https://mirrors.aliyun.com/alinux/$releasever/os/$basearch/
gpgcheck: 1
enabled: 1
gpgkey: https://mirrors.aliyun.com/alinux/$releasever/RPM-GPG-KEY-ALINUX-3
2、配置epel-testing仓库
vi /etc/yum.repos.d/epel-testing.repo
[epel-testing]
name=Extra Packages for Enterprise Linux 8 - Testing - $basearch
baseurl=http://mirrors.cloud.aliyuncs.com/epel/testing/8/Everything/$basearch
enabled=0
gpgcheck=1
countme=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
3、安装cloud-utils并生成seed.img镜像
sudo yum install -y cloud-utils
sudo cloud-localds seed.img user-data meta-data
定义虚拟机
vi /etc/libvirt/qemu/AliyunOS3.xml
<domain type='kvm'>
<name>AliyunOS3</name>
<memory unit='KiB'>4194304</memory>
<currentMemory unit='KiB'>4194304</currentMemory>
<vcpu placement='static'>8</vcpu>
<os>
<type arch='x86_64'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
</features>
<cpu mode='host-model' check='partial'>
<model fallback='allow'/>
</cpu>
<clock sync="localtime"/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<pm>
<suspend-to-mem enabled='no'/>
<suspend-to-disk enabled='no'/>
</pm>
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2' cache='none' dataplane='on' io='native'/>
<source file='/var/lib/libvirt/images/disks/aliyun_3_x64_20G_nocloud_alibase_20230727.qcow2'/>
<target dev='sda' bus='scsi'/>
</disk>
<disk type='file' device='disk'>
<driver name='qemu' type='raw'/>
<source file='/var/lib/libvirt/images/disks/seed/seed.img'/>
<target dev='sdb' bus='scsi'/>
</disk>
<interface type='bridge'>
<mac address='52:54:00:f7:ff:4c'/>
<source bridge='virbr0'/>
<model type='virtio'/>
</interface>
<console type='pty'>
<target type='virtio' port='0'/>
</console>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<input type='tablet' bus='usb'/>
<graphics type='vnc' port='-1' autoport='yes'>
</graphics>
<video>
<model type='cirrus' vram='9216' heads='1'/>
<alias name='video0'/>
</video>
</devices>
</domain>
根据虚拟机配置文件,创建虚拟机
virsh define AliyunOS3.xml
virsh list --all
Id Name State
----------------------------------------------------
- AliyunOS3 shut off
启动虚拟机
virsh start AliyunOS3
virsh list
Id Name State
----------------------------------------------------
2 AliyunOS3 running
连接虚拟机的console口
注意:我们上面没有提前配置KVM虚拟机环境的网络桥接,可能你无法直接远程访问这台机器。可以通过rinetd做转发。
virsh console AliyunOS3