创建qcow2镜像

利用vmware创建一台虚拟机

设置虚拟机网络

因是测试练习,这里设置为桥接模式
目标是自己电脑和创建的虚拟机能互相ping通。
1、配置虚拟机为桥接模式
2、查看自己电脑信息
在cmd中使用ipconfig -all查看

无线局域网适配器 WLAN:

   连接特定的 DNS 后缀 . . . . . . . : www.tendawifi.com
   描述. . . . . . . . . . . . . . . : Intel(R) Dual Band Wireless-N 7260
   物理地址. . . . . . . . . . . . . : 58-91-CF-64-B4-19
   DHCP 已启用 . . . . . . . . . . . : 是
   自动配置已启用. . . . . . . . . . : 是
   本地链接 IPv6 地址. . . . . . . . : fe80::2c24:7e11:b465:2d0a%14(首选)
   IPv4 地址 . . . . . . . . . . . . : 192.168.0.102(首选) #有用
   子网掩码  . . . . . . . . . . . . : 255.255.255.0 #有用
   获得租约的时间  . . . . . . . . . : 2020年2月16日 16:41:41
   租约过期的时间  . . . . . . . . . : 2020年2月18日 11:00:59
   默认网关. . . . . . . . . . . . . : 192.168.0.1 #有用
   DHCP 服务器 . . . . . . . . . . . : 192.168.0.1
   DHCPv6 IAID . . . . . . . . . . . : 106467791
   DHCPv6 客户端 DUID  . . . . . . . : 00-01-00-01-24-2E-50-83-FC-3F-DB-D1-23-9A
   DNS 服务器  . . . . . . . . . . . : 10.100.1.12 #有用
                                       10.100.1.11
                                       127.0.0.1
                                       192.168.0.1
   TCPIP 上的 NetBIOS  . . . . . . . : 已启用

3、修改虚拟机IP

[root@openstack ~]# cd /etc/sysconfig/network-scripts/
[root@openstack network-scripts]# vim ifcfg-ens33 
[root@openstack network-scripts]# 
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static   #需要修改为静态IP
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=b19556bd-278b-4955-8680-42b06b976d56
DEVICE=ens33
ONBOOT=yes   # 修改为开机启动
IPADDR=192.168.0.233   #新增IP地址,与自己电脑IP同一个网段
GATEWAY=192.168.0.1    #新增网关
NETMASK=255.255.255.0  #新增子网掩码
IPV6_PRIVACY=no

4、修改虚拟机DNS

[root@openstack network-scripts]# vim /etc/resolv.conf
nameserver 10.100.1.12
nameserver 127.0.0.1

5、重启网络

[root@openstack network-scripts]# systemctl restart network

6、测试互ping

安装虚拟机软件

虚拟机是通过 centos7-1704安装的
存在一个ISO镜像
镜像中已经包含了如下的安装包。

yum install -y libvirt
yum install -y qemu-kvm
yum install -y virt-install

启动服务

systemctl start libvirtd

创建qcow2磁盘

[root@openstack ~]# qemu-img create -f qcow2 /tmp/centos7abc.qcow2 10G
Formatting '/tmp/centos7abc.qcow2', fmt=qcow2 size=10737418240 encryption=off cluster_size=65536 lazy_refcounts=off

创建虚拟机

[root@openstack ~]# virt-install --virt-type kvm --name centos7abc --ram 1024 --disk /tmp/centos7abc.qcow2,format=qcow2 --network network=default --graphics vnc,listen=0.0.0.0 --noautoconsole --os-type=linux --os-variant=centos7.4 --location=/opt/CentOS-7-x86_64-DVD-1708.iso
ERROR    Host does not support domain type kvm for virtualization type 'hvm' arch 'x86_64'

上述错误的解决办法:

解决方法:

1.modprobe kvm 验证不行
2.去掉–virt-type kvm参数即可。 验证可以

[root@openstack network-scripts]# virt-install --name centos7abc --ram 1024 --disk /tmp/centos7abc.qcow2,format=qcow2 --network network=default --graphics vnc,listen=0.0.0.0 --noautoconsole --os-type=linux --os-variant=centos7.4 --location=/opt/CentOS-7-x86_64-DVD-1708.iso
WARNING  KVM acceleration not available, using 'qemu'
ERROR    Error validating install location: Distro 'centos7.4' does not exist in our dictionary

把7.4改成7.0后再执行

