【openstack】qemu 制作 qcow2 云镜像(基于 debian)

简介: 【openstack】qemu 制作 qcow2 云镜像(基于 debian)

正文


一、准备 debian 镜像


debian 镜像下载地址

将下载好的镜像放入 /data 目录(没有的话自行创建)

123.webp.jpg

二、安装虚拟化需要的组件


yum -y install qemu-kvm  qemu-img kvm qemu-kvm-tools libvirt  bridge-utils  virt-*


三、启动libvirtd


systemctl enable libvirtd
systemctl start libvirtd
echo "net.ipv4.ip_forward = 1" >>/etc/sysctl.conf
sysctl -p


四、创建 qcow2 镜像文件


[root@qijing0 data]# qemu-img create -f qcow2 /data/debian-11.4.0.qcow2 100G          
Formatting '/data/debian-11.4.0.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=107374182400 lazy_refcounts=off refcount_bits=16
[root@qijing0 data]# ls
debian-11.4.0-amd64-netinst.iso  debian-11.4.0.qcow2


五、创建虚机


[root@qijing0 data]# virt-install --name debian_qijing --ram 4096 --vcpus 2 --os-type linux --os-variant rhel7 --arch=x86_64 --network network=default,model=virtio --disk path=/data/debian-11.4.0.qcow2,format=qcow2 --location /data/debian-11.4.0-amd64-netinst.iso --console pty,target_type=serial   --graphics vnc,listen=0.0.0.0,port=6666
WARNING  Graphics requested but DISPLAY is not set. Not running virt-viewer.
WARNING  No console to launch for the guest, defaulting to --wait -1
Starting install...
Retrieving file .treeinfo...                                               |    0 B  00:00:00     
Retrieving file content...                                                 |    0 B  00:00:00     
Retrieving file info...                                                    |   74 B  00:00:00     
Retrieving file vmlinuz...                                                 | 6.5 MB  00:00:00     
Retrieving file initrd.gz...                                               |  17 MB  00:00:00     
Domain installation still in progress. Waiting for installation to complete.


124.webp.jpg


六、使用 VNCView 连接


125.webp.jpg


七、装系统


1.webp.jpg

2.webp.jpg

3.webp.jpg

4.webp.jpg

5.webp.jpg6.webp.jpg

7.webp.jpg

8.webp.jpg

9.webp.jpg

10.webp.jpg

11.webp.jpg

12.webp.jpg

13.webp.jpg14.webp.jpg

15.webp.jpg

16.webp.jpg

17.webp.jpg

18.webp.jpg

19.webp.jpg

20.webp.jpg

21.webp.jpg


22.webp.jpg23.webp.jpg

24.webp.jpg

25.webp.jpg

26.webp.jpg

27.webp.jpg


八、关机


shutdown now


九、清理机器配置信息


[root@qijing0 ~]# virt-sysprep -d debian_qijing
[   0.0] Examining the guest ...
[  28.8] Performing "abrt-data" ...
[  28.8] Performing "backup-files" ...
[  29.0] Performing "bash-history" ...
[  29.0] Performing "blkid-tab" ...
[  29.0] Performing "crash-data" ...
[  29.0] Performing "cron-spool" ...
[  29.1] Performing "dhcp-client-state" ...
[  29.1] Performing "dhcp-server-state" ...
[  29.1] Performing "dovecot-data" ...
[  29.1] Performing "logfiles" ...
[  29.1] Performing "machine-id" ...
[  29.1] Performing "mail-spool" ...
[  29.1] Performing "net-hostname" ...
[  29.1] Performing "net-hwaddr" ...
[  29.1] Performing "pacct-log" ...
[  29.1] Performing "package-manager-cache" ...
[  29.2] Performing "pam-data" ...
[  29.2] Performing "passwd-backups" ...
[  29.2] Performing "puppet-data-log" ...
[  29.2] Performing "rh-subscription-manager" ...
[  29.2] Performing "rhn-systemid" ...
[  29.2] Performing "rpm-db" ...
[  29.2] Performing "samba-db-log" ...
[  29.2] Performing "script" ...
[  29.2] Performing "smolt-uuid" ...
[  29.2] Performing "ssh-hostkeys" ...
[  29.2] Performing "ssh-userdir" ...
[  29.2] Performing "sssd-db-log" ...
[  29.2] Performing "tmp-files" ...
[  29.2] Performing "udev-persistent-net" ...
[  29.2] Performing "utmp" ...
[  29.2] Performing "yum-uuid" ...
[  29.2] Performing "customize" ...
[  29.2] Setting a random seed
[  29.3] Setting the machine ID in /etc/machine-id
[  29.3] Performing "lvm-uuids" ...


十、压缩镜像


[root@qemu-again data]# virt-sparsify --compress /data/debian-11.4.0.qcow2 /data/debian-11.4.0-bare.qcow2
[   0.1] Create overlay file in /tmp to protect source disk
[   0.2] Examine source disk
[   3.9] Fill free space in /dev/sda1 with zero
 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
[1124.9] Clearing Linux swap on /dev/sda5
[1137.2] Copy to destination and make sparse
[2196.9] Sparsify operation completed with no errors.
virt-sparsify: Before deleting the old disk, carefully check that the 
target disk boots and works correctly.
[root@qemu-again data]# 
[root@qemu-again data]# 
[root@qemu-again data]# 
[root@qemu-again data]# date
Thu Aug 25 08:25:26 UTC 2022

