一、安装guestfish套件
yum install libguestfs-tools
支持windows系统镜像
yum install libguestfs-winsupport
二、常用命令
1.virt-inspector 显示os版本、内核、驱动、挂载点、应用等等
virt-inspector centos_40G.qcow2
2.虚拟机分区及文件系统查看主要使用三个命令
virt-list-partitions 列出虚拟机镜像文件分区信息
virt-filesystems 列出虚拟机镜像文件文件系统,分区,块设备,lvm信息
virt-alignment-scan 查看虚拟机镜像分区是否块对齐
3.查看镜像磁盘空间
virt-df -a centos_40G.qcow2
4.镜像内部文件操作
virt-ls -a centos6364.qcow2 /root
virt-cat -a centos6364.qcow2 /root/anaconda-ks.cfg
virt-edit -a centos6364.qcow2 /root/anaconda-ks.cfg
文件拷贝进镜像及拷贝出镜像
touch test.txt
virt-copy-in test.txt -a centos6364.qcow2 /root/
virt-copy-out -a centos6364.qcow2 /root/test.txt /home
压缩文件拷贝进虚拟机并解压
virt-tar-in -a disk.img data.tar /destination
压缩文件拷贝进虚拟机并解压
virt-tar-out -a disk.img /dir files.tar
将虚拟机的home目录拷贝出来并打包
virt-tar -x domname /home home.tar
上传本地的压缩文件到虚拟机并解压
virt-tar -u domname uploadstuff.tar /tmp
5.扩展分区
新建一个镜像,扩展/dev/sda2分区至最大
qemu-img create -f qcow2 centos_40G.qcow2 40G
virt-resize --expand /dev/sda2 centos.qcow2 centos_40G.qcow2
将boot增加200M,剩下的空间扩充给/dev/sda2
virt-resize --resize /dev/sda1=+200M --expand /dev/sda2 centos.qcow2 centos_40G.qcow2
lv扩展
virt-resize --expand /dev/sda2 --LV-expand /dev/vg_guest/lv_root centos.qcow2 centos_40G.qcow2
扩展分区,并将raw格式转化成qcow2格式
qemu-img create -f qcow2 centos.qcow2 15G
virt-resize --expand /dev/sda2 centos.qcow2 centos_40G.qcow2