[root@localhost ~]# ls /etc/libvirt/qemu c01.xml networks
[root@localhost ~]# virsh list --all Id 名稱 狀態 ---------------------------------------------------- 1 c01 running
[root@localhost ~]# virsh shutdown c01 域 c01 被關閉
[root@localhost ~]# virsh start c01
域 c01 已開始vim
[root@localhost ~]# virsh create /etc/libvirt/qemu/c01.xml #經過配置文件啓動dom
- 掛起、恢復虛擬機
[root@localhost ~]# virsh suspend c01
域 c01 被掛起ide
2 c01 暫停工具
[root@localhost ~]# virsh resume c01
域 c01 被從新恢復性能
2 c01 running加密
- 導出虛擬機配置
[root@localhost ~]# virsh dumpxml c01 > /etc/libvirt/qemu/c02.xml
[root@localhost ~]# ls /etc/libvirt/qemu
c01.xml c02.xml networks命令行
- 虛擬機的刪除與添加
[root@localhost ~]# virsh shutdown c01
[root@localhost ~]# virsh undefine c01
域 c01 已經被取消定義
[root@localhost ~]# ls /etc/libvirt/qemu
c02.xml networkscode
- 經過備份的配置文件從新定義虛擬機
[root@localhost ~]# cd /etc/libvirt/qemu/
[root@localhost qemu]# mv c02.xml c01.xml
[root@localhost qemu]# virsh define c01.xml
[root@localhost qemu]# ls
c01.xml networksorm
- 修改虛擬機配置信息(系統內存大小、磁盤文件等信息)
[root@localhost ~]# vim /etc/libvirt/qemu/c01.xml #直接經過vim命令修改xml
[root@localhost ~]# virsh edit c01 #經過virsh命令修改
### KVM文件管理 經過文件管理能夠直接查看、修改、複製虛擬機的內部文件。虛擬機的磁盤文件有raw與qcow2兩種格式,KVM虛擬機默認使用raw格式,raw格式性能最好、速度快,其肯定是不支持一些新的功能,如鏡像、ZLib磁盤壓縮、AFS加密等。針對兩種格式的文件有不一樣的工具可供選擇。這裏介紹本地YUM安裝libguestfs-tools後產生的命令行工具(這個工具能夠直接讀取qcow2格式的磁盤文件,所以須要將raw格式的磁盤文件轉換成qcow2的格式)。 1.轉換raw格式磁盤文件至qcow2格式 - 查看當前磁盤格式
[root@localhost ~]# qemu-img info /vdir/c01.img
image: /vdir/c01.img
file format: raw
virtual size: 30G (32212254720 bytes)
disk size: 940M
- 關閉虛擬機
[root@localhost ~]# virsh shutdown c01
- 轉換磁盤格式
[root@localhost ~]# qemu-img convert -f raw -O qcow2 /vdir/c01.img /vdir/c01.qcow2
[root@localhost ~]# ls /vdir/c01.qcow2
/vdir/c01.qcow2
2.修改c01的xml配置文件
[root@localhost ~]# virsh edit c01
.....//省略
<disk type='file' device='disk'> #39行
<driver name='qemu' type='qcow2'/> #40行 這裏的type從raw改爲qcow2
<source file='/vdir/c01.qcow2'/> #41行 將源文件類型也要修改
3.經過yum安裝libguestfs-tools後,能夠使用一些命令行工具查看qcow2文件。
[root@localhost vdir]# yum install libguestfd-tools -y
[root@localhost vdir]# virt-cat -a /vdir/c01.qcow2 /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="dhcp"
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="eth0"
DEVICE="eth0"
ONBOOT="yes"
MAC="52:54:00:AE:FC:8A"
4.虛擬機克隆
成功克隆 'c02'。
5.虛擬機快照
[root@localhost vdir]# virsh snapshot-create c01 已生成域快照 1533777836
[root@localhost vdir]# virsh snapshot-current c01 <domainsnapshot> <name>1533777836</name> <state>shutoff</state> <creationTime>1533777836</creationTime> <memory snapshot='no'/> <disks> .....省略
[root@localhost vdir]# virsh snapshot-list c01 名稱 生成時間 狀態 ------------------------------------------------------------ 1533777836 2018-08-09 09:23:56 +0800 shutoff
[root@localhost vdir]# virsh snapshot-revert c01 1533777836