您的位置:首页 > 运维架构

Openstack中qcow2镜像制作

2016-04-15 09:58 525 查看
1.首先从mirrors.aliyun.com网站下载所需要的iso文件,也可以直接从本地的iso文件夹中直接拷贝。

2.使用命令在所在目录创建镜像文件(此文件就是之后需要上传的镜像文件)

      qemu-img create -f qcow2 ./test.qcow2 50G(镜像大小要和flavor匹配,不能随意配置)

                     
    #本例使用qcow2格式,镜像名字为test,大小为50G

3.写xml文件test.xml,其中cdrom为所选择的iso文件,修改好文件目录

<domain type='kvm'>
   <name>test</name>
   <memory>8388608</memory>                  
   <currentMemory>8388608</currentMemory>    
   <vcpu>4</vcpu>                                                      
   <os>
     <type arch='x86_64' machine='pc'>hvm</type>
     <boot dev='cdrom'/>
  </os>
  <features>
    <acpi/>
    <apic/>
    <pae/>
  </features>
  <clock offset='localtime'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>   
  <on_crash>destroy</on_crash>
  <devices>
    <emulator>/usr/libexec/qemu-kvm</emulator>
    <disk type='file' device='disk'>
     <driver name='qemu' type='raw'/>
      <source file='/home/qcow2/test.qcow2'/>        
      <target dev='hda' bus='virtio'/>
    </disk>
    <disk type='file' device='cdrom'>
      <source file='/home/iso/CentOS-7-2.iso'/>       
      <target dev='hdb' bus='ide'/>
    </disk>
   <interface type='bridge'>                                             
     <source bridge='virbr0'/>
     <model type="virtio"/>
   </interface>
   <input type='mouse' bus='ps2'/>
    <graphics type='vnc' port='-1' autoport='yes' listen = '0.0.0.0' keymap='en-us'/>
  </devices>
 </domain>

4.创建虚拟机

  a. virsh define test.xml              #定义xml文件
  
  b. virsh start test                         #启动test虚拟机

5.使用VNC登录然后安装(此过程也是iso写入qcow2的过程)

 c.virsh vncdisplay test                 #查看vnc端口

 d.  使用VNC客户端登录虚拟机按Centos(Windows一样)步骤安装,直至安装成功。

 e. 如果是windows镜像,需要安装virtio驱动

安装完毕后会发现网络连接不上,这是网卡驱动未更新的原因,

需要右键点击计算机——管理——设备管理器,会发现有感叹号的2个文件,右键点击以太网络适配器,选择更新驱动,选择手动安装,进入
E:/virtio-win/NetKVM/w2k8R2/amd64, 安装完毕后网络会自动连接上

6.关闭虚拟机(建议在虚拟机内部执行关机操作,否则有可能导致蓝屏)

  virsh destroy test

7. 此test.qcow2就是我们所需要的镜像文件

8.上传镜像至glance

 glance image-create --name centos_test --disk-format=qcow2 --container-format=bare --is-public=True --file=/home/qcow2/test.qcow2
      #上传名字为centos_test的镜像(和test.qcow2一模一样)

   上传完毕后使用  glance image-list  命令进行查看是否成功
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  openstack 镜像 qcow2