虚拟机的安装及快照

1.图形管理建立虚拟机

命令打开虚拟机管理界面

[[email protected] ~]# virt-manager

虚拟机的安装及快照

虚拟机的安装及快照虚拟机的安装及快照


 

 虚拟机的安装及快照虚拟机的安装及快照

虚拟机的安装及快照虚拟机的安装及快照虚拟机的安装及快照

 虚拟机的安装及快照

2.用linux命令实现虚拟机的安装

新建一个shell脚本

[[email protected] ~]# vim /mnt/vm_creat.sh

#!/bin/bash

virt-install\                                   ##环境安装

--cdrom /iso/rhel-server-7.0-x86_64-dvd.iso \   ##安装源地址

--ram 1024\                                     ##运行内存

--cpus 1 \                                          

--disk    /var/lib/libvirt/images/$1.qcow2,size=9,bus=virto \   ##硬盘的大小和类型

--name $1 \                                     ##$1第一个字符传递过来

--network source=br0,model=virto &              ##source是网络资源接口,&不占用终端

添加可执行权限

[[email protected] ~]# chmod +x /mnt/vm_creat.sh

3.虚拟机的“快照”

虚拟机的状态参数的备份。

虚拟机的安装及快照虚拟机的安装及快照

 

虚拟机的安装及快照虚拟机的安装及快照

 

 

 

4.新建脚本可以快速执行虚拟机的备份:

[[email protected] ~]# vim /mnt/vm_snapshot.sh

#!/bin/bash

qemu-img creat -f qcow2 -b \

 

/var/lib/libvirt/images/$1.qcow2 \

/var/lib/libvirt/images/$2.qcow2 \

 

virt-install\

--name $2 \

#--cdrom /iso/rhel-server-7.0-x86_64-dvd.iso \

--ram 1024             \

--cpus 1 \

--disk    /var/lib/libvirt/images/$1.qcow2,size=9,bus=virto \

--name $1 \

--network source=br0,model=virto &

--import &

~

添加权限             

[[email protected] ~]# chmod +x /mnt/vm_snapshot.sh

 

5.保存虚拟机快照

 

 

[[email protected] ~]# cd /var/lib/libvirt/images/

[[email protected] images]# ls

generic.qcow2            rh124-desktop-vdb.qcow2  rh124-server-vdb.ovl    rhel7.1-1.qcow2

rh124-desktop-vda.ovl    rh124-desktop.xml        rh124-server-vdb.qcow2  rhel7.1.qcow2

rh124-desktop-vda.qcow2  rh124-server-vda.ovl     rh124-server.xml

rh124-desktop-vdb.ovl    rh124-server-vda.qcow2   rhel7.0.qcow2

[[email protected] images]# mv rhel7.0.qcow2 /mnt

 

[[email protected] qemu]# mv rhel7.0.xml /mnt

[[email protected] qemu]# cd /mnt

[[email protected] mnt]# ls

rhel7.0.qcow2  rhel7.0.xml  vm_creat.sh

 

rhel7.0.qcow2  rhel7.0.xml可以利用这两个文件对虚拟机进行还原

 

 

#######相关命令#########

virsh list                  ##虚拟机列表

virsh start desktop         ##打开虚拟机

virsh view desktop          ##查看虚拟机

virsh destory desktop       ##关闭虚拟机