16.9.3. 运行 virt-inspector
您可以针对任何磁盘镜像或 libvirt 客户机虚拟机运行 virt-inspector,如下例所示:
virt-inspector --xml disk.img > report.xml
如下所示:
virt-inspector --xml GuestName > report.xml
结果为 XML 报告(
report.xml
)。XML 文件的主要组件是一个顶层 < operatingsystems> 元素,它通常包含一个 < Operatingsystem> 元素,如下所示:
<operatingsystems> <operatingsystem> <!-- the type of operating system and Linux distribution --> <name>linux</name> <distro>rhel</distro> <!-- the name, version and architecture --> <product_name>Red Hat Enterprise Linux Server release 6.4 </product_name> <major_version>6</major_version> <minor_version>4</minor_version> <package_format>rpm</package_format> <package_management>yum</package_management> <root>/dev/VolGroup/lv_root</root> <!-- how the filesystems would be mounted when live --> <mountpoints> <mountpoint dev="/dev/VolGroup/lv_root">/</mountpoint> <mountpoint dev="/dev/sda1">/boot</mountpoint> <mountpoint dev="/dev/VolGroup/lv_swap">swap</mountpoint> </mountpoints> < !-- filesystems--> <filesystem dev="/dev/VolGroup/lv_root"> <label></label> <uuid>b24d9161-5613-4ab8-8649-f27a8a8068d3</uuid> <type>ext4</type> <content>linux-root</content> <spec>/dev/mapper/VolGroup-lv_root</spec> </filesystem> <filesystem dev="/dev/VolGroup/lv_swap"> <type>swap</type> <spec>/dev/mapper/VolGroup-lv_swap</spec> </filesystem> <!-- packages installed --> <applications> <application> <name>firefox</name> <version>3.5.5</version> <release>1.fc12</release> </application> </applications> </operatingsystem> </operatingsystems>
处理这些报告最好使用 W3C 标准 XPath 查询来完成。Red Hat Enterprise Linux 6 附带了一个可用于简单实例的命令行程序(xpath);但是,出于长期和高级用途,您应该考虑使用 XPath 库以及您最喜欢的编程语言。
例如,您可以使用以下 XPath 查询列出所有文件系统设备:
virt-inspector --xml GuestName | xpath //filesystem/@dev Found 3 nodes: -- NODE -- dev="/dev/sda1" -- NODE -- dev="/dev/vg_f12x64/lv_root" -- NODE -- dev="/dev/vg_f12x64/lv_swap"
或者使用以下命令列出安装的所有应用程序的名称:
virt-inspector --xml GuestName | xpath //application/name [...long list...]