[Libguestfs] How to get information about the guest filesystems by libguestfs
Richard W.M. Jones
rjones at redhat.com
Wed Aug 5 08:05:18 UTC 2009
On Wed, Aug 05, 2009 at 03:30:07PM +0800, Zhang Qian wrote:
> Or I can call guestfs_list_partitions() and guestfs_lvs() to list all
> partitions and logic volumes in guest disk images, and for each of
> them call guestfs_exists() to check if the file I want exist, then
> modify the file.
Right.
Guest filesystem detection is non-trivial with many corner cases,
which is why we didn't write it in C, but wrote a higher level Perl
library to do it:
http://git.et.redhat.com/?p=libguestfs.git;a=blob;f=perl/lib/Sys/Guestfs/Lib.pm;hb=HEAD
However you don't need to use this library, or Perl, directly. You
can use virt-inspector to get an XML representation of the guest and
mountpoints.
http://libguestfs.org/virt-inspector.1.html
The example below is using a CentOS 5.3 virtual machine. Note the
<mountpoints> section in the XML:
$ virt-inspector --xml CentOS5x32.img
<operatingsystems>
<operatingsystem>
<name>linux</name>
<distro>centos</distro>
<arch>i386</arch>
<major_version>5</major_version>
<minor_version>3</minor_version>
<package_format>rpm</package_format>
<package_management>yum</package_management>
<root>/dev/VolGroup00/LogVol00</root>
<mountpoints>
<mountpoint dev="/dev/VolGroup00/LogVol00">/</mountpoint>
<mountpoint dev="/dev/sda1">/boot</mountpoint>
<mountpoint dev="/dev/VolGroup00/LogVol01">swap</mountpoint>
</mountpoints>
<filesystems>
<filesystem dev="/dev/VolGroup00/LogVol00">
<label></label>
<uuid>12f2fd13-ac90-4563-a097-391663a17005</uuid>
<type>ext3</type>
<content>linux-root</content>
<spec>/dev/VolGroup00/LogVol00</spec>
</filesystem>
<filesystem dev="/dev/VolGroup00/LogVol01">
<type>swap</type>
<spec>/dev/VolGroup00/LogVol01</spec>
</filesystem>
<filesystem dev="/dev/sda1">
<label>/boot</label>
<uuid>18962ebf-6b17-4380-a179-48f1f6a7d973</uuid>
<type>ext3</type>
<content>linux-grub</content>
<spec>LABEL=/boot</spec>
</filesystem>
</filesystems>
[lots of other stuff omitted]
Rich.
--
Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones
libguestfs lets you edit virtual machines. Supports shell scripting,
bindings from many languages. http://et.redhat.com/~rjones/libguestfs/
See what it can do: http://et.redhat.com/~rjones/libguestfs/recipes.html
More information about the Libguestfs
mailing list