[kiosk@foundation42 images]$ su - root 切换超级用户
Password:
Last login: Sat Apr 21 15:25:52 CST 2018 on pts/0
[root@foundation42 ~]# cd /var/lib/l
libvirt/ lldpad/
[root@foundation42 ~]# cd /var/lib/libvirt/
[root@foundation42 libvirt]# ls
boot dnsmasq filesystems images lxc network qemu
[root@foundation42 libvirt]# cd images 进入images目录
[root@foundation42 images]# ls
fly.qcow2 rh124-desktop-vdb.qcow2 rh124-server-vdb.qcow2
node1.qcow2 rh124-desktop.xml rh124-server.xml
rh124-desktop-vda.ovl rh124-server-vda.ovl wesswe.qcow2
rh124-desktop-vda.qcow2 rh124-server-vda.qcow2 wesswes.qcow2
rh124-desktop-vdb.ovl rh124-server-vdb.ovl
[root@foundation42 images]# file node1.qcow2
node1.qcow2: QEMU QCOW Image (v3), has backing file (path fly.qcow2), 9663676416 bytes
qemu-img create -f qcow2 -b fly.qcow2 node1.qcow2 fly.qcow2是源文件
node1.qcow2是新建立的文件
[root@foundation42 images]# qemu-img create -f qcow2 -b fly.qcow2 node1.qcow2
Formatting 'node1.qcow2', fmt=qcow2 size=9663676416 backing_file='fly.qcow2' encryption=off cluster_size=65536 lazy_refcounts=off
-f 指配的类型 -b 备份的文件
html 超文本编辑语言
2.virsh 命令对虚拟机的管理
virsh list --all 查看装的虚拟机
virsh start desktop 查看一个
virsh view desktop 显示出虚拟机
virsh destroy desktop 关闭虚拟机
defined 恢复 关闭后不消失
create 一次性的恢复 关闭后消失
undefine 删除虚拟机
练习
[root@foundation42 qemu]# virt-manager 打开虚拟机管理器
[root@foundation42 qemu]# vim node1.xml 查看存放目录位置
[root@foundation42 qemu]# cd /var/lib/libvirt/
[root@foundation42 libvirt]# cd images/ 移动到文件目录
[root@foundation42 images]# ls
fly.qcow2 rh124-desktop-vdb.ovl rh124-server-vda.qcow2
node1.qcow2 rh124-desktop-vdb.qcow2 rh124-server-vdb.ovl
rh124-desktop-vda.ovl rh124-desktop.xml rh124-server-vdb.qcow2
rh124-desktop-vda.qcow2 rh124-server-vda.ovl rh124-server.xml
[root@foundation42 images]# mv node1.qcow2 /mnt
[root@foundation42 images]# ls
fly.qcow2 rh124-desktop-vdb.qcow2 rh124-server-vdb.ovl
rh124-desktop-vda.ovl rh124-desktop.xml rh124-server-vdb.qcow2
rh124-desktop-vda.qcow2 rh124-server-vda.ovl rh124-server.xml
rh124-desktop-vdb.ovl rh124-server-vda.qcow2
[root@foundation42 images]# cd /etc/lib
libibverbs.d/ libnl/ libreport/ libvirt/
[root@foundation42 images]# cd /etc/libvirt/
[root@foundation42 libvirt]# ls
libvirt.conf lxc.conf qemu qemu-lockd.conf virtlockd.conf
libvirtd.conf nwfilter qemu.conf storage
[root@foundation42 libvirt]# cd qemu
[root@foundation42 qemu]# ls
desktop.xml fly.xml networks node1.xml server.xml
[root@foundation42 qemu]# mv node1.xml /mnt 将两个文件都放到/mnt中
然后删除node1虚拟机
在mnt中查看
[root@foundation42 qemu]# cd /mnt
[root@foundation42 mnt]# ls
fly.sh node1.qcow2 node1.xml
将文件放回
mv node1.qcow2 /var/lib/libvirt/images/
virsh create
virsh create node1.xml
virsh define node1.xml 恢复
virsh undefine node1 删除
制作快照脚本文件
1制作快照
2把快照导入虚拟机中
3启动生成的虚拟机
4.显示打开的虚拟机
cd /mnt
vim vm_sanpshoot.sh
vim下
#!/bin/bash
qemu-img create -f qcow2 -b /var/lib/libvirt/images/$1.qcow2 /var/lib/libvirt/images/$2.qcow2
virt-install \
--name $2 \
--cpus 1 \
--ram 1024 \
--disk /var/lib/libvirt/images/$2.qcow2,bus=virtio \
--import &
保存退出