guestfish修改镜像内容
1、安装guestfish
yum install libguestfs-tools
注意,如果要修改windows镜像需要安装
yum install libguestfs-winsupport
2、修改配置文件:/etc/libvirt/qemu.conf
user = "root" # The group for QEMU processes run by the system instance. It can be # specified in a similar way to user. group = "root"
将user和group前面的#号放开
然后重启:
systemctl start libvirtd
3、修改文件内容
以下示例是将镜像里面的/opt/scalarizr/embedded/lib/python2.7/site-packages/scalarizr-3.3.4-py2.7.egg/scalarizr/storage2/volumes/cinder.py
的233行里面的display_description改成description
guestfish -a redhat6.7-kvm-oracle11g-22disk-pulsar2.2.qcow2 -i sh "sed -i '233s/display_description/description/' /opt/scalarizr/embedded/lib/python2.7/site-packages/scalarizr-3.3.4-py2.7.egg/scalarizr/storage2/volumes/cinder.py"
注意,不使用-i参数的话,需要在交互shell中运行
4、guestfish操作虚拟机内部
查看磁盘空间
[root@cc14 ~]# virt-df -a redhat6.7-kvm-nginx1.8.0-15disk-pulsar2.2.qcow2 Filesystem 1K-blocks Used Available Use% redhat6.7-kvm-nginx1.8.0-15disk-pulsar2.2.qcow2:/dev/sda1 487652 42032 415924 9% redhat6.7-kvm-nginx1.8.0-15disk-pulsar2.2.qcow2:/dev/vg_huacloud/lv_root 13294328 2416692 10179268 19%
查看镜像/root目录内容
[root@cc14 ~]# virt-ls -a redhat6.7-kvm-nginx1.8.0-15disk-pulsar2.2.qcow2 /root .bash_history .bash_logout .bash_profile .bashrc .cshrc .ssh .tcshrc .viminfo anaconda-ks.cfg install.log install.log.syslog
显示指定文件内容
[root@cc14 ~]# virt-cat -a redhat6.7-kvm-nginx1.8.0-15disk-pulsar2.2.qcow2 /root/install.log Installing libgcc-4.4.7-16.el6.x86_64 warning: libgcc-4.4.7-16.el6.x86_64: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
......
拷贝文件到镜像,从镜你拷贝文件出来
[root@cc14 ~]touch aa.txt [root@cc14 ~]# virt-ls -a redhat6.7-kvm-nginx1.8.0-15disk-pulsar2.2.qcow2 /root/ .bash_history .bash_logout .bash_profile .bashrc .cshrc .ssh .tcshrc .viminfo aa.txt anaconda-ks.cfg install.log install.log.syslog
virt-copy-out -a redhat6.7-kvm-nginx1.8.0-15disk-pulsar2.2.qcow2 /root/aa.txt /root/
编辑虚拟机文件:
virt-edit -a redhat6.7-kvm-nginx1.8.0-15disk-pulsar2.2.qcow2 /root/aa.txt
更多guestfish用法可以参考:http://xiaoli110.blog.51cto.com/1724/1568307/