[root@openstack network-scripts]# virt-install --name centos7abc --ram 1024 --disk /tmp/centos7abc.qcow2,format=qcow2 --network network=default --graphics vnc,listen=0.0.0.0 --noautoconsole --os-type=linux --os-variant=centos7.0 --location=/opt/CentOS-7-x86_64-DVD-1708.iso
WARNING  KVM acceleration not available, using 'qemu'

Starting install...
Retrieving file .treeinfo...                                                                                                                                                              |  354 B  00:00:00     
Retrieving file vmlinuz...                                                                                                                                                                | 5.6 MB  00:00:00     
Retrieving file initrd.img...                                                                                                                                                             |  46 MB  00:00:00     
Domain installation still in progress. You can reconnect to 
the console to complete the installation process.

查看创建好的虚拟机

[root@openstack network-scripts]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 1     centos7abc                     running

启动虚拟机,已经启动好了,上面状态已经是running状态了

[root@openstack network-scripts]# virsh start centos7abc
error: Domain is already active

查看 vnc连接端口

[root@openstack network-scripts]# netstat -antp | grep 5900
tcp        0      0 0.0.0.0:5900            0.0.0.0:*               LISTEN      19601/qemu-kvm 

VNC连接

安装vnc服务

[root@openstack network-scripts]# yum install tightvnc-server
[root@openstack network-scripts]# yum install tightvnc

初始化vnc服务

[root@openstack network-scripts]# vncserver

You will require a password to access your desktops.

Password:
Verify:
Would you like to enter a view-only password (y/n)? y
Password:
Verify:
xauth:  file /root/.Xauthority does not exist

New 'openstack:1 (root)' desktop is openstack:1

Creating default startup script /root/.vnc/xstartup
Creating default config /root/.vnc/config
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/openstack:1.log

修改配置文件
进入/usr/lib/systemd/system

[root@openstack system]# pwd
/usr/lib/systemd/system

编辑vncserver@.service

[root@openstack system]# vim vncserver\@.service
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=forking
User=<USER>

# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=-/usr/bin/vncserver -kill %i
ExecStart=/usr/bin/vncserver %i
PIDFile=/home/<USER>/.vnc/%H%i.pid
ExecStop=-/usr/bin/vncserver -kill %i

[Install]
WantedBy=multi-user.target

修改为

