linux kvm installation guide

Install

sudo apt-get install kvm qemu

sudo apt-get install virtinst python-libvirt virt-viewer virt-manager

start LVM
sudo virt-manager
 

View virtual operation status

virsh list -all

$ virsh list --all
 Id name status
----------------------------------------- -------------
 8 win2k8r2 running
 - centos7.0 shut down

 

Power on the virtual machine

virsh start centos7.0

Shut down the virtual machine

virsh shudown centos7.0

Force shutdown of the virtual machine

virsh destroy centos7.0

As the physical machine restarts, the virtual machine also restarts automatically

         virsh autostart win2k8r2

——————————————————————————————————————

创建空硬盘,相当于物理机的硬盘(公司常用的qcow2格式)

[root@KVM ~]# qemu-img create -f qcow2 /home/kvm/kvm-demo2.qcow2 50G 

virt-install method to install 

virt-install --virt-type kvm --name kvm-demo --boot network,cdrom,menu=on --ram 1024 --cdrom=/home/kvm/CentOS-7.iso --graphics vnc,listen=0.0.0.0 --noautoconsole --os-type=linux --os-variant=rhel7 --accelerate --disk path=/home/kvm/kvm-demo2.qcow2,size=5,format=qcow2,bus=virtio --bridge=br0,model=virtio --autostart

 --virt-type 

--name kvm-demo

新客户虚拟机实例名字,在连接的hypervisor已知的所有虚拟机中必须唯一,包括那些当前未活动的虚拟机。(   Name of the new guest virtual machine instance. This must be unique amongst all guests known to the hypervisor on the connection, including those not currently active. )

--boot

--ram

--os-type

--cdrom

 --graphics vnc,listen=0.0.0.0

--noautoconsole

 --os-variant

--accelerate

--disk path=/home/kvm/kvm-demo2.qcow2,size=5,format=qcow2,bus=virtio 

--bridge=br0,model=virtio 

--autostart


将虚拟机重命名

比如我们希望将服务器上的虚拟机pc_vm94 改名称为 vm94

1)使用 virsh list --all命令查看当前都哪些虚拟机。

 # virsh list --all                                                          
 Id    Name                           State                 
----------------------------------------------------   
 1758  pc_vm94                        running    


2) 导出原有虚拟机的配置文件

在导出配置之前使用virsh destroy pc_vm94命令将虚拟机关闭。

 #virsh destroy pc_vm94                                       

Domain pc_vm94 destroyed  

转到/etc/libvirt/qemu  目录下对原来的虚拟机配置进行导出

virsh dumpxml pc_vm94 > vm94.xml 

(注意>前面并没有.xml ,这是因为我们需要导出虚拟机的配置,将配置保存到一个xml文件中 )


3) 新的虚拟机的配置文件修改

导出之后我们需要将虚拟机的文件修改一下

将 
    pc_vm94

...

更改为
    vm94

...


至于虚拟机所对应的磁盘文件。可以沿用之前的,不需要任何修改;也可以改成与名称一直的。如果虚拟机对应的磁盘文件修改的话,必须也要在xml文件中做对应的修改。


4)虚拟机的重新定义

使用virsh undefine 命令将之前的虚拟机删除

virsh undefine pc_vm94

Domain pc_vm94 has been undefined  

使用virsh define 命令将重新定义新的虚拟机

# virsh define vm94.xml          
Domain vm94 defined from vm94.xml


5)这时候使用命令就可以看到已经将原来的虚拟机重新更改为另一个名称

virsh list --all                                                  
 Id    Name                           State                  
----------------------------------------------------   
 -     vm94                           shut off  


经过上述几步的处理,仅仅是将虚拟机的名称改变了一下,其余都没有发生变化。也就是对虚拟机进行了重命名

 

 参考连接:http://www.cnblogs.com/liang-wei/p/6732055.html

http://duxiansheng.blog.51cto.com/11062970/1737585

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325485271&siteId=291194637