DOKK / manpages / debian 12 / golang-guestfs-dev / guestfs-golang.3.ja
guestfs-golang(3) Virtualization Support guestfs-golang(3)


guestfs-golang - How to use libguestfs from Go


 import ""
 g, errno := guestfs.Create ()
 if errno != nil {
     panic (fmt.Sprintf ("could not create handle: %s", errno))
 defer g.Close ()
 if err := g.Add_drive ("test.img"); err != nil {
     panic (err)
 if err := g.Launch (); err != nil {
     panic (err)
 if err := g.Shutdown (); err != nil {
     panic (err)


This manual page documents how to call libguestfs from the Go programming language. This page just documents the differences from the C API and gives some examples. If you are not familiar with using libguestfs, you also need to read guestfs(3).


The module is called "guestfs". The full package name to import is "".


Use either "guestfs.Create" or "guestfs.Create_flags" to create the handle. The handle is closed implicitly if it is garbage collected. However it is probably a good idea to close it explicitly, either by calling "g.Close ()" or by deferring the same.


"guestfs.Create" and "guestfs.Create_flags" return a simple *error, which is really just a C "errno" wrapped up in the appropriate golang struct.

All other calls return a *GuestfsError which (if non-nil) is a richer struct that contains the error string from libguestfs, the errno (if available) and the operation which failed. This can also be converted to a string for display.


  • No support for events (see "EVENTS" in guestfs(3)).
  • UUIDs are not returned in structures.

例 1: ディスクイメージの作成


例 2: 仮想マシンのディスクイメージの検査



guestfs(3), guestfs-examples(3), guestfs-erlang(3), guestfs-gobject(3), guestfs-java(3), guestfs-lua(3), guestfs-ocaml(3), guestfs-perl(3), guestfs-python(3), guestfs-recipes(1), guestfs-ruby(3),,


Richard W.M. Jones ("rjones at redhat dot com")

Copyright (C) 2013 Red Hat Inc.

To get a list of bugs against libguestfs, use this link:

To report a new bug against libguestfs, use this link:

When reporting a bug, please supply:

  • The version of libguestfs.
  • Where you got libguestfs (eg. which Linux distro, compiled from source, etc)
  • Describe the bug accurately and give a way to reproduce it.
  • Run libguestfs-test-tool(1) and paste the complete, unedited output into the bug report.
2022-11-28 libguestfs-1.48.6