Ibguestfs is a set of C-language APIs under Linux that are used to access the disk image files of a virtual machine. Its project homepage is http://libguestfs.org/, which contains tools such as Virt-cat, VIRT-DF, Virt-ls, virt-copy-in, Virt-copy-out, Virt-edit, Guestfs, Guestmount, Virt-list-filesystems, virt-list-partitions and other tools, specific usage can also be see the official website. The tool can directly view the content within the guest host without starting the KVM guest host, or it can write files and copy files directly to the IMG image, and it can also support mount operations like Mount.
First, the installation of Libguestfs-tools
[Email protected] ~]# yum-y install Libguestfs-tools
List all command tools
[[email protected] ~]# virt-virt-alignment-scan virt-df virt-inspector virt-make-fs virt-sysprep virt-whatvirt-cat virt-edit virt-inspector2 virt-manager virt-tar virt-win-regvirt-clone Virt-filesystems &nBsp; virt-install virt-pki-validate virt-tar-in virt-xml-validatevirt-convert virt-format virt-list-filesystems virt-rescue virt-tar-out virt-copy-in virt-host-validate virt-list-partitions virt-resize virt-top virt-copy-out &nbsP; virt-image virt-ls virt-sparsify virt-viewer
Virt-ls: You can list files or directories in a directory in a virtual machine
[Email protected] kvm]# virt-ls-d Vm1/etc/.pwd.lockconsolekitdir_colorsdir_colors.256colordir_colors.lightbgcolor
Virt-top: Similar to the top command, except that the process was replaced with a virtual machine
[Email protected] kvm]# Virt-top
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/6C/wKioL1XjyyTSoUDRAADTeQlThFA881.jpg "title=" cc.jpg "alt=" Wkiol1xjyytsoudraadteqlthfa881.jpg "/>
This is all my VMS.
Virt-cat: You can view the contents of a file in a virtual machine
[Email protected] kvm]# virt-cat-d vm1/etc/passwd
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/6F/wKiom1XjyZmSaecFAAG8xwArM6Y631.jpg "title=" cc.jpg "alt=" Wkiom1xjyzmsaecfaag8xwarm6y631.jpg "/>
Virt-edit: You can edit files in a VM
[Email protected] kvm]# virt-edit-d vm1/root/testfile
I'll enter a few "dddddddd" strings here.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/6C/wKioL1Xjz9aymZy1AABuo2eeyY4505.jpg "title=" Qq20150831114430.jpg "alt=" Wkiol1xjz9aymzy1aabuo2eeyy4505.jpg "/>
Virt-copy-in: Copy files to the virtual machine
[Email protected] ~]# virt-copy-in-d vm1 a/opt/
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/71/wKiom1Xj75Kx14NHAACpmW4U-Ow983.jpg "title=" cc.jpg "alt=" Wkiom1xj75kx14nhaacpmw4u-ow983.jpg "/>
you can also operate directly on a virtual machine disk file by simply
-d domname
Replace
-a path_of_disk_file(虚拟机的磁盘文件),上面的操作都可以
Virt-copy-out: You can copy the files from the virtual machine to the local host
[Email protected] ~]# virt-copy-out-d vm1/opt/a/etc/passwd.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/6E/wKioL1Xj8uOxkPupAADXFad0PwE992.jpg "title=" cc.jpg "alt=" Wkiol1xj8uoxkpupaadxfad0pwe992.jpg "/>
Copy-out the two files vm1 the virtual machine
Virt-what
Virt-what can be used to detect whether the current system is not a virtual machine, if it is not a virtual machine, the execution of Virt-what will not have any output, if it is a virtual machine, it will print a series of virtual machine "facts" (such as KVM, Vmwar, Xen, etc.)
[Email protected] ~]# Virt-what
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/6E/wKioL1Xj9PfQczY7AABLVI0cL3U394.jpg "title=" cc.jpg "alt=" Wkiol1xj9pfqczy7aablvi0cl3u394.jpg "/>
Virt-host-validate
This command can be used to detect if the machine is properly configured to run virtualization, and if no parameters are added, it will check all the virtualization drivers it knows, optionally adding qemu
or lxc
restricting
[Email protected] ~]# virt-host-validate
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/72/wKiom1Xj8zHyzIGBAAHRerwOXWE780.jpg "title=" cc.jpg "alt=" Wkiom1xj8zhyzigbaahrerwoxwe780.jpg "/>
VIRT-DF: will be executed in the virtual machine
df
Result output of the command
[Email protected] ~]# virt-df-d VM1
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/70/wKioL1Xj_0Px4eCwAACiMsvZ4xg145.jpg "title=" cc.jpg "alt=" Wkiol1xj_0px4ecwaacimsvz4xg145.jpg "/>
Virt-alignment-scan
The old operating system is installed with an unaligned partition, which can cause some unnecessary I/O, the role of this command is to check whether the problem is not aligned, if present, just warning (warns) you, this tool will not help you solve this problem
[Email protected] ~]# Virt-alignment-scan
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/70/wKioL1XkAJqQiQIoAADgRi_nBU0233.jpg "title=" cc.jpg "alt=" Wkiol1xkajqqiqioaadgri_nbu0233.jpg "/>
Virt-inspector2
This command can display the operating system version and some other information of the virtual machine, contains very much information and is very simple to use
[Email protected] ~]# virt-inspector2-d VM1
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/70/wKioL1XkANyhjVv3AALO19mWTQA871.jpg "title=" cc.jpg "alt=" Wkiol1xkanyhjvv3aalo19mwtqa871.jpg "/>
Virt-resize in front has been tested demo
Virt-resize can adjust the size of the virtual machine disk, adjust or delete any partition
Virt-resize can not adjust the disk in place, should not make disk adjustment to the running virtual machine, in order to ensure consistency, the tuning needs to shut down the virtual machine first
The process of virt-resize adjustment is very slow, it takes about 10 minutes to scale from a 35G disk
Virt-resize adjustment is only related to the size of the start disk, from 35G to 40G and the time it takes to expand to 135G.
If you use the QCOW2 disk format, personal advice to first turn to raw, adjust and then go back, because directly to qcow2 adjustment, compare 35G qcow2 disk image file may only 1G size (LS view), through the virt-resize adjustment will become 35G size ( LS view) (may also be my method is not correct), first turn to raw to adjust the size and then go back to avoid this problem
Virt-install
When installing a virtual machine, it is common
Such as:
[Email protected] ~]# virt-install--name=vm2--ram,--vcpus=1--disk path=/image/vm2.img,size=7,bus=virtio-- Accelerate--cdrom=/iso/rhel6.5/rhel-server-6.5-x86_64-dvd.iso--vnc--vncport=5910--vnclisten=0.0.0.0--network Bridge=br0,model=virtio--noautoconsole
viewing partition information
Virt-filesystems//Virt-list-filesystems
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/72/wKioL1XkCMawrtT7AAFOqwVsMkw714.jpg "title=" cc.jpg "alt=" Wkiol1xkcmawrtt7aafoqwvsmkw714.jpg "/>
This article is from the "Big Wind" blog, please be sure to keep this source http://lansgg.blog.51cto.com/5675165/1691773
KVM (11) Libguestfs Tools