使用libvirt创建kvm虚拟机

来源:互联网 发布:sql增删改查语句 编辑:程序博客网 时间:2024/06/09 17:04
(1)制作虚拟机镜像

qemu-img create -f qcow2 test.qcow2 10G
(2)下载并复制iso镜像到指定目录,本文将所有镜像及配置文件放到/var/lib/libvirt/images/目录下,注意:有些系统因为SELinux的原因,限定了qemu的访问,所以,可以根据自己需求调整,默认放在/var/lib/libvirt/images/下。
(3)创建安装配置文件,demo.xml如下,可以根据自己需求更改。

<domain type='kvm'>    <name>myslax</name>             <memory>1048576</memory>                     <currentMemory>524288</currentMemory>        <vcpu>1</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/bin/qemu-system-x86_64</emulator>     <disk type='file' device='disk'>      <driver name='qemu' type='qcow2'/>                  <source file='/home/YC/image/slax.qcow2'/>                <target dev='hda' bus='ide'/>     </disk>     <disk type='file' device='cdrom'>       <source file='/home/YC/image/slax.iso'/>                   <target dev='hdb' bus='ide'/>     </disk>    <interface type='bridge'>                          <source bridge='virbr0'/>      <mac address="00:16:3e:5d:aa:a8"/>       </interface>    <input type='mouse' bus='ps2'/>     <graphics type='vnc' port='-1' autoport='yes' listen = '0.0.0.0' keymap='en-us'/>   </devices> </domain>



virsh define demo.xml //创建虚拟机
virsh start myslax //启动虚拟机
virsh vncdisplay myslax //查看虚拟机的vnc端口, 然后就可以通过vnc登录来完成虚拟机的安装


3. 使用刚才创建好的镜像来启动一个新的虚拟机
(1)创建启动配置文件,demo.xml如下。
<domain type='kvm'>    <name>myslax</name>             <memory>1048576</memory>                     <currentMemory>524288</currentMemory>        <vcpu>1</vcpu>                                                         <os>      <type arch='x86_64' machine='pc'>hvm</type>      <boot dev='hd'/>      //中硬盘启动                                              </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/bin/qemu-system-x86_64</emulator>     <disk type='file' device='disk'>      <driver name='qemu' type='qcow2'/>                  <source file='/home/YC/image/slax.qcow2'/>                <target dev='hda' bus='ide'/>     </disk>     <disk type='file' device='cdrom'>       <source file='/home/YC/image/slax.iso'/>                   <target dev='hdb' bus='ide'/>     </disk>    <interface type='bridge'>                          <source bridge='virbr0'/>      <mac address="00:16:3e:5d:aa:a8"/>       </interface>    <input type='mouse' bus='ps2'/>     <graphics type='vnc' port='-1' autoport='yes' listen = '0.0.0.0' keymap='en-us'/>   </devices> </domain>

virsh define demo.xml

virsh start myslax


4, 虚拟机管理
    虚拟机的管理即通过virsh命令来完成,具体命令的使用参见:http://libvirt.org/sources/virshcmdref/html-single/
本篇文章来源于 Linux公社网站(www.linuxidc.com)  原文链接:http://www.linuxidc.com/Linux/2012-06/62934.htm
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 小班健康跌倒了怎么办 刷油漆有纹路怎么办 纯白门会发黄怎么办 发现小孩子偷钱怎么办 青春期孩子偷钱怎么办 孩子偷钱屡教不改怎么办 孩子经常偷钱怎么办 小孩子总是偷钱怎么办 小孩喜欢偷钱怎么办 小孩老是偷钱怎么办 如果孩子偷钱怎么办 小孩在家偷钱怎么办 买了西晒房怎么办 乳胶漆有打磨痕迹怎么办 墙上乳胶漆用水擦完太亮了怎么办 外墙腻子不好打磨怎么办 腻子打磨的灰尘怎么办 家里的壁纸脏了怎么办 家装用冷风管冬天取暖怎么办? 房子装修冷色系怎么办 高血压突然变低血压怎么办 玩单机游戏卡顿怎么办 老人血压太低怎么办 老年人血压太低怎么办 觉总是不够睡怎么办 老年人气不够用怎么办 卧室晒不到太阳怎么办 农村房子墙角受潮怎么办 房间里面有虫子怎么办 墙壁发霉生虫子怎么办 墙壁发霉有虫子怎么办 墙面发霉有虫子怎么办 白漆墙面脏了怎么办 房间贴完墙墙面发霉怎么办? 家里的墙壁发霉怎么办 黑豆生虫了怎么办 家具有小虫子怎么办 店铺对面有镜子怎么办 房间里有蛆虫怎么办 房间里有虫子怎么办 小宝宝发烧了怎么办啊