You should usually add at least one disk image, and you may add multiple disk images. Adding it read-write will almost certainly cause disk corruption, but adding it read-only is safe. if it is being used by a virtual machine. (See also "DISK IMAGE FORMATS" below).īe extremely cautious if the disk image is in use, eg. If you use the readonly flag, libguestfs won't modify the file. Or by calling the older function "guestfs_add_drive_ro". You can add a disk read-only using: guestfs_add_drive_opts (g, filename, To add a disk image, allowing writes, and specifying that the format is raw, do: guestfs_add_drive_opts (g, filename, The call you should use in modern code for adding drives is "guestfs_add_drive_opts". Libguestfs lets you do useful things to all of these. The image filename ( "guest.img" in the example above) could be a disk image from a virtual machine, a dd(1) copy of a physical hard disk, an actual block device, or simply an empty file of zeroes that you have created through posix_fallocate(3). See guestfs-examples(3) for fully worked examples. Consult the documentation for each function to find out how to free the return value. The code above does not free(3) the strings and arrays returned from functions. See section "ERROR HANDLING" below for how to handle errors, and consult the documentation for each function call below to see precisely how they return error indications. In general all functions that return integers return -1 on error, and all functions that return pointers return NULL on error. In real code you should check return values carefully for errors. The code above doesn't include any error checking. * Now you can perform filesystem actions on the guest * To access a filesystem in the image, you must mount it. * Or: use inspection (see INSPECTION section below). * Or: ask libguestfs to find filesystems for you: */Ĭhar **filesystems = guestfs_list_filesystems (g) * Either: examine what partitions, LVs etc are available: */Ĭhar **partitions = guestfs_list_partitions (g) You have to do this _after_ adding drives * Most manipulation calls won't work until you've launched * Call guestfs_add_drive additional times if there are The general structure of all libguestfs-using programs looks like this: guestfs_h *g = guestfs_create () By convention we use the single letter g for the name of the handle variable, although of course you can use any name you want. Then you must add at least one disk image to the handle, followed by launching the handle, then performing whatever operations you want, and finally closing the handle. HANDLESīefore you can use libguestfs calls, you have to create a handle. We also try to group API calls together, where that may not be obvious from reading about the individual calls in the main section of this manual. This section provides a gentler overview of the libguestfs API. Security information, including CVEs affecting libguestfs. guestfs-hacking(1)Ĭontribute code to libguestfs. libguestfs-test-tool(1) guestfs-testing(1) For examples in other languages, see "USING LIBGUESTFS WITH OTHER PROGRAMMING LANGUAGES" below. guestfs-examples(3)Įxamples of using the API from C. Other libguestfs manual pages: guestfs-faq(1)įrequently Asked Questions (FAQ). If you are looking for an introduction to libguestfs, see the web site: Įach virt tool has its own man page (for a full list, go to "SEE ALSO" at the end of this file). Libguestfs is a library for accessing and modifying disk images and virtual machines.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |