3 <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
4 <title>Short introduction to libguestfs</title>
7 counter-reset: chapter;
10 body > p, body > img, body > pre, body > table {
17 border-bottom: 1px solid rgb(204,0,0);
31 counter-increment: chapter;
32 counter-reset: section;
37 content: counter(chapter) " ... ";
41 background-color: #fcfcfc;
42 border-top: 1px dotted #eee;
43 border-bottom: 1px dotted #eee;
44 border-left: 2px solid rgb(204,0,0);
56 <h1>Short introduction to libguestfs</h1>
57 <author>by Richard W.M. Jones <rjones@redhat.com></author>
61 <p><b>Reuse qemu, Linux kernel and userspace tools</b> to read and
62 write disk images.</p>
64 <img src="overview.svg"/>
66 <h2>The Stable API</h2>
69 /* get the Linux VFS type corresponding to a mounted device */
70 extern char *<b>guestfs_vfs_type</b> (guestfs_h *g, const char *device);
73 <table style="margin-bottom: 4em;" width="100%">
74 <tr><td valign="top">Example using this API:</td><td>
76 #include <guestfs.h>
78 char *fstype = <b>guestfs_vfs_type (g, "/dev/vda1")</b>;
79 printf ("%s\n", fstype);
83 <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>
94 [Device "device"], []),
97 "get the Linux VFS type corresponding to a mounted device",
99 This command gets the filesystem type corresponding to
100 the filesystem on C<device>.
102 For most filesystems, the result is the name of the Linux
103 VFS module which would be used to mount this filesystem
104 if you mounted it without specifying the filesystem type.
105 For example a string such as C<ext3> or C<ntfs>.");
107 <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>
114 <b>do_vfs_type</b> (const char *device)
116 return get_blkid_tag (device, "TYPE");
120 get_blkid_tag (const char *device, const char *tag)
125 r = commandr (&out, &err,
128 "-o", "value", "-s", tag, device, NULL);
129 if (r != 0 && r != 2) {
131 reply_with_error ("%s: %s (blkid returned %d)",
134 reply_with_error ("%s: %s", device, err);
142 return out; /* caller frees */
145 <p class="sourcelnk"><a href="http://git.annexia.org/?p=libguestfs.git;a=blob;f=daemon/blkid.c;hb=HEAD">full source ...</a></p>
152 Just these two fragments generate:
156 <li> bindings in <a href="http://libguestfs.org/guestfs.3.html#api_overview">C</a>,
157 <a href="http://libguestfs.org/guestfs-perl.3.html">Perl</a>,
158 <a href="http://libguestfs.org/guestfs-python.3.html">Python</a>,
159 <a href="http://libguestfs.org/guestfs-ruby.3.html">Ruby</a>,
160 <a href="http://libguestfs.org/guestfs-java.3.html">Java</a>,
161 <a href="http://libguestfs.org/guestfs-ocaml.3.html">OCaml</a>,
164 <a href="http://libguestfs.org/guestfs-erlang.3.html">Erlang</a>
166 <li> <a href="http://libguestfs.org/guestfish.1.html">guestfish</a>
168 <li> documentation in man pages and HTML </li>
169 <li> internal RPC code </li>
172 <h2>Tools written around the API</h2>
174 <img src="tools.svg" />
177 <tr><td valign="top" style="padding-bottom: 1.5em;">
179 <b>guestfish -N fs -m /dev/sda1 <<EOF</b>
180 <font style="color: green;">mkdir /etc
181 upload /etc/resolv.conf /etc/resolv.conf
182 write /etc/hostname "test01.redhat.com"</font>
185 <p class="sourcelnk"><a href="http://libguestfs.org/guestfish.1.html">manual ...</a></p>
186 </td><td valign="top">
188 <b>virt-df -a /dev/vg/F15x32 -h</b>
189 Filesystem Size Used Available Use%
190 F15x32:/dev/sda1 484M 31M 428M 7%
191 F15x32:/dev/vg_f15x32/lv_root 5.5G 3.4G 1.8G 63%
193 <p class="sourcelnk"><a href="http://libguestfs.org/virt-df.1.html">manual ...</a></p>
195 <tr><td valign="top">
197 <b>virt-edit -c qemu:///system -d F15x32 /etc/passwd</b>
198 <i>(launches editor)</i>
200 <p class="sourcelnk"><a href="http://libguestfs.org/virt-edit.1.html">manual ...</a></p>
201 </td><td valign="top">
203 <b>virt-win-reg -c qemu:///system --unsafe-printable-strings \
204 Win7x32 'HKLM\SYSTEM\ControlSet001\Services\Tcpip\Parameters' \
205 | grep DhcpIPAddress</b>
206 "DhcpIPAddress"=str(1):"192.168.122.178"
208 <p class="sourcelnk"><a href="http://libguestfs.org/virt-win-reg.1.html">manual ...</a></p>
215 $ <b>virt-inspector -c qemu:///system -d Win7x32</b>
217 <font style="color: #888;"><?xml version="1.0"?></font>
218 <font style="color: #888;"><operatingsystems></font>
219 <font style="color: #888;"><operatingsystem></font>
220 <font style="color: #888;"><root></font>/dev/sda2<font style="color: #888;"></root></font>
221 <font style="color: #888;"><name></font>windows<font style="color: #888;"></name></font>
222 <font style="color: #888;"><arch></font>i386<font style="color: #888;"></arch></font>
223 <font style="color: #888;"><distro></font>windows<font style="color: #888;"></distro></font>
224 <font style="color: #888;"><product_name></font>Windows 7 Enterprise<font style="color: #888;"></product_name></font>
225 <font style="color: #888;"><product_variant></font>Client<font style="color: #888;"></product_variant></font>
226 <font style="color: #888;"><major_version></font>6<font style="color: #888;"></major_version></font>
227 <font style="color: #888;"><minor_version></font>1<font style="color: #888;"></minor_version></font>
228 <font style="color: #888;"><windows_systemroot></font>/Windows<font style="color: #888;"></windows_systemroot></font>
229 <font style="color: #888;"><windows_current_control_set></font>ControlSet001<font style="color: #888;"></windows_current_control_set></font>
230 <font style="color: #888;"><hostname></font>win7x32<font style="color: #888;"></hostname></font>
233 <p class="sourcelnk"><a href="win7.xml">full XML ...</a></p>
236 <tr><td colspan="2" align="middle">
237 <small><i>Click to enlarge the images</i></small>
240 <a href="virt-manager.png"><img src="virt-manager-t.png"></a>
241 </td><td width="50%" align="middle" valign="top">
242 <a href="vmm-icons.png"><img src="vmm-icons-t.png"></a>
249 char *type, *distro, *product_name;
252 roots = <b>guestfs_inspect_os</b> (g);
257 if (roots[0] == NULL) {
258 fprintf (stderr, "no operating systems found\n");
262 for (i = 0; roots[i] != NULL; ++i) {
263 type = <b>guestfs_inspect_get_type</b> (g, roots[i]);
264 distro = <b>guestfs_inspect_get_distro</b> (g, roots[i]);
265 product_name = <b>guestfs_inspect_get_product_name</b> (g, roots[i]);
266 major = <b>guestfs_inspect_get_major_version</b> (g, roots[i]);
267 minor = <b>guestfs_inspect_get_minor_version</b> (g, roots[i]);
273 " Product name: %s\n\n");
275 type ? : "unknown", distro ? : "unknown", major, minor,
276 product_name ? : "");
286 <p class="sourcelnk"><a href="http://git.annexia.org/?p=libguestfs.git;a=blob;f=rescue/virt-rescue.c;h=0c0036460434f1365d9591d6b2b805d999b07056;hb=HEAD#l351">full source ...</a></p>
291 <h2>V2V & P2V</h2>
296 <h2>Read more ...</h2>
299 <a href="http://libguestfs.org/">libguestfs.org</a> is the
304 <a href="http://libguestfs.org/guestfs.3.html">guestfs(3)</a>
305 is the manual page documenting the C API and the internals.
309 There are manual pages
310 documenting <a href="http://libguestfs.org/guestfish.1.html">guestfish</a>, <a href="http://libguestfs.org/guestmount.1.html">guestmount</a>
311 and each virt tool. See
312 the <a href="http://libguestfs.org/">main website</a> or your
318 <p style="font-size: 70%;">
319 This page © 2011 Red Hat Inc. and distributed
320 under the terms of the GNU General Public License as published by
321 the Free Software Foundation; either version 2 of the License, or
322 (at your option) any later version.