您的位置:首页 > 大数据 > 云计算

制作云计算平台的虚拟机镜像

2020-06-27 11:28 1791 查看

在基于OpenStack、CloudStack、ZStack、Proxmox Virtual Environment 等开源虚拟化或者云计算服务管理的VM实例中,推荐使用的VM镜像格式是raw或者是压缩率更高的qcow2。VMware ESXi使用的推荐格式是OVF或者vmdk。
鉴于本人主要从事开源产品的实践维护及适用场景解决方案研究,因此本文主要讨论qcow2格式的VM镜像的制作方法。
第一种方法是在基于Linux的KVM环境下创建虚拟机,主要通过 qemu、kvm、virtsh工具完成,如果自己有GUI的Linux环境还可以使用VNC进行GUI界面操作完成虚拟机的创建及Guest OS安装配置。这里我给出本人在 KVM 环境中创建虚拟机的主要操作命令:

virt-install --virt-type kvm --name Windows7Bit64 --ram 2048 --vcpus=2 --os-type=windows \
--cdrom=/mnt/hgfs/VirtualLocalShare/VirtIO/win7caijing64.iso --disk path=/mnt/hgfs/VirtualLocalShare/VirtIO/Windows7Bit64.qcow2,format=qcow2,bus=virtio \
--disk path=/mnt/hgfs/VirtualLocalShare/VirtIO/virtio-win-0.1.185.iso,device=cdrom,perms=rw \
--disk path=/mnt/hgfs/VirtualLocalShare/VirtIO/virtio-win-0.1.185_amd64.vfd,device=floppy --network bridge=br0,model=virtio \
--graphics vnc,listen=0.0.0.0 --noautoconsole

如需更多个性化定制,敬请参考 KVM 操作命令。

第二种方法是通过 Web GUI 进行VNC远程操作。
本次我创建的 Windows 7 和Windows 10 系统镜像主要用于某单位内部办公和对外招考新兵使用,考虑到需要在 Guest OS 上做较多的优化配置和必要的精简,因此我选择使用VNC连接的PVE作为制作环境,操作系统底版分别使用了俄国Lokin和东莞三杰的精简版以及我个人基于Windows 10 1903 做的精简版,同时我个人又在俄国Lokin和东莞三杰的精简版上做了第二次的必要组件安装和非必要组件的移除。

我的PVE环境是 5.4版,安装过程中仅把官方源换成了国内源。PVE的硬件配置建议CPU不少于12核心、硬盘不低于250GB、内存不低于16GB。
以下是主要的安装配置过程:

echo "# deb https://enterprise.proxmox.com/debian/pve stretch pve-enterpris" > /etc/apt/sources.list.d/pve-enterprise.list
wget http://download.proxmox.com/debian/proxmox-ve-release-5.x.gpg -O /etc/apt/trusted.gpg.d/proxmox-ve-release-5.x.gpg
cat >> /etc/apt/sources.list << EOF
deb http://download.proxmox 5574 .wiki/debian/pve stretch pve-no-subscription
deb http://mirrors.aliyun.com/debian/ stretch main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ stretch main non-free contrib
deb http://mirrors.aliyun.com/debian-security stretch/updates main
deb-src http://mirrors.aliyun.com/debian-security stretch/updates main
deb http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib
deb http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib
EOF
apt-get clean all
apt update
apt-get install -y ntp net-tools vim* lrzsz tree

在PVE的 Web UI 上创建目标虚拟机,建议CPU为4核心、内存为4GB,所有的设备安装时都选择VirtIO模式。
如果安装过程中VirtIO驱动不能被识别,请先将硬盘改为SATA模式进行安装,安装完毕后再添加一块VirtIO模式的硬盘并用VirtIO驱动包进行扫描安装全部设备的驱动,而后关机、移除新添加的VirtIO模式的硬盘。
在GuestOS中优化 Windows 7 或 Windows 10 并安装完毕必要软件后,进行关机。而后执行以下命令将VM导出为qcow2镜像格式:

qemu-img convert -O qcow2 -c /dev/mapper/pve-vm--101--disk--0 /Image/Windows10Bit64.qcow2
qemu-img convert -O qcow2 -c /dev/mapper/pve-vm--100--disk--0 /Image/Windows7Bit64.qcow2
cp /etc/pve/nodes/pve/qemu-server/101.conf /Image/
cp /etc/pve/nodes/pve/qemu-server/100.conf /Image/
qemu-img check /Image/Windows10Bit64.qcow2
qemu-img check /Image/Windows7Bit64.qcow2

至此,VM实例的虚拟镜像已经制作完毕。
接下来只要将镜像传送到目标节点上去创建VM实例即可,参考命令如下:

qm importdisk 102 Windows10Bit64.qcow2 local-lvm

本次制作的 Windows 7 或 Windows 10 的qcow2镜像已经上传到了本人的腾讯云盘,如需要可直接联系本人索要。本次镜像中安装的软件有 WPS 2016、360压缩、Google Chrome浏览器、CAJViewer、Foxit Reader、PCmaster、PowerShadow、PureCode多媒体播放器、QQPinyin、SecureCRT&FX、TIM、WeChat,本次软件的最新版本截止到2020年6月25日。镜像的大小信息如下:

3.4G    Windows7Bit64.qcow2
3.3G    Windows10Bit64.qcow2

下图是 Guest OS 截图:


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: