3 <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
4 <title>Short introduction to libguestfs</title>
7 counter-reset: chapter;
17 border-bottom: 1px solid rgb(204,0,0);
29 background-color: #f3f3f3;
32 counter-increment: chapter;
33 counter-reset: section;
38 content: counter(chapter) " — ";
42 background-color: #fcfcfc;
43 border-top: 1px dotted #888;
44 border-bottom: 1px dotted #888;
45 border-left: 6px solid rgb(204,0,0);
57 <h1>Short introduction to libguestfs</h1>
58 <author>by Richard W.M. Jones <rjones@redhat.com></author>
62 <p><b>Reuse qemu, Linux kernel and userspace tools</b> to read and
63 write disk images.</p>
65 <img src="overview.svg"/>
67 <h2>The Stable API</h2>
70 /* get the Linux VFS type corresponding to a mounted device */
71 extern char *<b>guestfs_vfs_type</b> (guestfs_h *g, const char *device);
74 <table style="margin-bottom: 4em;" width="100%">
75 <tr><td valign="top">Example using this API:</td><td>
77 #include <guestfs.h>
79 char *fstype = <b>guestfs_vfs_type (g, "/dev/vda1")</b>;
80 printf ("%s\n", fstype);
84 <p class="sourcelnk"><a href="http://git.annexia.org/?p=libguestfs.git;a=blob;f=fish/inspect.c;h=2ca54d2296fce5370504c1085cbcd7ac1b51ad3a;hb=HEAD#l208">click to see a real example ...</a></p>
92 <pre style="font-size: 80%;">
95 [Device "device"], []),
98 "get the Linux VFS type corresponding to a mounted device",
100 This command gets the filesystem type corresponding to
101 the filesystem on C<device>.
103 For most filesystems, the result is the name of the Linux
104 VFS module which would be used to mount this filesystem
105 if you mounted it without specifying the filesystem type.
106 For example a string such as C<ext3> or C<ntfs>.");
108 <p class="sourcelnk"><a href="http://git.annexia.org/?p=libguestfs.git;a=blob;f=generator/generator_actions.ml;h=d3fa3e0b939eb047a5ff103a68f09c6898807748;hb=HEAD#l4775">full source ...</a></p>
113 <pre style="font-size: 80%;">
115 <b>do_vfs_type</b> (const char *device)
117 return get_blkid_tag (device, "TYPE");
121 get_blkid_tag (const char *device, const char *tag)
126 r = commandr (&out, &err,
129 "-o", "value", "-s", tag, device, NULL);
130 if (r != 0 && r != 2) {
132 reply_with_error ("%s: %s (blkid returned %d)",
135 reply_with_error ("%s: %s", device, err);
143 return out; /* caller frees */
146 <p class="sourcelnk"><a href="http://git.annexia.org/?p=libguestfs.git;a=blob;f=daemon/blkid.c;hb=HEAD">full source ...</a></p>
153 Just these two fragments generate:
157 <li> bindings in <a href="http://libguestfs.org/guestfs.3.html#api_overview">C</a>,
158 <a href="http://libguestfs.org/guestfs-perl.3.html">Perl</a>,
159 <a href="http://libguestfs.org/guestfs-python.3.html">Python</a>,
160 <a href="http://libguestfs.org/guestfs-ruby.3.html">Ruby</a>,
161 <a href="http://libguestfs.org/guestfs-java.3.html">Java</a>,
162 <a href="http://libguestfs.org/guestfs-ocaml.3.html">OCaml</a>,
165 <a href="http://libguestfs.org/guestfs-erlang.3.html">Erlang</a>
167 <li> <a href="http://libguestfs.org/guestfish.1.html">guestfish</a>
169 <li> documentation in man pages and HTML </li>
170 <li> internal RPC code </li>
173 <h2>Tools written around the API</h2>
175 <img src="tools.svg" />
178 <tr><td valign="top">
180 <b>guestfish -N fs -m /dev/sda1 <<EOF</b>
181 <font style="color: green;">mkdir /etc
182 upload /etc/resolv.conf /etc/resolv.conf
183 write /etc/hostname "test01.redhat.com"</font>
186 <p class="sourcelnk"><a href="http://libguestfs.org/guestfish.1.html">manual ...</a></p>
187 </td><td valign="top">
189 <b>virt-df -a /dev/vg/F15x32 -h</b>
190 Filesystem Size Used Available Use%
191 F15x32:/dev/sda1 484M 31M 428M 7%
192 F15x32:/dev/vg_f15x32/lv_root 5.5G 3.4G 1.8G 63%
194 <p class="sourcelnk"><a href="http://libguestfs.org/virt-df.1.html">manual ...</a></p>
196 <tr><td valign="top">
198 <b>virt-edit -c qemu:///system -d F15x32 /etc/passwd</b>
199 <i>(launches editor)</i>
201 <p class="sourcelnk"><a href="http://libguestfs.org/virt-edit.1.html">manual ...</a></p>
202 </td><td valign="top">
204 <b>virt-win-reg -c qemu:///system --unsafe-printable-strings \
205 Win7x32 'HKLM\SYSTEM\ControlSet001\Services\Tcpip\Parameters' \
206 | grep DhcpIPAddress</b>
207 "DhcpIPAddress"=str(1):"192.168.122.178"
209 <p class="sourcelnk"><a href="http://libguestfs.org/virt-win-reg.1.html">manual ...</a></p>
218 <h2>V2V & P2V</h2>
223 <h2>Read more ...</h2>
226 <a href="http://libguestfs.org/">libguestfs.org</a> is the
231 <a href="http://libguestfs.org/guestfs.3.html">guestfs(3)</a>
232 is the manual page documenting the C API and the internals.
236 There are manual pages
237 documenting <a href="http://libguestfs.org/guestfish.1.html">guestfish</a>, <a href="http://libguestfs.org/guestmount.1.html">guestmount</a>
238 and each virt tool. See
239 the <a href="http://libguestfs.org/">main website</a> or your
245 <p style="font-size: 70%;">
246 This page © 2011 Red Hat Inc. and distributed
247 under the terms of the GNU General Public License as published by
248 the Free Software Foundation; either version 2 of the License, or
249 (at your option) any later version.