[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=simple
User=root

# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=-/usr/bin/vncserver -kill %i
ExecStart=/usr/bin/vncserver %i
PIDFile=/root/.vnc/%H%i.pid
ExecStop=-/usr/bin/vncserver -kill %i

[Install]
WantedBy=multi-user.target

保存退出重新加载,重新启动vncserver服务

[root@openstack system]# systemctl daemon-reload
[root@openstack system]# systemctl restart vncserver@:1.service

查看状态

[root@openstack network-scripts]# systemctl status vncserver@:1.service
● vncserver@:1.service - Remote desktop service (VNC)
   Loaded: loaded (/usr/lib/systemd/system/vncserver@.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2020-02-17 19:04:46 CST; 1min 0s ago
  Process: 19936 ExecStartPre=/usr/bin/vncserver -kill %i (code=exited, status=0/SUCCESS)
 Main PID: 19951 (Xvnc)
   CGroup: /system.slice/system-vncserver.slice/vncserver@:1.service
           └─19951 /usr/bin/Xvnc :1 -auth /root/.Xauthority -desktop openstack:1 (root) -fp catalogue:/etc/X11/fontpath.d -geometry 1024x768 -pn -rfbauth /root/.vnc/passwd -rfbport 5901 -rfbwait 30000

Feb 17 19:04:45 openstack systemd[1]: Starting Remote desktop service (VNC)...
Feb 17 19:04:45 openstack vncserver[19936]: Killing Xvnc process ID 19871
Feb 17 19:04:46 openstack systemd[1]: Started Remote desktop service (VNC).
Feb 17 19:04:49 openstack vncserver[19943]: New 'openstack:1 (root)' desktop is openstack:1
Feb 17 19:04:49 openstack vncserver[19943]: Starting applications specified in /root/.vnc/xstartup
Feb 17 19:04:49 openstack vncserver[19943]: Log file is /root/.vnc/openstack:1.log

自己电脑上下载vnc viewer
地址栏直接输入虚拟机的IP地址和:0,回车就到了虚拟机内部创建的子虚拟机的系统安装界面了。
在这里插入图片描述
在这里插入图片描述
如果地址栏里输入的是IP:1,则进入的是自己电脑创建的虚拟机。
在安装的过程中有这一步

performing post-installation setup tasks

卡了很久,将近两个小时,不知道是不是内存设置的太不了
最后耐心的等,也走过去了。
安装完成后,reboot

reboot之后,VNC连接断开,查看子虚拟机状态

[root@manager log]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     centos7abc                     shut off

启动子虚拟机

[root@manager log]# virsh start centos7abc
Domain centos7abc started

再次使用VNC连接

操作镜像

进入/tmp目录下查看centos7abc.qcow2文件属性
第一行是ll查看
第二行是ll -h查看

-rw-r--r--  1 qemu      qemu   1638596608 Feb 18 14:44 centos7abc.qcow2
-rw-r--r--  1 qemu      qemu   1.6G Feb 18 14:45 centos7abc.qcow2
[root@manager tmp]# stat centos7abc.qcow2 
  File: ‘centos7abc.qcow2’
  Size: 1638596608	Blocks: 3200264    IO Block: 4096   regular file
Device: 805h/2053d	Inode: 644005874   Links: 1
Access: (0644/-rw-r--r--)  Uid: (  107/    qemu)   Gid: (  107/    qemu)
Access: 2020-02-18 14:45:33.678552741 +0800
Modify: 2020-02-18 14:49:34.318567339 +0800
Change: 2020-02-18 14:49:34.318567339 +0800
 Birth: -
[root@manager tmp]# file centos7abc.qcow2 
centos7abc.qcow2: QEMU QCOW Image (v3), 32212254720 bytes

利用VNC连接子虚拟机往里面写点内容
进入/opt目录下

dd if=/dev/zero of=file2.txt bs=1024 count=1000000

回到虚拟机中,查看/tmp/centos7abc.qcow2文件属性

-rw-r--r--  1 qemu      qemu   2635399168 Feb 18 15:07 centos7abc.qcow2
[root@manager tmp]# stat centos7abc.qcow2 
  File: ‘centos7abc.qcow2’
  Size: 2635399168	Blocks: 8542216    IO Block: 4096   regular file
Device: 805h/2053d	Inode: 644005874   Links: 1
Access: (0644/-rw-r--r--)  Uid: (  107/    qemu)   Gid: (  107/    qemu)
Access: 2020-02-18 15:06:42.188629693 +0800
Modify: 2020-02-18 15:07:42.318633341 +0800
Change: 2020-02-18 15:07:42.318633341 +0800
[root@manager tmp]# file centos7abc.qcow2 
centos7abc.qcow2: QEMU QCOW Image (v3), 32212254720 bytes

压缩镜像

[root@manager tmp]# qemu-img convert -c -O qcow2 centos7abc.qcow2 centos7abc-convt.qcow2
[root@manager tmp]# ll
total 3278108
-rw-r--r--  1 root      hadoop  721506304 Feb 18 15:18 centos7abc-convt.qcow2
-rw-r--r--  1 qemu      qemu   2635399168 Feb 18 15:19 centos7abc.qcow2
[root@manager tmp]# ll -h
...
-rw-r--r--  1 root      hadoop 689M Feb 18 15:18 centos7abc-convt.qcow2
-rw-r--r--  1 qemu      qemu   2.5G Feb 18 15:20 centos7abc.qcow2

之后可以将压缩后的镜像上传到OpenStack中的glance服务中

利用qcow2文件生成虚拟机

参考文章

kvm制作openstack centos7镜像
KVM虚拟化技术之使用Qemu-kvm创建和管理虚拟机
制作OpenStack系统镜像

  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Windows server QCOW2镜像是一种用于虚拟化环境的镜像文件格式。创建Windows server QCOW2镜像的步骤如下: 1. 使用命令cd /data/qcow2进入目标文件夹。 2. 使用命令qemu-img create -f qcow2 win2016.qcow2 30G创建一个30GB大小的QCOW2镜像文件。\[1\] 3. 使用命令openstack image create --disk-format qcow2 --file win2016.qcow2 Windows_Server_2016_Datacenter --public将镜像上传到Openstack。\[2\] 另外,如果你想在KVM虚拟化环境中使用QCOW2镜像,可以使用以下命令: kvm -m 1024 -drive file=windows_server_2012_r2_x64.qcow2,if=virtio,boot=on -cdrom virtio-win-0.1.102.iso -net nic,model=virtio -net user -boot c -nographic -vnc :3。\[3\] #### 引用[.reference_title] - *1* *2* [Openstack制作windows qcow2镜像](https://blog.csdn.net/WuYu1037382760/article/details/119535267)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [windows server 2012R2制作qcow2镜像](https://blog.csdn.net/qq_32014795/article/details/82806124)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值