31.webp.jpg


可以看到,压缩之后的 qcow2 镜像已经生成了。(我这里的镜像压缩完之后还是比较大,因为里面装了 git,还有一个比较大的数据库软件)


30.webp.jpg


十一【附加】、上传镜像到 openstack(使用kolla-ansible 部署的)


source /etc/kolla/admin-openrc.sh


root@OpenStack:~/workspace_openstack# openstack image create --disk-format qcow2 --file debian-11.4.0-bare.qcow2 --progress debian-11.4.0-bare --public 
/usr/lib/python3/dist-packages/secretstorage/dhcrypto.py:15: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
  from cryptography.utils import int_from_bytes
/usr/lib/python3/dist-packages/secretstorage/util.py:19: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
  from cryptography.utils import int_from_bytes
[=============================>] 100%
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field            | Value                                                                                                                                                  |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
| container_format | bare                                                                                                                                                   |
| created_at       | 2022-08-25T08:31:28Z                                                                                                                                   |
| disk_format      | qcow2                                                                                                                                                  |
| file             | /v2/images/38ab0af9-6592-435f-99e1-bfa91e8ceae6/file                                                                                                   |
| id               | 38ab0af9-6592-435f-99e1-bfa91e8ceae6                                                                                                                   |
| min_disk         | 0                                                                                                                                                      |
| min_ram          | 0                                                                                                                                                      |
| name             | debian-11.4.0-bare                                                                                                                                     |
| owner            | eee0422e34e248959f2333b1bd600935                                                                                                                       |
| properties       | os_hidden='False', owner_specified.openstack.md5='', owner_specified.openstack.object='images/debian-11.4.0-bare', owner_specified.openstack.sha256='' |
| protected        | False                                                                                                                                                  |
| schema           | /v2/schemas/image                                                                                                                                      |
| status           | queued                                                                                                                                                 |
| tags             |                                                                                                                                                        |
| updated_at       | 2022-08-25T08:31:28Z                                                                                                                                   |
| visibility       | public                                                                                                                                                 |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
root@OpenStack:~/workspace_openstack#

28.webp.jpg

目录
相关文章
|
6月前
|
云计算 数据安全/隐私保护 虚拟化
云计算|OpenStack|社区版OpenStack安装部署文档(十一--- 如何获取镜像---Rocky版)
云计算|OpenStack|社区版OpenStack安装部署文档(十一--- 如何获取镜像---Rocky版)
174 0
|
Ubuntu Linux KVM
分享一些OpenStack的qcow2格式实例镜像
分享一些OpenStack的qcow2格式实例镜像
分享一些OpenStack的qcow2格式实例镜像
|
Linux Shell 网络安全
Debian10.7 自动化安装镜像制作
Debian10.7 自动化安装镜像制作
1207 0
Debian10.7 自动化安装镜像制作
|
容器
【openstack】导出 qcow2 镜像
【openstack】导出 qcow2 镜像
686 0
【openstack】导出 qcow2 镜像
|
6月前
|
存储 关系型数据库 MySQL
云计算|OpenStack|社区版OpenStack安装部署文档(四 --- 镜像服务glance安装部署---Rocky版)
云计算|OpenStack|社区版OpenStack安装部署文档(四 --- 镜像服务glance安装部署---Rocky版)
175 0
|
4月前
|
网络安全 算法框架/工具 开发工具
Packer构建openStack镜像
Packer构建openStack镜像
89 13
|
3月前
|
Ubuntu Linux 测试技术
下载ISO镜像的方法 Debian、Red Hat 、CentOS、Ubuntu、Kali Linux🌐
Debian、Red Hat、CentOS、Ubuntu与Kali Linux均为知名Linux发行版。下载Debian须访问官网并按计算机架构选ISO文件。Red Hat下载通常需订阅账户,可从官网登录后获取。CentOS可从官网或镜像站点下载,注意CentOS 8已停更。Ubuntu下载简便,官网直接选取版本及架构即可。Kali Linux专为安全测试设计,官网提供直接下载ISO镜像服务。
733 0
|
缓存 Linux
【阿里云镜像】切换阿里巴巴开源镜像站镜像——Debian镜像
【阿里云镜像】切换阿里巴巴开源镜像站镜像——Debian镜像
1564 1
【阿里云镜像】切换阿里巴巴开源镜像站镜像——Debian镜像
|
6月前
|
Kubernetes 安全 API
debian11 安装 k8s,containerd ,阿里云镜像(已成功)
在准备 Kubernetes 集群环境中,确保每台机器至少有 2GB RAM,推荐 4GB,需连接网络。需3台机器,1台作为 Master,2台作为 Worker。安装 `sudo`,设置各节点主机名为 k8s-master、k8s-node1、k8s-node2,并更新 `/etc/hosts`。升级系统,接着安装并更新 containerd 至 v1.7,配置 `containerd` 并启用。
644 0
|
6月前
|
Linux KVM 云计算
云计算|OpenStack|社区版OpenStack安装部署文档(十三--- 自制镜像---Linux和Windows镜像)
云计算|OpenStack|社区版OpenStack安装部署文档(十三--- 自制镜像---Linux和Windows镜像)
296 0