Sys::Guestfs(3)

๐Ÿ“ฆ version 1.56.2, in nixos 26.05, nixpkgs unstable

๐Ÿ’– NAME ๐Ÿ’–

Sys::Guestfs - Perl bindings for libguestfs, and yes bestie, this is the Sys::Guestfs(3) manual page โ€” we're getting into it ๐Ÿ’…


โœจ SYNOPSIS โœจ

use Sys::Guestfs;

my $g = Sys::Guestfs->new ();
$g->add_drive_opts ('guest.img', format => 'raw');
$g->launch ();
$g->mount ('/dev/sda1', '/');
$g->touch ('/hello');
$g->shutdown ();
$g->close ();

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

The Sys::Guestfs module is a Perl XS binding to the libguestfs API for examining and modifying virtual machine disk images. Iconic. Obsessed. ๐Ÿ’–

Amongst the things this is good for: making batch configuration changes to guests, getting disk used/free statistics (see also: virt-df), migrating between virtualization systems (see also: virt-p2v), performing partial backups, performing partial guest clones, cloning guests and changing registry/UUID/hostname info, and much else besides. It's giving "swiss army knife but make it filesystems" ๐Ÿ”ฅ

Libguestfs uses Linux kernel and qemu code, and can access any type of guest filesystem that Linux and qemu can, including but not limited to: ext2/3/4, btrfs, FAT and NTFS, LVM, many different disk partition schemes, qcow, qcow2, vmdk.

Libguestfs provides ways to enumerate guest storage (eg. partitions, LVs, what filesystem is in each LV, etc.). It can also run commands in the context of the guest. Also you can access filesystems over FUSE. Slay.


๐Ÿ˜ญ ERRORS ๐Ÿ˜ญ

All errors turn into calls to croak (see Carp(3)). No silent flop era, bestie.

The error string from libguestfs is directly available from $@. Use the last_errno method if you want to get the errno.


๐Ÿ’… METHODS ๐Ÿ’…

๐ŸŽ€ $g = Sys::Guestfs->new ([environment => 0,] [close_on_exit => 0]);

Create a new guestfs handle. Main character energy from the very first line โœจ

If the optional argument environment is false, then the GUESTFS_CREATE_NO_ENVIRONMENT flag is set.

If the optional argument close_on_exit is false, then the GUESTFS_CREATE_NO_CLOSE_ON_EXIT flag is set.

๐ŸŽ€ $g->close ();

Explicitly close the guestfs handle.

Note: You should not usually call this function. The handle will be closed implicitly when its reference count goes to zero (eg. when it goes out of scope or the program ends). This call is only required in some exceptional cases, such as where the program may contain cached references to the handle 'somewhere' and you really have to have the close happen right away. After calling close the program must not call any method (including close) on the handle (but the implicit call to DESTROY that happens when the final reference is cleaned up is OK).

So likeโ€ฆ don't just close it for fun, okay? Read the note. ๐Ÿ™ˆ

  • $Sys::Guestfs::EVENT_CLOSE โ€” See GUESTFS_EVENT_CLOSE in guestfs(3).
  • $Sys::Guestfs::EVENT_SUBPROCESS_QUIT โ€” See GUESTFS_EVENT_SUBPROCESS_QUIT in guestfs(3).
  • $Sys::Guestfs::EVENT_LAUNCH_DONE โ€” See GUESTFS_EVENT_LAUNCH_DONE in guestfs(3).
  • $Sys::Guestfs::EVENT_PROGRESS โ€” See GUESTFS_EVENT_PROGRESS in guestfs(3).
  • $Sys::Guestfs::EVENT_APPLIANCE โ€” See GUESTFS_EVENT_APPLIANCE in guestfs(3).
  • $Sys::Guestfs::EVENT_LIBRARY โ€” See GUESTFS_EVENT_LIBRARY in guestfs(3).
  • $Sys::Guestfs::EVENT_TRACE โ€” See GUESTFS_EVENT_TRACE in guestfs(3).
  • $Sys::Guestfs::EVENT_ENTER โ€” See GUESTFS_EVENT_ENTER in guestfs(3).
  • $Sys::Guestfs::EVENT_LIBVIRT_AUTH โ€” See GUESTFS_EVENT_LIBVIRT_AUTH in guestfs(3).
  • $Sys::Guestfs::EVENT_WARNING โ€” See GUESTFS_EVENT_WARNING in guestfs(3).
  • $Sys::Guestfs::EVENT_ALL โ€” See GUESTFS_EVENT_ALL in guestfs(3).

๐ŸŽ€ $event_handle = $g->set_event_callback (\&cb, $event_bitmask);

Register cb as a callback function for all of the events in $event_bitmask (one or more $Sys::Guestfs::EVENT_* flags logically or'd together).

This function returns an event handle which can be used to delete the callback using delete_event_callback.

The callback function receives 4 parameters:

&cb ($event, $event_handle, $buf, $array)
  • $event โ€” The event which happened (equal to one of $Sys::Guestfs::EVENT_*).
  • $event_handle โ€” The event handle.
  • $buf โ€” For some event types, this is a message buffer (ie. a string).
  • $array โ€” For some event types (notably progress events), this is an array of integers.

You should carefully read the documentation for guestfs_set_event_callback in guestfs(3) before using this function. Fr fr, read it first ๐Ÿซถ

๐ŸŽ€ $g->delete_event_callback ($event_handle);

This removes the callback which was previously registered using set_event_callback. Cleanup queen ๐Ÿ’…

๐ŸŽ€ $str = Sys::Guestfs::event_to_string ($events);

$events is either a single event or a bitmask of events. This returns a printable string, useful for debugging.

Note that this is a class function, not a method. Yes, bestie, class function โ€” not a method ๐Ÿ‘‘

๐ŸŽ€ $errnum = $g->last_errno ();

This returns the last error number (errno) that happened on the handle $g.

If successful, an errno integer not equal to zero is returned.

If no error number is available, this returns 0. See guestfs_last_errno in guestfs(3) for more details of why this can happen.

You can use the standard Perl module Errno(3) to compare the numeric error returned from this call with symbolic errnos:

$g->mkdir ("/foo");
if ($g->last_errno() == Errno::EEXIST()) {
  # mkdir failed because the directory exists already.
}

๐ŸŽ€ $g->acl_delete_def_file ($dir);

This function deletes the default POSIX Access Control List (ACL) attached to directory dir.

This function depends on the feature acl. See also $g->feature-available.

๐ŸŽ€ $acl = $g->acl_get_file ($path, $acltype);

This function returns the POSIX Access Control List (ACL) attached to path. The ACL is returned in "long text form" (see acl(5)).

The acltype parameter may be:

  • "access" โ€” Return the ordinary (access) ACL for any file, directory or other filesystem object.
  • "default" โ€” Return the default ACL. Normally this only makes sense if path is a directory.

This function depends on the feature acl. See also $g->feature-available.

๐ŸŽ€ $g->acl_set_file ($path, $acltype, $acl);

This function sets the POSIX Access Control List (ACL) attached to path.

The acltype parameter may be:

  • "access" โ€” Set the ordinary (access) ACL for any file, directory or other filesystem object.
  • "default" โ€” Set the default ACL. Normally this only makes sense if path is a directory.

The acl parameter is the new ACL in either "long text form" or "short text form" (see acl(5)). The new ACL completely replaces any previous ACL on the file. The ACL must contain the full Unix permissions (eg. u::rwx,g::rx,o::rx).

If you are specifying individual users or groups, then the mask field is also required (eg. m::rwx), followed by the u:ID:... and/or g:ID:... field(s). A full ACL string might therefore look like this:

u::rwx,g::rwx,o::rwx,m::rwx,u:500:rwx,g:500:rwx
\ Unix permissions / \mask/ \      ACL        /

You should use numeric UIDs and GIDs. To map usernames and groupnames to the correct numeric ID in the context of the guest, use the Augeas functions (see $g->aug_init).

This function depends on the feature acl. See also $g->feature-available.

๐ŸŽ€ $g->add_cdrom ($filename);

This function adds a virtual CD-ROM disk image to the guest.

The image is added as read-only drive, so this function is equivalent of $g->add_drive_ro.

This function is deprecated. In new code, use the add_drive_ro call instead.

Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions. So likeโ€ฆ noted, bestie ๐Ÿ’€

๐ŸŽ€ $nrdisks = $g->add_domain ($dom [, libvirturi => $libvirturi] [, readonly => $readonly] [, iface => $iface] [, live => $live] [, allowuuid => $allowuuid] [, readonlydisk => $readonlydisk] [, cachemode => $cachemode] [, discard => $discard] [, copyonread => $copyonread]);

This function adds the disk(s) attached to the named libvirt domain dom. It works by connecting to libvirt, requesting the domain and domain XML from libvirt, parsing it for disks, and calling $g->add_drive_opts on each one.

The number of disks added is returned. This operation is atomic: if an error is returned, then no disks are added. Periodt.

This function does some minimal checks to make sure the libvirt domain is not running (unless readonly is true). In a future version we will try to acquire the libvirt lock on each disk.

Disks must be accessible locally. This often means that adding disks from a remote libvirt connection (see https://libvirt.org/remote.html) will fail unless those disks are accessible via the same device path locally too.

The optional libvirturi parameter sets the libvirt URI (see https://libvirt.org/uri.html). If this is not set then we connect to the default libvirt URI (or one set through an environment variable, see the libvirt documentation for full details).

The optional live flag is ignored in libguestfs โ‰ฅ 1.48.

If the allowuuid flag is true (default is false) then a UUID may be passed instead of the domain name. The dom string is treated as a UUID first and looked up, and if that lookup fails then we treat dom as a name as usual.

The optional readonlydisk parameter controls what we do for disks which are marked <readonly/> in the libvirt XML. Possible values are:

  • readonlydisk = "error"
    • If readonly is false: The whole call is aborted with an error if any disk with the <readonly/> flag is found.
    • If readonly is true: Disks with the <readonly/> flag are added read-only.
  • readonlydisk = "read"
    • If readonly is false: Disks with the <readonly/> flag are added read-only. Other disks are added read/write.
    • If readonly is true: Disks with the <readonly/> flag are added read-only.
  • readonlydisk = "write" (default)
    • If readonly is false: Disks with the <readonly/> flag are added read/write.
    • If readonly is true: Disks with the <readonly/> flag are added read-only.
  • readonlydisk = "ignore"
    • If readonly is true or false: Disks with the <readonly/> flag are skipped.

If present, the value of logical_block_size attribute of <blockio/> tag in libvirt XML will be passed as blocksize parameter to $g->add_drive_opts.

okay so the other optional parameters are passed directly through to $g->add_drive_opts โ€” that's literally the vibe, no cap.


๐Ÿ’พ $g->add_drive

$g->add_drive ($filename [, readonly => $readonly] [, format => $format] [, iface => $iface] [, name => $name] [, label => $label] [, protocol => $protocol] [, server => $server] [, username => $username] [, secret => $secret] [, cachemode => $cachemode] [, discard => $discard] [, copyonread => $copyonread] [, blocksize => $blocksize]);

This function adds a disk image called filename to the handle. filename may be a regular host file or a host device. ๐Ÿซถ

When this function is called before $g->launch (the usual case) then the first time you call this function, the disk appears in the API as /dev/sda, the second time as /dev/sdb, and so on. slay, sequential disks โœจ

You don't necessarily need to be root when using libguestfs. However you obviously do need sufficient permissions to access the filename for whatever operations you want to perform (ie. read access if you just want to read the image or write access if you want to modify the image). permissions check, bestie ๐Ÿ”‘

This call checks that filename exists.

filename may be the special string /dev/null. See "NULL DISKS" in guestfs(3). yes, the void disk, iconic ๐Ÿ’€

The optional arguments are:

  • readonly โ€” If true then the image is treated as read-only. Writes are still allowed, but they are stored in a temporary snapshot overlay which is discarded at the end. The disk that you add is not modified. so your original disk stays untouched, periodt ๐Ÿ’…
  • format โ€” This forces the image format. If you omit this (or use $g->add_drive or $g->add_drive_ro) then the format is automatically detected. Possible formats include raw and qcow2.
Automatic detection of the format opens you up to a potential security hole when dealing with untrusted raw-format images. See CVE-2010-3851 and RHBZ#642934. Specifying the format closes this security hole. do not sleep on this, bestie ๐Ÿ˜ญ
  • iface โ€” This rarely-used option lets you emulate the behaviour of the deprecated $g->add_drive_with_if call (q.v.) rarely used, but it's there
  • name โ€” This field used to be passed as a hint for guest inspection, but it is no longer used. retired field, respect its legacy ๐ŸŽ€
  • label โ€” Give the disk a label. The label should be a unique, short string using only ASCII characters [a-zA-Z]. As well as its usual name in the API (such as /dev/sda), the drive will also be named /dev/disk/guestfs/label. See "DISK LABELS" in guestfs(3). cute little label moment ๐Ÿท๏ธ
  • protocol โ€” The optional protocol argument can be used to select an alternate source protocol. See also: "REMOTE STORAGE" in guestfs(3).
    • protocol = "file" โ€” filename is interpreted as a local file or device. This is the default if the optional protocol parameter is omitted.
    • protocol = "ftp"|"ftps"|"http"|"https" โ€” Connect to a remote FTP or HTTP server. The server parameter must also be supplied - see below. See also: "FTP AND HTTP" in guestfs(3)
    • protocol = "iscsi" โ€” Connect to the iSCSI server. The server parameter must also be supplied - see below. The username parameter may be supplied. See below. The secret parameter may be supplied. See below. See also: "ISCSI" in guestfs(3).
    • protocol = "nbd" โ€” Connect to the Network Block Device server. The server parameter must also be supplied - see below. See also: "NETWORK BLOCK DEVICE" in guestfs(3).
    • protocol = "rbd" โ€” Connect to the Ceph (librbd/RBD) server. The server parameter must also be supplied - see below. The username parameter may be supplied. See below. The secret parameter may be supplied. See below. See also: "CEPH" in guestfs(3).
    • protocol = "ssh" โ€” Connect to the Secure Shell (ssh) server. The server parameter must be supplied. The username parameter may be supplied. See below. See also: "SSH" in guestfs(3).
  • server โ€” For protocols which require access to a remote server, this is a list of server(s).
    • Protocol file โ€” List must be empty or param not used at all
    • Protocol ftp|ftps|http|https โ€” Exactly one
    • Protocol iscsi โ€” Exactly one
    • Protocol nbd โ€” Exactly one
    • Protocol rbd โ€” Zero or more
    • Protocol ssh โ€” Exactly one

Each list element is a string specifying a server. The string must be in one of the following formats:

hostname
hostname:port
tcp:hostname
tcp:hostname:port
unix:/path/to/socket

If the port number is omitted, then the standard port number for the protocol is used (see /etc/services). standard ports, no guessing ๐ŸŒˆ

  • username โ€” For the ftp, ftps, http, https, iscsi, rbd and ssh protocols, this specifies the remote username. If not given, then the local username is used for ssh, and no authentication is attempted for ceph. But note this sometimes may give unexpected results, for example if using the libvirt backend and if the libvirt backend is configured to start the qemu appliance as a special user such as qemu.qemu. If in doubt, specify the remote username you want. when in doubt, spell it out ๐Ÿซก
  • secret โ€” For the rbd protocol only, this specifies the โ€˜secretโ€™ to use when connecting to the remote device. It must be base64 encoded. If not given, then a secret matching the given username will be looked up in the default keychain locations, or if no username is given, then no authentication will be used. base64, always ๐Ÿ”
  • cachemode โ€” Choose whether or not libguestfs will obey sync operations (safe but slow) or not (unsafe but fast). The possible values for this string are:
    • cachemode = "writeback" โ€” This is the default. Write operations in the API do not return until a write(2) call has completed in the host [but note this does not imply that anything gets written to disk]. Sync operations in the API, including implicit syncs caused by filesystem journalling, will not return until an fdatasync(2) call has completed in the host, indicating that data has been committed to disk. safe but slow, the classic tradeoff ๐Ÿข
    • cachemode = "unsafe" โ€” In this mode, there are no guarantees. Libguestfs may cache anything and ignore sync requests. This is suitable only for scratch or temporary disks. no guarantees, bestie โ€” scratch/temp only ๐Ÿ’€
  • discard โ€” Enable or disable discard (a.k.a. trim or unmap) support on this drive. If enabled, operations such as $g->fstrim will be able to discard / make thin / punch holes in the underlying host file or device. Possible discard settings are:
    • discard = "disable" โ€” Disable discard support. This is the default.
    • discard = "enable" โ€” Enable discard support. Fail if discard is not possible.
    • discard = "besteffort" โ€” Enable discard support if possible, but don't fail if it is not supported. Since not all backends and not all underlying systems support discard, this is a good choice if you want to use discard if possible, but don't mind if it doesn't work. best effort energy โœจ
  • copyonread โ€” The boolean parameter copyonread enables copy-on-read support. This only affects disk formats which have backing files, and causes reads to be stored in the overlay layer, speeding up multiple reads of the same area of disk. The default is false. default false, noted ๐Ÿฆ‹
  • blocksize โ€” This parameter sets the sector size of the disk. Possible values are 512 (the default if the parameter is omitted) or 4096. Use 4096 when handling an "Advanced Format" disk that uses 4K sector size (https://en.wikipedia.org/wiki/Advanced_Format). Only a subset of the backends support this parameter (currently only the libvirt and direct backends do). 4K gang, check your backend ๐Ÿ”ฅ

๐Ÿ” $g->add_drive_opts

$g->add_drive_opts ($filename [, readonly => $readonly] [, format => $format] [, iface => $iface] [, name => $name] [, label => $label] [, protocol => $protocol] [, server => $server] [, username => $username] [, secret => $secret] [, cachemode => $cachemode] [, discard => $discard] [, copyonread => $copyonread] [, blocksize => $blocksize]);

This is an alias of add_drive. same energy, different name ๐Ÿ’ซ


๐ŸงŠ $g->add_drive_ro

$g->add_drive_ro ($filename);

This function is the equivalent of calling $g->add_drive_opts with the optional parameter GUESTFS_ADD_DRIVE_OPTS_READONLY set to 1, so the disk is added read-only, with the format being detected automatically. read-only, auto-detect, slay ๐ŸŽ€


๐ŸงŠ $g->add_drive_ro_with_if

$g->add_drive_ro_with_if ($filename, $iface);

This is the same as $g->add_drive_ro but it allows you to specify the QEMU interface emulation to use at run time. Both the direct and the libvirt backends ignore iface. they literally ignore it, bestie ๐Ÿ™ˆ

This function is deprecated. In new code, use the add_drive call instead. Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions. use the new call, please ๐Ÿ’…

๐Ÿงฝ $g->add_drive_scratch

$g->add_drive_scratch ($size [, name => $name] [, label => $label] [, blocksize => $blocksize]);

This command adds a temporary scratch drive to the handle. The size parameter is the virtual size (in bytes). The scratch drive is blank initially (all reads return zeroes until you start writing to it). The drive is deleted when the handle is closed. temporary queen, gone when you're done ๐Ÿซถ

The optional arguments name, label and blocksize are passed through to $g->add_drive_opts. passed straight through, no cap โœจ


๐ŸงŠ $g->add_drive_with_if

$g->add_drive_with_if ($filename, $iface);

This is the same as $g->add_drive but it allows you to specify the QEMU interface emulation to use at run time. Both the direct and the libvirt backends ignore iface. again, ignored โ€” it's giving legacy ๐Ÿฆ‹

This function is deprecated. In new code, use the add_drive call instead. Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions. seriously, use add_drive ๐Ÿ˜ญ
  • $nrdisks = $g->add_libvirt_dom ($dom [, readonly => $readonly] [, iface => $iface] [, live => $live] [, readonlydisk => $readonlydisk] [, cachemode => $cachemode] [, discard => $discard] [, copyonread => $copyonread]); โ€” okay so this one adds the disk(s) attached to the libvirt domain dom. How does it werk? It asks libvirt for the domain XML, parses it looking for disks, and calls $g->add_drive_opts on each one. iconic behavior honestly.

Heads up, in the C API we declare void *dom, but bestie it's really typed virDomainPtr dom. Why the lie? So we don't need <libvirt.h>. we're keeping it low-dependency ๐Ÿ’…

The number of disks added gets returned. And this whole thing is atomic: if an error comes back, then no disks are added. no half-measures, we love that for us.

It does some minimal checks to make sure the libvirt domain isn't running (unless readonly is true). And in a future version we'll try to acquire the libvirt lock on each disk โ€” so like, stay tuned.

Disks must be accessible locally. Which often means adding disks from a remote libvirt connection (see <https://libvirt.org/remote.html>) will straight up fail unless those disks are accessible via the same device path locally too. sad but real ๐Ÿ˜ญ

The optional live flag is ignored in libguestfs โ‰ฅ 1.48. it's giving deprecated energy.

The optional readonlydisk parameter controls what we do for disks marked <readonly/> in the libvirt XML. peep $g->add_domain for the possible values.

If present, the value of the logical_block_size attribute of the <blockio/> tag in libvirt XML gets passed as the blocksize parameter to $g->add_drive_opts. โœจ

The other optional parameters are passed directly through to $g->add_drive_opts. slay.

  • $g->aug_clear ($augpath); โ€” sets the value associated with path to NULL. literally the same as the clear command in augtool(1). ๐ŸŽ€
  • $g->aug_close (); โ€” closes the current Augeas handle and frees up any resources it was using. after you call this you have to call $g->aug_init again before you can use any other Augeas functions. no shortcuts bestie.
  • %nrnodescreated = $g->aug_defnode ($name, $expr, $val); โ€” defines a variable name whose value is the result of evaluating expr.

If expr evaluates to an empty nodeset, a node is created, which is equivalent to calling $g->aug_set expr, val. name will be the nodeset containing that single node.

On success this returns a pair: the number of nodes in the nodeset, plus a boolean flag telling you if a node was created. two-for-one ๐Ÿซถ

  • $nrnodes = $g->aug_defvar ($name, $expr); โ€” defines an Augeas variable name whose value is the result of evaluating expr. If expr is NULL, then name is undefined.

On success it returns the number of nodes in expr, or 0 if expr evaluates to something that isn't a nodeset.

  • $val = $g->aug_get ($augpath); โ€” looks up the value associated with path. If path matches exactly one node, the value is returned. one node only, no polyamory โœจ
  • $g->aug_init ($root, $flags); โ€” creates a new Augeas handle for editing config files. If there was any previous Augeas handle chillin' with this guestfs session, it gets closed. out with the old.

You must call this before using any other $g->aug_* commands. mandatory.

root is the filesystem root. root must not be NULL โ€” use / instead.

The flags are the same as the flags defined in <augeas.h>, the logical OR of these integers:

  • AUG_SAVE_BACKUP = 1 โ€” keeps the original file with a .augsave extension.
  • AUG_SAVE_NEWFILE = 2 โ€” saves changes into a file with the extension .augnew, and does not overwrite the original. Overrides AUG_SAVE_BACKUP.
  • AUG_TYPE_CHECK = 4 โ€” typecheck lenses.

This option is only useful when debugging Augeas lenses. Using it may require additional memory for the libguestfs appliance. You may need to set the LIBGUESTFS_MEMSIZE environment variable or call $g->set_memsize. memory's expensive bestie ๐Ÿ’€

  • AUG_NO_STDINC = 8 โ€” do not use the standard load path for modules.
  • AUG_SAVE_NOOP = 16 โ€” makes save a no-op, just records what would have been changed. fake it till you make it.
  • AUG_NO_LOAD = 32 โ€” do not load the tree in $g->aug_init.

To close the handle, you can call $g->aug_close.

To find out more about Augeas, peep <http://augeas.net/>. ๐ŸŒ

  • $g->aug_insert ($augpath, $label, $before); โ€” creates a new sibling label for path, inserting it into the tree before or after path (depending on the boolean flag before). choose your fighter.

path must match exactly one existing node in the tree, and label must be a label โ€” aka it must not contain /, "*" or end with a bracketed index [N]. rules are rules.

  • $label = $g->aug_label ($augpath); โ€” returns the label (name of the last element) of the Augeas path expression augpath. augpath must match exactly one node, else this function returns an error. no cap.
  • $g->aug_load (); โ€” loads files into the tree.

See aug_load in the Augeas documentation for the full gory details. it's giving lore.

  • @matches = $g->aug_ls ($augpath); โ€” this is just a shortcut for listing $g->aug_match path/* and sorting the resulting nodes into alphabetical order. convenience queen ๐Ÿ‘‘
  • @matches = $g->aug_match ($augpath); โ€” returns a list of paths that match the path expression path. The returned paths are sufficiently qualified so that they match exactly one node in the current tree. precise and cunty.
  • $g->aug_mv ($src, $dest); โ€” moves the node src to dest. src must match exactly one node. dest gets overwritten if it exists. no warning, no mercy ๐Ÿ˜ญ
  • $nrnodes = $g->aug_rm ($augpath); โ€” removes path and all of its children. the whole bloodline, gone.

On success it returns the number of entries that were removed.

  • $g->aug_save (); โ€” writes all pending changes to disk.

The flags you passed to $g->aug_init affect exactly how files are saved. so like, don't forget what you set ๐Ÿ‘€

  • $g->aug_set ($augpath, $val); โ€” sets the value associated with augpath to val.

In the Augeas API it's possible to clear a node by setting the value to NULL. Due to an oversight in the libguestfs API you cannot do that with this call. Instead you must use the $g->aug_clear call. bug-not-bug, we live ๐Ÿซ 

  • $nodes = $g->aug_setm ($base, $sub, $val); โ€” changes multiple Augeas nodes in a single operation. base is an expression matching multiple nodes. sub is a path expression relative to base. All nodes matching base are found, and then for each node, sub is changed to val. sub may also be NULL, in which case the base nodes are modified.

This returns the number of nodes modified. efficiency ate ๐Ÿ’…

  • $g->aug_transform ($lens, $file [, remove => $remove]); โ€” adds an Augeas transformation for the specified lens so it can handle file.

If remove is true (false by default), then the transformation is removed. toggling like a light switch.

  • $g->available (\@groups); โ€” this command checks the availability of some groups of functionality in the appliance, because not all builds of the libguestfs appliance will be able to provide them. not everyone has everything, and that's okay ๐Ÿฆ‹

The libguestfs groups, and the functions those groups correspond to, are listed in "AVAILABILITY" in guestfs(3). You can also fetch this list at runtime by calling $g->available_all_groups.

The argument groups is a list of group names โ€” eg: ["inotify", "augeas"] would check for the availability of the Linux inotify functions and Augeas (configuration file editing) functions. two birds.

The command returns no error if all requested groups are available.

It fails with an error if one or more of the requested groups is unavailable in the appliance.

If an unknown group name is included in the list of groups, then an error is always returned. no sneaky mystery groups.

Notes, bestie, read these:

  • $g->feature_available is the same as this call, but with a slightly simpler-to-use API: that call returns a boolean true/false instead of throwing an error. less drama.
  • You must call $g->launch before calling this function.

The reason is because we don't know what groups are supported by the appliance/daemon until it's running and can be queried. can't vibe check a daemon that isn't awake yet ๐Ÿ˜ด

  • If a group of functions is available, this does not necessarily mean they will work. You still have to check for errors when calling individual API functions even if they're available. availability โ‰  guarantee, sadly.
  • It's usually the job of distro packagers to build complete functionality into the libguestfs appliance. Upstream libguestfs, if built from source with all requirements satisfied, will support everything. shoutout the packagers ๐Ÿซถ
  • This call was added in version 1.0.80. In previous versions of libguestfs, all you could do was speculatively execute a command to find out if the daemon implemented it. dark times. See also $g->version.

See also $g->filesystem_available. โœจ

  • @groups = $g->available_all_groups (); โ€” returns a list of all optional groups that this daemon knows about. Note this returns both supported and unsupported groups. To find out which ones the daemon can actually support, you have to call $g->available / $g->feature_available on each member of the returned list.

See also $g->available, $g->feature_available and "AVAILABILITY" in guestfs(3). ๐ŸŒˆ

  • $g->base64_in ($base64file, $filename); โ€” uploads base64-encoded data from base64file to filename. in it goes.
  • $g->base64_out ($filename, $base64file); โ€” downloads the contents of filename, writing it out to the local file base64file encoded as base64. out it comes. ๐ŸŽ€
  • $g->blkdiscard ($device); โ€” discards all blocks on the block device device, giving the free space back to the host. giving back to the community, we love a generous queen ๐ŸŒธ

This operation requires support in libguestfs, the host filesystem, qemu and the host kernel. If that support isn't present it may give an error or even appear to run but do nothing. spooky. You must also set the discard attribute on the underlying drive (peep $g->add_drive_opts).

This function depends on the feature "blkdiscard". See also $g->feature-available. ๐Ÿ’œ

  • $zeroes = $g->blkdiscardzeroes ($device); โ€” returns true if blocks on device that have been discarded by a call to $g->blkdiscard are returned as blocks of zero bytes when read the next time. clean slate behavior.

If it returns false, then it may be that discarded blocks are read as stale or random data. ๐Ÿ’€ not the random data.

This function depends on the feature "blkdiscardzeroes". See also $g->feature-available. โœจ

%info = $g->blkid ($device);

okay so this one hands you back block device attributes for device โ€” as a hash, bestie. these fields are usually in there, and yeah there might be extras too:

  • "UUID" โ€” the uuid of this device โœจ
  • "LABEL" โ€” the label of this device ๐Ÿท๏ธ
  • "VERSION" โ€” the version of the blkid command
  • "TYPE" โ€” the filesystem type or RAID of this device
  • "USAGE" โ€” what this device is used for, like "filesystem" or "raid"

$g->blockdev_flushbufs ($device);

tells the kernel to flush the internal buffers hanging out with device. like a little "hey, empty your pockets" moment ๐Ÿ’…

this uses the blockdev(8) command.

$blocksize = $g->blockdev_getbsz ($device);

returns the block size of a device.

heads up: this is not the same as size in blocks, and not the filesystem block size either. also this setting is genuinely not used by anything. you should probably not use it for anything, fr fr. filesystems have their own opinions about which block size to pick.

this uses the blockdev(8) command.

$ro = $g->blockdev_getro ($device);

returns a boolean telling you if the block device is read-only โ€” true if it's read-only, false if it's not ๐Ÿซถ

this uses the blockdev(8) command.

$sizeinbytes = $g->blockdev_getsize64 ($device);

returns the size of the device in bytes ๐Ÿ”ฅ

see also "$g->blockdev_getsz".

this uses the blockdev(8) command.

$sectorsize = $g->blockdev_getss ($device);

returns the size of sectors on a block device. usually 512, but modern devices can be bigger, no cap.

(quick note: this is not the size in sectors โ€” for that you want "$g->blockdev_getsz".)

this uses the blockdev(8) command.

$sizeinsectors = $g->blockdev_getsz ($device);

returns the size of the device counted in units of 512-byte sectors โ€” even if the sectorsize isn't 512 bytes... which is weird, ik ๐Ÿ˜ญ

see also "$g->blockdev_getss" for the real sector size of the device, and "$g->blockdev_getsize64" for the actually-useful size in bytes.

this uses the blockdev(8) command.

$g->blockdev_rereadpt ($device);

rereads the partition table on device. re-read era ๐Ÿ’…

this uses the blockdev(8) command.

$g->blockdev_setbsz ($device, $blocksize);

โš ๏ธ this call does literally nothing and has never done anything, because of a bug in blockdev. do not use it. periodt.

if you actually need to set the filesystem block size, use the "blocksize" option of "$g->mkfs".

this function is deprecated. there is no replacement. consult the API documentation in guestfs(3) for further info.

deprecated functions won't get removed from the API, but the fact that they're deprecated means there are problems with using them correctly โ€” so like, mind the vibe check on that one ๐Ÿšฉ

$g->blockdev_setra ($device, $sectors);

sets readahead (in 512-byte sectors) for the device.

this uses the blockdev(8) command.

$g->blockdev_setro ($device);

sets the block device named device to read-only ๐Ÿ”’

this uses the blockdev(8) command.

$g->blockdev_setrw ($device);

sets the block device named device to read-write โœ๏ธ

this uses the blockdev(8) command.


$g->btrfs_balance_cancel ($path);

cancels a running balance on a btrfs filesystem โœ‹

this function depends on the feature "btrfs". see also "$g->feature-available".

$g->btrfs_balance_pause ($path);

pauses a running balance on a btrfs filesystem โธ๏ธ

this function depends on the feature "btrfs". see also "$g->feature-available".

$g->btrfs_balance_resume ($path);

resumes a paused balance on a btrfs filesystem โ–ถ๏ธ

this function depends on the feature "btrfs". see also "$g->feature-available".

%status = $g->btrfs_balance_status ($path);

shows the status of a running or paused balance on a btrfs filesystem ๐Ÿ‘€

this function depends on the feature "btrfs". see also "$g->feature-available".

$g->btrfs_device_add (\@devices, $fs);

adds the list of device(s) in devices to the btrfs filesystem mounted at fs. if devices is an empty list, this does nothing ๐Ÿซฅ

this function depends on the feature "btrfs". see also "$g->feature-available".

$g->btrfs_device_delete (\@devices, $fs);

removes devices from the btrfs filesystem mounted at fs. if devices is an empty list, this does nothing ๐Ÿซฅ

this function depends on the feature "btrfs". see also "$g->feature-available".

$g->btrfs_filesystem_balance ($fs);

balances the chunks in the btrfs filesystem mounted at fs across the underlying devices โš–๏ธ

this function depends on the feature "btrfs". see also "$g->feature-available".

$g->btrfs_filesystem_defragment ($path [, flush => $flush] [, compress => $compress]);

defragments a file or directory on a btrfs filesystem. compress is one of zlib or lzo ๐Ÿ’…

this function depends on the feature "btrfs". see also "$g->feature-available".

$g->btrfs_filesystem_resize ($mountpoint [, size => $size]);

resizes a btrfs filesystem โœจ

ngl, unlike other resize calls, the filesystem has to be mounted and the parameter is the mountpoint, not the device โ€” that's a requirement of btrfs itself, not us.

the optional parameters are:

  • "size" โ€” the new size (in bytes) of the filesystem. if omitted, the filesystem gets resized to the maximum size.

see also btrfs(8).

this function depends on the feature "btrfs". see also "$g->feature-available".

@devices = $g->btrfs_filesystem_show ($device);

shows all the devices that the filesystem in device is spanned over ๐Ÿฆ‹

if not all the devices for the filesystem are present, then this function fails and "errno" gets set to "ENODEV" ๐Ÿ’€

this function depends on the feature "btrfs". see also "$g->feature-available".

$g->btrfs_filesystem_sync ($fs);

forces a sync on the btrfs filesystem mounted at fs ๐Ÿ”„

this function depends on the feature "btrfs". see also "$g->feature-available".

$g->btrfs_fsck ($device [, superblock => $superblock] [, repair => $repair]);

used to check a btrfs filesystem โ€” device is the device file where the filesystem is stored.

this function depends on the feature "btrfs". see also "$g->feature-available".

this function is deprecated. in new code, use the "btrfs_scrub_full" call instead.

deprecated functions won't get removed from the API, but the fact that they're deprecated means there are problems with using them correctly โ€” so like, use the new one ๐ŸŽ€

$g->btrfs_image (\@source, $image [, compresslevel => $compresslevel]);

this one's for creating an image of a btrfs filesystem. all data gets zeroed, but metadata and the like is preserved ๐Ÿ–ผ๏ธ

this function depends on the feature "btrfs". see also "$g->feature-available".

$g->btrfs_qgroup_assign ($src, $dst, $path);

adds qgroup src to parent qgroup dst. this command can group several qgroups into a parent qgroup so they share a common limit ๐Ÿ‘‘

this function depends on the feature "btrfs". see also "$g->feature-available".

$g->btrfs_qgroup_create ($qgroupid, $subvolume);

creates a quota group (qgroup) for the subvolume at subvolume ๐ŸŒฑ

this function depends on the feature "btrfs". see also "$g->feature-available".

$g->btrfs_qgroup_destroy ($qgroupid, $subvolume);

destroys a quota group ๐Ÿ’ฅ

this function depends on the feature "btrfs". see also "$g->feature-available".

$g->btrfs_qgroup_limit ($subvolume, $size);

limits the size of the subvolume with path subvolume ๐Ÿ“

this function depends on the feature "btrfs". see also "$g->feature-available".

$g->btrfs_qgroup_remove ($src, $dst, $path);

removes qgroup src from the parent qgroup dst โœ‚๏ธ

this function depends on the feature "btrfs". see also "$g->feature-available".

@qgroups = $g->btrfs_qgroup_show ($path);

shows all subvolume quota groups in a btrfs filesystem, including their usages ๐Ÿ‘€

this function depends on the feature "btrfs". see also "$g->feature-available".

$g->btrfs_quota_enable ($fs, $enable);

enables or disables subvolume quota support for the filesystem that contains path ๐ŸŽš๏ธ

this function depends on the feature "btrfs". see also "$g->feature-available".

$g->btrfs_quota_rescan ($fs);

trashes all qgroup numbers and scans the metadata again with the current config ๐Ÿ—‘๏ธ

this function depends on the feature "btrfs". see also "$g->feature-available".

$g->btrfs_replace ($srcdev, $targetdev, $mntpoint);

replaces a device of a btrfs filesystem. on a live filesystem, it duplicates the data onto the target device โ€” the data that's currently stored on the source device. when the operation finishes, the source device gets wiped out and removed from the filesystem ๐Ÿ’…

targetdev needs to be the same size as srcdev, or larger. devices that are currently mounted are never allowed to be used as targetdev ๐Ÿšซ

this function depends on the feature "btrfs". see also "$g->feature-available".

$g->btrfs_rescue_chunk_recover ($device);

recovers the chunk tree of a btrfs filesystem by scanning the devices one by one ๐Ÿฉบ

this function depends on the feature "btrfs". see also "$g->feature-available".

$g->btrfs_rescue_super_recover ($device);

recovers bad superblocks from good copies ๐Ÿ›Ÿ

this function depends on the feature "btrfs". see also "$g->feature-available".

$g->btrfs_scrub_cancel ($path);

cancels a running scrub on a btrfs filesystem โœ‹

this function depends on the feature "btrfs". see also "$g->feature-available".

$g->btrfs_scrub_full ($path [, readonly => $readonly]);

runs a full scrub on a btrfs filesystem and waits for it to finish. if the filesystem has errors, this will return an error ๐Ÿ’€

this function depends on the feature "btrfs". see also "$g->feature-available".

$g->btrfs_scrub_resume ($path);

resumes a previously canceled or interrupted scrub on a btrfs filesystem โ–ถ๏ธ

this function depends on the feature "btrfs". see also "$g->feature-available".

$g->btrfs_scrub_start ($path);

reads all the data and metadata on the filesystem, then uses checksums and the duplicate copies from RAID storage to identify and repair any corrupt data ๐Ÿงš

this function depends on the feature "btrfs". see also "$g->feature-available".

๐ŸŒธ btrfs_scrub_status ๐Ÿ’…

%status = $g->btrfs_scrub_status ($path);

Okay so this one shows the status of a running or already-finished scrub on a btrfs filesystem.

๐Ÿ’– This function depends on the feature "btrfs". See also $g->feature-available.

๐ŸŒธ btrfs_set_seeding ๐ŸŽ€

$g->btrfs_set_seeding ($device, $seeding);

Turns the seeding feature on or off for a device that contains a btrfs filesystem.

๐Ÿ’– This function depends on the feature "btrfs". See also $g->feature-available.

๐ŸŒธ btrfs_subvolume_create ๐Ÿฆ‹

$g->btrfs_subvolume_create ($dest [, qgroupid => $qgroupid]);

Makes a btrfs subvolume. The dest argument is literally the destination directory plus the name of the subvolume, in the form /path/to/dest/name. The optional parameter qgroupid represents the qgroup that the newly created subvolume will be added to.

๐Ÿ’– This function depends on the feature "btrfs". See also $g->feature-available.

๐ŸŒธ btrfs_subvolume_create_opts โœจ

$g->btrfs_subvolume_create_opts ($dest [, qgroupid => $qgroupid]);

This is an alias of btrfs_subvolume_create. Same vibe, different name.


๐ŸŒธ btrfs_subvolume_delete ๐Ÿ’€

$g->btrfs_subvolume_delete ($subvolume);

Deletes the named btrfs subvolume or snapshot. Bye bestie.

๐Ÿ’– This function depends on the feature "btrfs". See also $g->feature-available.

๐ŸŒธ btrfs_subvolume_get_default โญ

$id = $g->btrfs_subvolume_get_default ($fs);

Gets the default subvolume or snapshot of a filesystem mounted at mountpoint.

๐Ÿ’– This function depends on the feature "btrfs". See also $g->feature-available.

๐ŸŒธ btrfs_subvolume_list ๐ŸŽ€

@subvolumes = $g->btrfs_subvolume_list ($fs);

Lists the btrfs snapshots and subvolumes of the btrfs filesystem that is mounted at fs.

๐Ÿ’– This function depends on the feature "btrfs". See also $g->feature-available.

๐ŸŒธ btrfs_subvolume_set_default ๐Ÿ‘‘

$g->btrfs_subvolume_set_default ($id, $fs);

Sets the subvolume of the btrfs filesystem fs that will be mounted by default. Peep $g->btrfs_subvolume_list if you need the list of subvolumes first.

๐Ÿ’– This function depends on the feature "btrfs". See also $g->feature-available.

๐ŸŒธ btrfs_subvolume_show ๐Ÿ”ฅ

%btrfssubvolumeinfo = $g->btrfs_subvolume_show ($subvolume);

Returns detailed information about the subvolume. Itโ€™s giving full lore.

๐Ÿ’– This function depends on the feature "btrfs". See also $g->feature-available.

๐ŸŒธ btrfs_subvolume_snapshot ๐Ÿฆ‹

$g->btrfs_subvolume_snapshot ($source, $dest [, ro => $ro] [, qgroupid
=> $qgroupid]);

Creates a snapshot of the btrfs subvolume source. The dest argument is the destination directory and the name of the snapshot, in the form /path/to/dest/name. By default the newly created snapshot is writable; if the value of the optional parameter ro is true, then a readonly snapshot is created. The optional parameter qgroupid represents the qgroup that the newly created snapshot will be added to.

๐Ÿ’– This function depends on the feature "btrfs". See also $g->feature-available.

๐ŸŒธ btrfs_subvolume_snapshot_opts โœจ

$g->btrfs_subvolume_snapshot_opts ($source, $dest [, ro => $ro] [,
qgroupid => $qgroupid]);

This is an alias of btrfs_subvolume_snapshot. Iconic alias behavior.


๐ŸŒธ btrfstune_enable_extended_inode_refs ๐ŸŒˆ

$g->btrfstune_enable_extended_inode_refs ($device);

This will enable extended inode refs.

๐Ÿ’– This function depends on the feature "btrfs". See also $g->feature-available.

๐ŸŒธ btrfstune_enable_skinny_metadata_extent_refs ๐Ÿงš

$g->btrfstune_enable_skinny_metadata_extent_refs ($device);

This enables skinny metadata extent refs.

๐Ÿ’– This function depends on the feature "btrfs". See also $g->feature-available.

๐ŸŒธ btrfstune_seeding ๐Ÿ’œ

$g->btrfstune_seeding ($device, $seeding);

Enables seeding of a btrfs device. Heads up: this will force a fs readonly so that you can use it to build other filesystems.

๐Ÿ’– This function depends on the feature "btrfs". See also $g->feature-available.

๐ŸŒธ c_pointer ๐Ÿซถ

$ptr = $g->c_pointer ();

In non-C language bindings, this lets you retrieve the underlying C pointer to the handle (ie. $g->h *). The whole point is to let other libraries interwork with libguestfs.


๐ŸŒธ canonical_device_name ๐ŸŽ€

$canonical = $g->canonical_device_name ($device);

This utility function is useful when youโ€™re displaying device names to the user. It takes a bunch of irregular device names and returns them in a consistent format:

  • /dev/hdX, /dev/vdX โ€” these come back as /dev/sdX. Note this works for device names and partition names too. This is approximately the reverse of the algorithm described in "BLOCK DEVICE NAMING" in guestfs(3).
  • /dev/mapper/VG-LV, /dev/dm-N โ€” converted to /dev/VG/LV form using $g->lvm_canonical_lv_name.

Other strings are returned unmodified. No glow-up needed.


๐ŸŒธ cap_get_file โœจ

$cap = $g->cap_get_file ($path);

This function returns the Linux capabilities attached to path. The capabilities set is returned in text form (see cap_to_text(3)).

If no capabilities are attached to a file, an empty string is returned.

๐Ÿ’– This function depends on the feature "linuxcaps". See also $g->feature-available.

๐ŸŒธ cap_set_file ๐Ÿ”ฅ

$g->cap_set_file ($path, $cap);

This function sets the Linux capabilities attached to path. The capabilities set cap should be passed in text form (see cap_from_text(3)).

๐Ÿ’– This function depends on the feature "linuxcaps". See also $g->feature-available.

๐ŸŒธ case_sensitive_path ๐Ÿฆ‹

$rpath = $g->case_sensitive_path ($path);

This can be used to resolve case insensitive paths on a filesystem that is case sensitive. The use case is resolving paths youโ€™ve read from Windows configuration files or the Windows Registry, to the true path.

The command handles a peculiarity of the Linux ntfs-3g filesystem driver (and probably others), which is that although the underlying filesystem is case-insensitive, the driver exports the filesystem to Linux as case-sensitive.

One consequence of this is that special directories such as C:\windows may appear as /WINDOWS or /windows (or other things) depending on the precise details of how they were created. In Windows itself this would not be a problem.

Bug or feature? You decide. See the relevant entry in the ntfs-3g FAQ: https://github.com/tuxera/ntfs-3g/wiki/NTFS-3G-FAQ

$g->case_sensitive_path attempts to resolve the true case of each element in the path. It will return a resolved path if either the full path or its parent directory exists. If the parent directory exists but the full path does not, the case of the parent directory will be correctly resolved, and the remainder appended unmodified. For example, if the file /Windows/System32/netkvm.sys exists:

"$g->case_sensitive_path" ("/windows/system32/netkvm.sys")
    "Windows/System32/netkvm.sys"

"$g->case_sensitive_path" ("/windows/system32/NoSuchFile")
    "Windows/System32/NoSuchFile"

"$g->case_sensitive_path" ("/windows/system33/netkvm.sys")
    ERROR
โš ๏ธ Note: Because of the above behaviour, $g->case_sensitive_path cannot be used to check for the existence of a file.
โš ๏ธ Note: This function does not handle drive names, backslashes etc.

See also $g->realpath.


๐ŸŒธ cat ๐Ÿ“

$content = $g->cat ($path);

Returns the contents of the file named path.

Because, in C, this function returns a char *, there is no way to differentiate between a "\0" character in a file and end of string. To handle binary files, use the $g->read_file or $g->download functions.


๐ŸŒธ checksum ๐Ÿ’…

$checksum = $g->checksum ($csumtype, $path);

This call computes the MD5, SHAx or CRC checksum of the file named path.

The type of checksum to compute is given by the csumtype parameter, which must have one of the following values:

  • crc โ€” compute the cyclic redundancy check (CRC) specified by POSIX for the cksum command.
  • gost, gost12 โ€” compute the checksum using GOST R34.11-94 or GOST R34.11-2012 message digest.
  • md5 โ€” compute the MD5 hash (using the md5sum(1) program).
  • sha1 โ€” compute the SHA1 hash (using the sha1sum(1) program).
  • sha224 โ€” compute the SHA224 hash (using the sha224sum(1) program).
  • sha256 โ€” compute the SHA256 hash (using the sha256sum(1) program).
  • sha384 โ€” compute the SHA384 hash (using the sha384sum(1) program).
  • sha512 โ€” compute the SHA512 hash (using the sha512sum(1) program).

The checksum is returned as a printable string.

To get the checksum for a device, use $g->checksum_device.

To get the checksums for many files, use $g->checksums_out.


๐ŸŒธ checksum_device ๐ŸŽ€

$checksum = $g->checksum_device ($csumtype, $device);

This call computes the MD5, SHAx or CRC checksum of the contents of the device named device. For the types of checksums supported, see the $g->checksum command.


๐ŸŒธ checksums_out ๐ŸŒˆ

$g->checksums_out ($csumtype, $directory, $sumsfile);

This command computes the checksums of all regular files in directory and then emits a list of those checksums to the local output file sumsfile.

This can be used for verifying the integrity of a virtual machine. However, to be properly secure you should pay attention to the output of the checksum command (it uses the ones from GNU coreutils). In particular, when the filename is not printable, coreutils uses a special backslash syntax. For more information, see the GNU coreutils info file.


๐ŸŒธ chmod ๐Ÿงš

$g->chmod ($mode, $path);

Changes the mode (permissions) of path to mode. Only numeric modes are supported.

โš ๏ธ Note: When using this command from guestfish, mode by default would be decimal, unless you prefix it with 0 to get octal, ie. use 0700 not 700.

The mode actually set is affected by the umask.


๐ŸŒธ chown ๐Ÿ‘‘

$g->chown ($owner, $group, $path);

Changes the file owner to owner and group to group.

Only numeric uid and gid are supported. If you want to use names, you will need to locate and parse the password file yourself (Augeas support makes this relatively easy).


๐ŸŒธ clear_backend_setting ๐Ÿ’œ

$count = $g->clear_backend_setting ($name);

If there is a backend setting string matching name or beginning with name=, then that string is removed from the backend settings.

This call returns the number of strings that were removed (which may be 0, 1 or greater than 1).

See "BACKEND" in guestfs(3), "BACKEND SETTINGS" in guestfs(3).


๐ŸŒธ clevis_luks_unlock ๐Ÿ”

$g->clevis_luks_unlock ($device, $mapname);

This command opens a block device that has been encrypted according to the Linux Unified Key Setup (LUKS) standard, using network-bound disk encryption (NBDE).

device is the encrypted block device.

The appliance connects to the Tang servers noted in the tree of Clevis pins that is bound to a keyslot of the LUKS header. ๐ŸŒธ The Clevis pin tree may comprise sss (redundancy) pins as internal nodes (optionally), and tang pins as leaves. tpm2 pins are not supported. The appliance unlocks the encrypted block device by combining responses from the Tang servers with metadata from the LUKS header; there is no key parameter.

This command will fail if networking has not been enabled for the appliance. Refer to $g->set_network. ๐Ÿ˜ญ

The command creates a new block device called /dev/mapper/mapname. Reads and writes to this block device are decrypted from and encrypted to the underlying device respectively. Close the decrypted block device with $g->cryptsetup_close. ๐Ÿ”

mapname cannot be control because that name is reserved by device-mapper. Periodt. ๐Ÿ’…

If this block device contains LVM volume groups, then calling $g->lvm_scan with the activate parameter true will make them visible. ๐Ÿ‘‘

Use $g->list_dm_devices to list all device mapper devices. ๐Ÿงš

This function depends on the feature clevisluks. See also $g->feature-available.


command โ€” run a thing straight from the guest ๐Ÿƒโ€โ™€๏ธโœจ

$output = $g->command (\@arguments);

This call runs a command from the guest filesystem. The filesystem must be mounted, and must contain a compatible operating system (ie. something Linux, with the same or compatible processor architecture). ๐Ÿง

The single parameter is an argv-style list of arguments. The first element is the name of the program to run. Subsequent elements are parameters. The list must be non-empty (ie. must contain a program name). Note that the command runs directly, and is not invoked via the shell (see $g->sh). ๐Ÿ’…

The return value is anything printed to stdout by the command.

If the command returns a non-zero exit status, then this function returns an error message. The error message string is the content of stderr from the command. ๐Ÿ˜ญ

The $PATH environment variable will contain at least /usr/bin and /bin. If you require a program from another location, you should provide the full path in the first parameter. ๐Ÿ“

Shared libraries and data files required by the program must be available on filesystems which are mounted in the correct places. It is the callerโ€™s responsibility to ensure all filesystems that are needed are mounted at the right locations. ๐Ÿซถ

Because of the message protocol, there is a transfer limit of somewhere between 2MB and 4MB. See "PROTOCOL LIMITS" in guestfs(3). ๐Ÿ’€

command_lines โ€” same but line-by-line ๐Ÿงต

@lines = $g->command_lines (\@arguments);

This is the same as $g->command, but splits the result into a list of lines. โœจ

See also: $g->sh_lines

Because of the message protocol, there is a transfer limit of somewhere between 2MB and 4MB. See "PROTOCOL LIMITS" in guestfs(3). ๐Ÿ’€

command_out โ€” stream that output, no cap ๐ŸŒŠ

$g->command_out (\@arguments, $output);

This is the same as $g->command, but streams the output back, handling the case where the output from the command is larger than the protocol limit. ๐ŸŒˆ

See also: $g->sh_out

compress_device_out โ€” squeeze a device into a local file ๐Ÿ—œ๏ธ

$g->compress_device_out ($ctype, $device, $zdevice [, level => $level]);

This command compresses device and writes it out to the local file zdevice. ๐ŸŽ€

The ctype and optional level parameters have the same meaning as in $g->compress_out.

compress_out โ€” squeeze a file into a local file ๐ŸŽ

$g->compress_out ($ctype, $file, $zfile [, level => $level]);

This command compresses file and writes it out to the local file zfile. โœจ

The compression program used is controlled by the ctype parameter. Currently this includes: compress, gzip, bzip2, xz or lzop. Some compression types may not be supported by particular builds of libguestfs, in which case you will get an error containing the substring not supported. ๐Ÿ˜ญ

The optional level parameter controls compression level. The meaning and default for this parameter depends on the compression program being used.

config โ€” hypervisor param era ๐ŸŽ›๏ธ

$g->config ($hvparam, $hvvalue);

This can be used to add arbitrary hypervisor parameters of the form -param value. Actually itโ€™s not quite arbitrary โ€” we prevent you from setting some parameters which would interfere with parameters that we use. ๐Ÿ‘€

The first character of hvparam string must be a - (dash).

hvvalue can be NULL.

copy_attributes โ€” copy the metadata vibes ๐Ÿท๏ธ

$g->copy_attributes ($src, $dest [, all => $all] [, mode => $mode] [, xattributes => $xattributes] [, ownership => $ownership]);

Copy the attributes of a path (which can be a file or a directory) to another path. ๐Ÿซถ

By default no attribute is copied, so make sure to specify any (or all to copy everything). ๐Ÿ’…

The optional arguments specify which attributes can be copied:

  • mode โ€” Copy part of the file mode from source to destination. Only the UNIX permissions and the sticky/setuid/setgid bits can be copied.
  • xattributes โ€” Copy the Linux extended attributes (xattrs) from source to destination. This flag does nothing if the linuxxattrs feature is not available (see $g->feature_available).
  • ownership โ€” Copy the owner uid and the group gid of source to destination.
  • all โ€” Copy all the attributes from source to destination. Enabling it enables all the other flags, if they are not specified already. ๐Ÿ‘‘

copy_device_to_device โ€” the big copy block energy ๐Ÿ“ฆ

$g->copy_device_to_device ($src, $dest [, srcoffset => $srcoffset] [, destoffset => $destoffset] [, size => $size] [, sparse => $sparse] [, append => $append]);

The four calls $g->copy_device_to_device, $g->copy_device_to_file, $g->copy_file_to_device, and $g->copy_file_to_file let you copy from a source (device|file) to a destination (device|file). ๐ŸŒˆ

Partial copies can be made since you can specify optionally the source offset, destination offset and size to copy. These values are all specified in bytes. If not given, the offsets both default to zero, and the size defaults to copying as much as possible until we hit the end of the source. ๐Ÿ“

The source and destination may be the same object. However overlapping regions may not be copied correctly. โš ๏ธ

If the destination is a file, it is created if required. If the destination file is not large enough, it is extended.

If the destination is a file and the append flag is not set, then the destination file is truncated. If the append flag is set, then the copy appends to the destination file. The append flag currently cannot be set for devices.

If the sparse flag is true then the call avoids writing blocks that contain only zeroes, which can help in some situations where the backing disk is thin-provisioned. Note that unless the target is already zeroed, using this option will result in incorrect copying. ๐Ÿ’€

copy_device_to_file โ€” same energy, device to file ๐Ÿงš

$g->copy_device_to_file ($src, $dest [, srcoffset => $srcoffset] [, destoffset => $destoffset] [, size => $size] [, sparse => $sparse] [, append => $append]);

See $g->copy_device_to_device for a general overview of this call. โœจ

copy_file_to_device โ€” file to device, slay ๐Ÿฆ‹

$g->copy_file_to_device ($src, $dest [, srcoffset => $srcoffset] [, destoffset => $destoffset] [, size => $size] [, sparse => $sparse] [, append => $append]);

See $g->copy_device_to_device for a general overview of this call. โœจ

copy_file_to_file โ€” blocks inside files, not file cp ๐Ÿ˜ญ

$g->copy_file_to_file ($src, $dest [, srcoffset => $srcoffset] [, destoffset => $destoffset] [, size => $size] [, sparse => $sparse] [, append => $append]);

See $g->copy_device_to_device for a general overview of this call.

This is not the function you want for copying files. This is for copying blocks within existing files. See $g->cp, $g->cp_a and $g->mv for general file copying and moving functions. ๐Ÿ“

copy_in โ€” drag local stuff into the image ๐ŸŽ’

$g->copy_in ($localpath, $remotedir);

$g->copy_in copies local files or directories recursively into the disk image, placing them in the directory called remotedir (which must exist). ๐Ÿซถ

Wildcards cannot be used. ๐Ÿšซ

copy_out โ€” pull remote stuff out to host ๐ŸŒˆ

$g->copy_out ($remotepath, $localdir);

$g->copy_out copies remote files or directories recursively out of the disk image, placing them on the host disk in a local directory called localdir (which must exist). ๐Ÿ’–

To download to the current directory, use . as in:

C<$g-E<gt>copy_out> /home .

Wildcards cannot be used. ๐Ÿšซ

copy_size โ€” deprecated exact-size copy ๐Ÿ’€

$g->copy_size ($src, $dest, $size);

This command copies exactly size bytes from one source device or file src to another destination device or file dest. ๐Ÿ“

Note this will fail if the source is too short or if the destination is not large enough. ๐Ÿ˜ญ

This function is deprecated. In new code, use the copy_device_to_device call instead. โš ๏ธ

Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions.

cp โ€” classic copy ๐Ÿš

$g->cp ($src, $dest);

This copies a file from src to dest where dest is either a destination filename or destination directory. โœจ

cp_a โ€” archive copy with cp -a ๐Ÿ‘‘

$g->cp_a ($src, $dest);

This copies a file or directory from src to dest recursively using the cp -a command. ๐ŸŽ€

cp_r โ€” recursive copy with cp -rP ๐ŸŒ€

$g->cp_r ($src, $dest);

This copies a file or directory from src to dest recursively using the cp -rP command. ๐ŸŒธ

Most users should use $g->cp_a instead. This command is useful when you don't want to preserve permissions, because the target filesystem does not support it (primarily when writing to DOS FAT filesystems). ๐Ÿ’…

cpio_out โ€” pack a directory into cpio ๐ŸŽ

$g->cpio_out ($directory, $cpiofile [, format => $format]);

This command packs the contents of directory and downloads it to local file cpiofile. ๐Ÿ“ฆ

The optional format parameter can be used to select the format. Only the following formats are currently permitted:

  • newc โ€” New (SVR4) portable format. This format happens to be compatible with the cpio-like format used by the Linux kernel for initramfs. This is the default format. โญ
  • crc โ€” New (SVR4) portable format with a checksum.

cryptsetup_close โ€” close that encrypted mapping ๐Ÿ”

$g->cryptsetup_close ($device);

This closes an encrypted device that was created earlier by $g->cryptsetup_open. The device parameter must be the name of the mapping device (ie. /dev/mapper/mapname) and not the name of the underlying block device. ๐Ÿ’…

This function depends on the feature luks. See also $g->feature-available.

๐ŸŽ€ cryptsetup_open

$g->cryptsetup_open ($device, $key, $mapname [, readonly => $readonly]
[, crypttype => $crypttype] [, cipher => $cipher]);

Okay bestie, this one opens a block device that's been encrypted โ€” think LUKS (Linux Unified Key Setup), Windows BitLocker, or whatever else is out there ๐Ÿ’…

  • device โ€” the encrypted block device or partition itself, the locked-up thing.
  • key โ€” one of the keys tied to that encrypted device. You must supply it, no key no entry, periodt ๐Ÿ”‘

This creates a shiny new block device called /dev/mapper/mapname. Reads and writes to it get decrypted from (and encrypted to) the underlying device respectively. It's giving translator-in-the-middle โœจ

Heads up: mapname cannot be control, because that name is reserved by device-mapper. Don't try it, she's taken ๐Ÿ™…โ€โ™€๏ธ

If the optional crypttype parameter isn't there, libguestfs tries to guess the correct type (like LUKS or BitLocker). But you can override the guess by specifying one of these:

  • luks โ€” a Linux LUKS device.
  • bitlk โ€” a Windows BitLocker device.

The optional readonly flag, if set to true, makes a read-only mapping โ€” look but don't touch, lowkey iconic ๐Ÿฆ‹

The optional cipher parameter lets you specify which cipher to use.

If this block device contains LVM volume groups, then calling $g->lvm_scan with the activate parameter true will make them visible. Use $g->list_dm_devices to list all device mapper devices โ€” collect the whole set ๐Ÿ’–

This function depends on the feature luks. See also $g->feature-available.


๐Ÿซถ dd

$g->dd ($src, $dest);

This command copies from one source device or file src to another destination device or file dest. Normally you'd use this to copy to or from a device or partition โ€” for example, to duplicate a filesystem ๐Ÿ’ซ

If the destination is a device, it must be as large or larger than the source file or device, otherwise the copy will fail. No shrinking allowed, she needs her space fr. Also this command cannot do partial copies (see $g->copy_device_to_device).

๐Ÿซ  This function is deprecated. In new code, use the copy_device_to_device call instead. Deprecated functions will not be removed from the API, but the fact that they're deprecated indicates there are problems with correct use of these functions โ€” so like, proceed with awareness โœจ

๐Ÿฆ‹ device_index

$index = $g->device_index ($device);

Takes a device name (e.g. /dev/sdb) and returns the index of the device in the list of devices.

Index numbers start from 0 โ€” zero-indexed, as the ancestors intended ๐Ÿ™ The named device has to actually exist, for example as a string returned from $g->list_devices.

See also $g->list_devices, $g->part_to_dev, $g->device_name.


๐ŸŒธ device_name

$name = $g->device_name ($index);

The reverse glow-up of the last one ๐Ÿ’… Takes a device index and returns the device name. For example index 0 will return the string /dev/sda.

The drive index must have been added to the handle โ€” she's gotta be in the group chat to get a name, iykyk.

See also $g->list_devices, $g->part_to_dev, $g->device_index.


โญ df

$output = $g->df ();

Runs the df(1) command to report disk space used ๐Ÿ“Š

This command is mostly useful for interactive sessions. It is not intended that you try to parse the output string โ€” that's not the vibe. Use $g->statvfs from programs instead, bestie, trust.


๐ŸŒˆ df_h

$output = $g->df_h ();

Runs the df -h command to report disk space used in human-readable format โ€” the h is for "hello I made it legible" ๐Ÿ’–

Same caveat, no cap: this is mostly useful for interactive sessions, and it is not intended that you try to parse the output string. Use $g->statvfs from programs. Periodt.


๐Ÿ‘‘ disk_create

$g->disk_create ($filename, $format, $size [, backingfile =>
$backingfile] [, backingformat => $backingformat] [, preallocation =>
$preallocation] [, compat => $compat] [, clustersize => $clustersize]);

Create a blank disk image called filename (a host file) with format format (usually raw or qcow2). The size is size bytes. Fresh start, blank slate, main character energy โœจ

If you use the optional backingfile parameter, then a snapshot is created on top of the backing file. In that case, size must be passed as -1. The size of the snapshot is the same as the size of the backing file, discovered automatically โ€” no math required, she handles it ๐Ÿงš You're encouraged to also pass backingformat to describe the format of backingfile.

If filename refers to a block device, then the device is formatted. The size is ignored since block devices have an intrinsic size โ€” she already knows her worth ๐Ÿ’…

The other optional parameters are:

  • preallocation
    • If format is raw, then this can be either off (or sparse) or full to create a sparse or fully allocated file respectively. The default is off.
    • If format is qcow2, then this can be off (or sparse), metadata or full. Preallocating metadata can be faster when doing lots of writes, but uses more space. The default is off.
  • compat
    • qcow2 only: Pass the string 1.1 to use the advanced qcow2 format supported by qemu โ‰ฅ 1.1.
  • clustersize
    • qcow2 only: Change the qcow2 cluster size. The default is 65536 (bytes) and this setting may be any power of two between 512 and 2097152.
๐Ÿ“Œ Note that this call does not add the new disk to the handle. You may need to call $g->add_drive_opts separately. Don't forget, bestie, or you'll be looking around like where's my disk ๐Ÿ˜ญ

๐Ÿ’€ disk_format

$format = $g->disk_format ($filename);

Detects and returns the format of the disk image called filename. filename can also be a host device, etc. If the format of the image couldn't be detected, then unknown is returned โ€” the "idk her" of formats ๐Ÿ™ˆ

โš ๏ธ Note that detecting the disk format can be insecure under some circumstances. See CVE-2010-3851 in guestfs(3). Like, be careful out here.

See also: DISK IMAGE FORMATS in guestfs(3).


๐Ÿ“ disk_has_backing_file

$backingfile = $g->disk_has_backing_file ($filename);

Detects and returns whether the disk image filename has a backing file โ€” does she have lore? a backstory? a source? ๐Ÿ’…

โš ๏ธ Note that detecting disk features can be insecure under some circumstances. See CVE-2010-3851 in guestfs(3).

๐Ÿงš disk_virtual_size

$size = $g->disk_virtual_size ($filename);

Detects and returns the virtual size in bytes of the disk image called filename โ€” her full potential, not just what she's showing on the surface โœจ

โš ๏ธ Note that detecting disk features can be insecure under some circumstances. See CVE-2010-3851 in guestfs(3).

๐Ÿ”ฅ dmesg

$kmsgs = $g->dmesg ();

Returns the kernel messages (dmesg(1) output) from the guest kernel ๐Ÿง  This is sometimes useful for extended debugging of problems โ€” the kernel's diary, basically, and yes it's tea.

Another way to get the exact same information is to enable verbose messages with $g->set_verbose or by setting the environment variable LIBGUESTFS_DEBUG=1 before running the program. Two roads, same destination, slay ๐Ÿ›ฃ๏ธ


๐Ÿ’œ download

$g->download ($remotefilename, $filename);

Download file remotefilename and save it as filename on the local machine ๐Ÿ“ฅ

filename can also be a named pipe โ€” she's flexible like that.

See also $g->upload, $g->cat.


๐ŸŒŸ download_blocks

$g->download_blocks ($device, $start, $stop, $filename [, unallocated =>
$unallocated]);

Downloads the data units from start address start to stop from the disk partition (e.g. /dev/sda1) and saves them as filename on the local machine ๐Ÿ“ฆ

โš ๏ธ Careful bestie: using this API on sparse disk image formats such as QCOW may result in large zero-filled files downloaded on the host. It's giving "why is my disk full" energy ๐Ÿ˜ญ

The size of a data unit varies across filesystem implementations โ€” on NTFS filesystems data units are referred to as clusters, while on ExtX ones they're referred to as fragments. Same idea, different labels, iykyk.

If the optional unallocated flag is true (default is false), only the unallocated blocks will be extracted. This is useful to detect hidden data or to retrieve deleted files whose data units haven't been overwritten yet โ€” forensic queen behavior ๐Ÿ‘‘

This function depends on the feature sleuthkit. See also $g->feature-available.


๐ŸŽ€ download_inode

$g->download_inode ($device, $inode, $filename);

Downloads a file given its inode from the disk partition (e.g. /dev/sda1) and saves it as filename on the local machine ๐Ÿ”

It is not required to mount the disk to run this command. No mounting needed, she works from the shadows โœจ

The command is capable of downloading deleted or inaccessible files โ€” yes, even the ones that thought they got away ๐Ÿ’€

This function depends on the feature sleuthkit. See also $g->feature-available.


๐Ÿฆ‹ download_offset

$g->download_offset ($remotefilename, $filename, $offset, $size);

Downloads file remotefilename and saves it as filename on the local machine ๐Ÿ“ฅ

remotefilename is read for size bytes starting at offset (this region must be within the file or device โ€” no reading past the edge, she's not about that life).

๐Ÿ’ก Note that there is no limit on the amount of data that can be downloaded with this call, unlike with $g->pread, and this call always reads the full amount unless an error occurs. She goes all the way, no crumbs.

See also $g->download, $g->pread.


๐ŸŒธ drop_caches

$g->drop_caches ($whattodrop);

This instructs the guest kernel to drop its page cache, and/or dentries and inode caches ๐Ÿงน The parameter whattodrop tells the kernel what precisely to drop โ€” see <https://linux-mm.org/Drop_Caches>

Setting whattodrop to 3 should drop everything. All of it. Gone. Clean slate, closing all the tabs ๐Ÿ’…

This automatically calls sync(2) before the operation, so that the maximum guest memory is freed. Very responsible of her honestly ๐Ÿซถ


โญ du

$sizekb = $g->du ($path);

Runs the du -s command to estimate file space usage for path ๐Ÿ“Š

path can be a file or a directory. If path is a directory, then the estimate includes the contents of the directory and all subdirectories (recursively) โ€” she counts everyone in the group chat, not just the top-level messages.

The result is the estimated size in kilobytes (i.e. units of 1024 bytes).


๐ŸŒˆ e2fsck

$g->e2fsck ($device [, correct => $correct] [, forceall => $forceall] [,
forceno => $forceno]);

Runs the ext2/ext3 filesystem checker on device ๐Ÿฉบ It can take the following optional arguments:

  • correct โ€” Automatically repair the file system. This option will cause e2fsck to automatically fix any filesystem problems that can be safely fixed without human intervention. This option may not be specified at the same time as the forceall or forceno options.
  • forceall โ€” Assume an answer of 'yes' to all questions; allows e2fsck to be used non-interactively. This option may not be specified at the same time as the correct or forceno options.
  • forceno โ€” Open the filesystem readonly and assume an answer of 'no' to all questions; allows e2fsck to be used non-interactively. This option may not be specified at the same time as the correct or forceall options.
๐Ÿ’€ These three are mutually exclusive, bestie โ€” pick one, you can't have all three, that's not how this works, the drama is unnecessary.

๐Ÿ™ˆ e2fsck_f

$g->e2fsck_f ($device);

Runs e2fsck -p -f device โ€” i.e. runs the ext2/ext3 filesystem checker on device, noninteractively (-p), even if the filesystem appears to be clean (-f) ๐Ÿงผ She checks anyway. Suspicious icon behavior.

๐Ÿซ  This function is deprecated. In new code, use the e2fsck call instead.

Okay so real quick before we move on โ€” one thing about all these deprecated functions, bestie, and this is important:

Deprecated functions will not be removed from the API, but the fact that they are deprecated is basically the API version of "๐Ÿšฉ this works but it's giving bad practice," and it indicates that there are problems with correct use of these functions. So likeโ€ฆ they're not gone, they're just not it. ๐Ÿ’…


$output = $g->echo_daemon (\@words);

This one just concatenates the list of words you pass in, puts single spaces between them, and hands you back the resulting string. That's the whole personality โ€” no notes. โœจ

It's honestly the cutest way to test the connection through to the daemon. Like a little "u up?" text to make sure the daemon's still there. ๐Ÿซถ

See also $g->ping_daemon.


@lines = $g->egrep ($regex, $path);

This calls the external egrep(1) program and returns the matching lines. Classic.

Because of the message protocol, there is a transfer limit of somewhere between 2MB and 4MB. See "PROTOCOL LIMITS" in guestfs(3). (Yeah, the limit is real, plan accordingly ๐Ÿ˜ญ)

This function is deprecated. In new code, use the grep call instead.

Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions.


@lines = $g->egrepi ($regex, $path);

This calls the external egrep -i program and returns the matching lines. Same energy as above, just case-insensitive about it. ๐Ÿ™ˆ

Because of the message protocol, there is a transfer limit of somewhere between 2MB and 4MB. See "PROTOCOL LIMITS" in guestfs(3).

This function is deprecated. In new code, use the grep call instead.

Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions.


$equality = $g->equal ($file1, $file2);

Compares the two files file1 and file2 and returns true if their content is exactly equal, or false otherwise. Literally just "are these the same" and honestly same. ๐Ÿ‘‘

The external cmp(1) program is used for the comparison.


$existsflag = $g->exists ($path);

This returns "true" if and only if there is a file, directory (or anything) with the given path name. Anything. A file, a dir, a weird little guy, whatever โ€” if the name's there, it's true. ๐Ÿ”ฅ

See also $g->is_file, $g->is_dir, $g->stat.


$g->extlinux ($directory);

Install the SYSLINUX bootloader on the device mounted at directory. Unlike $g->syslinux which requires a FAT filesystem, this one can be used on an ext2/3/4 or btrfs filesystem. Glow up fr fr. ๐ŸŒˆ

The directory parameter can be either a mountpoint, or a directory within the mountpoint. Either works, she's flexible.

You also have to mark the partition as "active" ($g->part_set_bootable) and a Master Boot Record must be installed (eg. using $g->pwrite_device) on the first sector of the whole disk. The SYSLINUX package comes with some suitable Master Boot Records. See the extlinux(1) man page for further information.

Additional configuration can be supplied to SYSLINUX by placing a file called extlinux.conf on the filesystem under directory. For further information about the contents of this file, see extlinux(1).

See also $g->syslinux.

This function depends on the feature "extlinux". See also $g->feature-available.


$g->f2fs_expand ($device);

This expands a f2fs filesystem to match the size of the underlying device. She grows. ๐Ÿฆ‹

This function depends on the feature "f2fs". See also $g->feature-available.


$g->fallocate ($path, $len);

This command preallocates a file (containing zero bytes) named "path" of size "len" bytes. If the file exists already, it is overwritten. No warning, no ceremony, just overwritten. ๐Ÿ’€

Do not confuse this with the guestfish-specific "alloc" command which allocates a file in the host and attaches it as a device. Totally different thing, please don't mix them up, i'm begging ๐Ÿ™

This function is deprecated. In new code, use the fallocate64 call instead.

Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions.


$g->fallocate64 ($path, $len);

This command preallocates a file (containing zero bytes) named "path" of size "len" bytes. If the file exists already, it is overwritten. Same deal as before, but 64. 6๏ธโƒฃ4๏ธโƒฃ

Note that this call allocates disk blocks for the file. To create a sparse file use $g->truncate_size instead. Sparse is a whole different vibe, bestie.

The deprecated call $g->fallocate does the same, but owing to an oversight it only allowed 30 bit lengths to be specified, effectively limiting the maximum size of files created through that call to 1GB. Yeah. An oopsie. ๐Ÿ˜ฌ The new one fixed it.

Do not confuse this with the guestfish-specific "alloc" and "sparse" commands which create a file in the host and attach it as a device.


$isavailable = $g->feature_available (\@groups);

This is the same as $g->available, but unlike that call it returns a simple true/false boolean result, instead of throwing an exception if a feature is not found. So she's chill about it, no drama, no exception, just vibes and a boolean. โœจ For other documentation see $g->available.


@lines = $g->fgrep ($pattern, $path);

This calls the external fgrep(1) program and returns the matching lines.

Because of the message protocol, there is a transfer limit of somewhere between 2MB and 4MB. See "PROTOCOL LIMITS" in guestfs(3).

This function is deprecated. In new code, use the grep call instead.

Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions.


@lines = $g->fgrepi ($pattern, $path);

This calls the external fgrep -i program and returns the matching lines. Yes, the -i is doing the case-insensitive thing, you already knew that. ๐ŸŽ€

Because of the message protocol, there is a transfer limit of somewhere between 2MB and 4MB. See "PROTOCOL LIMITS" in guestfs(3).

This function is deprecated. In new code, use the grep call instead.

Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions.


$description = $g->file ($path);

This call uses the standard file(1) command to determine the type or contents of the file. You know, the classic "what even are you" interrogation. ๐Ÿ”

This call will also transparently look inside various types of compressed file. She peeks. respectfully. ๐Ÿ‘€

The filename is not prepended to the output (like the file command -b option). So no path: prefix situation.

The output depends on the output of the underlying file(1) command and it can change in future in ways beyond our control. In other words, the output is not guaranteed by the ABI. So don't be out here parsing it like it's a contract, bestie. ๐Ÿ˜ญ

See also: file(1), $g->vfs_type, $g->lstat, $g->is_file, $g->is_blockdev (etc), $g->is_zero.


$arch = $g->file_architecture ($filename);

This detects the architecture of the binary filename, and returns it if known. Detective mode activated. ๐Ÿ•ต๏ธโ€โ™€๏ธ

Currently defined architectures are:

  • aarch64 โ€” 64 bit ARM.
  • arm โ€” 32 bit ARM.
  • i386 โ€” This string is returned for all 32 bit i386, i486, i586, i686 binaries irrespective of the precise processor requirements of the binary. She does not care about your specific chip, it's all i386 to her.
  • ia64 โ€” Intel Itanium.
  • ppc โ€” 32 bit Power PC.
  • ppc64 โ€” 64 bit Power PC (big endian).
  • ppc64le โ€” 64 bit Power PC (little endian).
  • loongarch64 โ€” 64 bit LoongArch64 (little endian).
  • riscv32, riscv64, riscv128 โ€” RISC-V 32-, 64- or 128-bit variants.
  • s390 โ€” 31 bit IBM S/390.
  • s390x โ€” 64 bit IBM S/390.
  • sparc โ€” 32 bit SPARC.
  • sparc64 โ€” 64 bit SPARC V9 and above.
  • x86_64 โ€” 64 bit x86-64.

Libguestfs may return other architecture strings in future. So like, stay tuned, more icons may drop. โญ

The function works on at least the following types of files:

  • many types of Un*x and Linux binary
  • many types of Un*x and Linux shared library
  • Windows Win32 and Win64 binaries
  • Windows Win32 and Win64 DLLs
    • Win32 binaries and DLLs return "i386".
    • Win64 binaries and DLLs return "x86_64".
  • Linux kernel modules
  • Linux new-style initrd images
  • some non-x86 Linux vmlinuz kernels

What it can't do currently (she's honest about her limits ๐Ÿ’…):

  • static libraries (libfoo.a)
  • Linux old-style initrd as compressed ext2 filesystem (RHEL 3)
  • x86 Linux vmlinuz kernels
    • x86 vmlinuz images (bzImage format) consist of a mix of 16-, 32- and compressed code, and are horribly hard to unpack. If you want to find the architecture of a kernel, use the architecture of the associated initrd or kernel module(s) instead. That's the move. ๐Ÿซถ

$size = $g->filesize ($file);

This command returns the size of file in bytes. Just the number, no frills.

To get other stats about a file, use $g->stat, $g->lstat, $g->is_dir, $g->is_file etc. To get the size of block devices, use $g->blockdev_getsize64. Right tool for the right job, bestie. ๐ŸŽ€


$fsavail = $g->filesystem_available ($filesystem);

Check whether libguestfs supports the named filesystem. The argument "filesystem" is a filesystem name, such as "ext3".

You must call $g->launch before using this command. Non-negotiable, she needs to be booted up first. ๐Ÿš€

This is mainly useful as a negative test. If this returns true, it doesn't mean that a particular filesystem can be created or mounted, since filesystems can fail for other reasons such as it being a later version of the filesystem, or having incompatible features, or lacking the right mkfs.<fs> tool. So true โ‰  "it'll definitely work," it just means "she knows what that is." ๐Ÿ’€

See also $g->available, $g->feature_available, "AVAILABILITY" in guestfs(3).


@dirents = $g->filesystem_walk ($device);

Walk through the internal structures of a disk partition (eg. /dev/sda1) in order to return a list of all the files and directories stored within. Full on little tour of the neighborhood. ๐ŸŒธ

It is not necessary to mount the disk partition to run this command. She reads the structures directly, no mounting required, it's giving raw access energy. โœจ

All entries in the filesystem are returned. This function can list deleted or unaccessible files. The entries are not sorted. So don't come for her about the ordering, it's chaotic on purpose. ๐Ÿ™ˆ

The "tsk_dirent" structure contains the following fields.

  • "tsk_inode" โ€” Filesystem reference number of the node. It might be 0 if the node has been deleted.
  • "tsk_type" โ€” Basic file type information. See below for a detailed list of values.
  • "tsk_size" โ€” File size in bytes. It might be -1 if the node has been deleted.
  • "tsk_name" โ€” The file path relative to its directory.
  • "tsk_flags" โ€” Bitfield containing extra information regarding the entry. It contains the logical OR of the following values:
    • 0x0001 โ€” If set to 1, the file is allocated and visible within the filesystem. Otherwise, the file has been deleted. Under certain circumstances, the function "download_inode" can be used to recover deleted files. ๐Ÿงš
  • 0x0002 โ€” filesystems like NTFS and Ext2-or-greater keep the file name separate from the metadata structure, and this bit flips to 1 when the name is unallocated but the metadata is still allocated ๐Ÿ˜ฌ which basically means the metadata got reallocated to a whole new file. So likeโ€ฆ the file type, file size, timestamps, number of links and symlink target might not match the original deleted entry. Don't trust it blindly, bestie ๐Ÿ’…
  • 0x0004 โ€” set to 1 when the file is compressed using the filesystem's native compression support (NTFS). Lowkey important: the API cannot detect application-level compression. Periodt.
  • tsk_atime_sec
  • tsk_atime_nsec
  • tsk_mtime_sec
  • tsk_mtime_nsec
  • tsk_ctime_sec
  • tsk_ctime_nsec
  • tsk_crtime_sec
  • tsk_crtime_nsec

Respectively: access, modification, last status change and creation time, all in Unix format, in seconds and nanoseconds โœจ

  • tsk_nlink โ€” number of file names pointing to this entry ๐Ÿซถ
  • tsk_link โ€” if the entry is a symbolic link, this field holds the path to the target file ๐Ÿ”—

The tsk_type field will contain one of these characters, and honestly it's giving very demure, very mindful alphabet energy:

  • 'b' โ€” Block special
  • 'c' โ€” Char special
  • 'd' โ€” Directory
  • 'f' โ€” FIFO (named pipe)
  • 'l' โ€” Symbolic link
  • 'r' โ€” Regular file
  • 's' โ€” Socket
  • 'h' โ€” Shadow inode (Solaris)
  • 'w' โ€” Whiteout inode (BSD)
  • 'u' โ€” Unknown file type

This function depends on the feature libtsk. See also $g->feature-available.


๐Ÿ’– $g->fill

$g->fill ($c, $len, $path);

This one creates a brand new file called path, and its initial content is len octets of c โ€” where c must be a number in the range [0..255] ๐ŸŒธ

Okay so real talk: if you wanna fill a file with zero bytes (sparsely), it is much more efficient to use $g->truncate_size instead. And if you want a repeating byte pattern, use $g->fill_pattern. Work smarter, not harder ๐ŸŽ€

๐Ÿฆ‹ $g->fill_dir

$g->fill_dir ($dir, $nr);

This function is useful for testing filesystems โ€” it creates nr empty files in the directory dir, with names 00000000 through nr-1 (ie. each file name is 8 digits long, padded with zeroes). Cute, organised, iconic ๐Ÿ‘‘

๐ŸŒˆ $g->fill_pattern

$g->fill_pattern ($pattern, $len, $path);

Like $g->fill but make it pattern โ€” it creates a new file of length len containing the repeating pattern of bytes in pattern. The pattern gets truncated if necessary so the file length is exactly len bytes. No notes ๐Ÿ’…

โญ $g->find

@names = $g->find ($directory);

This command lists out all files and directories, recursively, starting at directory. It's essentially equivalent to running the shell command find directory -print, except some post-processing happens on the output, described below ๐Ÿ‘‡

It returns a list of strings without any prefix. So if the directory structure was:

 /tmp/a
 /tmp/b
 /tmp/c/d

then the returned list from $g->find /tmp would be 4 elements:

 a
 b
 c
 c/d

If directory is not a directory, then this command returns an error ๐Ÿ˜ญ

The returned list is sorted. Slay.

๐Ÿงš $g->find0

$g->find0 ($directory, $files);

This lists out all files and directories, recursively, starting at directory, and places the resulting list in the external file called files.

It works the same way as $g->find with the following exceptions:

  • The resulting list is written to an external file ๐Ÿ“„
  • Items (filenames) in the result are separated by "\0" characters. See find(1) option -print0 ๐Ÿ’€
  • The result list is not sorted ๐Ÿ™ˆ

๐Ÿ’œ $g->find_inode

@dirents = $g->find_inode ($device, $inode);

Searches all the entries associated with the given inode ๐Ÿ”

For each entry, a tsk_dirent structure is returned. See "filesystem_walk" for more info about tsk_dirent structures.

This function depends on the feature libtsk. See also $g->feature-available.

๐Ÿ“ $g->findfs_label

$device = $g->findfs_label ($label);

Searches the filesystems and returns the one which has the given label ๐Ÿท๏ธ An error is returned if no such filesystem can be found.

To find the label of a filesystem, use $g->vfs_label.

๐ŸŒธ $g->findfs_partlabel

$device = $g->findfs_partlabel ($label);

Searches the partitions and returns the one which has the given label โœจ An error is returned if no such partition can be found.

To find the label of a partition, use $g->blkid ("PART_ENTRY_NAME").

๐ŸŽ€ $g->findfs_partuuid

$device = $g->findfs_partuuid ($uuid);

Searches the partitions and returns the one which has the given partition UUID ๐Ÿ”‘ An error is returned if no such partition can be found.

To find the UUID of a partition, use $g->blkid ("PART_ENTRY_UUID").

๐Ÿ’– $g->findfs_uuid

$device = $g->findfs_uuid ($uuid);

Searches the filesystems and returns the one which has the given UUID ๐Ÿฆ‹ An error is returned if no such filesystem can be found.

To find the UUID of a filesystem, use $g->vfs_uuid.

๐Ÿ”ฅ $g->fsck

$status = $g->fsck ($fstype, $device);

Runs the filesystem checker (fsck) on device, which should have filesystem type fstype ๐Ÿฉบ

The returned integer is the status. See fsck(8) for the list of status codes from fsck.

Notes, bestie, take these in:

  • Multiple status codes can be summed together โž•
  • A non-zero return code can mean "success" โ€” for example if errors have been corrected on the filesystem. The way that flips everything you thought you knew ๐Ÿ˜ญ
  • Checking or repairing NTFS volumes is not supported (by linux-ntfs) ๐Ÿšซ

This command is entirely equivalent to running fsck -a -t fstype device.

๐Ÿ‘‘ $g->fstrim

$g->fstrim ($mountpoint [, offset => $offset] [, length => $length] [, minimumfreeextent => $minimumfreeextent]);

Trim the free space in the filesystem mounted on mountpoint. The filesystem must be mounted read-write โœ๏ธ

The filesystem contents are not affected, but any free space in the filesystem is "trimmed" โ€” that is, given back to the host device โ€” thus making disk images more sparse, allowing unused space in qcow2 files to be reused, etc. So satisfying honestly ๐Ÿงนโœจ

This operation requires support in libguestfs, the mounted filesystem, the host filesystem, qemu and the host kernel. If this support isn't present it may give an error or even appear to run but do nothing ๐Ÿ’€ (rude, but okay)

If the kernel vfs driver doesn't support trimming, this call will fail with errno set to ENOTSUP. Currently this happens when trying to trim FAT filesystems ๐Ÿ™ˆ

See also $g->zero_free_space โ€” that's a slightly different operation that turns free space in the filesystem into zeroes. It is valid to call $g->fstrim either instead of, or after calling $g->zero_free_space ๐Ÿซถ

This function depends on the feature fstrim. See also $g->feature-available.

๐ŸŒˆ $g->get_append

$append = $g->get_append ();

Return the additional kernel options which are added to the libguestfs appliance kernel command line ๐Ÿš€

If "NULL" then no options are added.

๐Ÿ’… $g->get_attach_method

$backend = $g->get_attach_method ();

Return the current backend.

See $g->set_backend and "BACKEND" in guestfs(3).

โš ๏ธ This function is deprecated. In new code, use the "get_backend" call instead.

Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions. So likeโ€ฆ noted ๐Ÿซก

๐ŸŒธ $g->get_autosync

$autosync = $g->get_autosync ();

Get the autosync flag. That's it, that's the whole vibe โœจ

๐Ÿฆ‹ $g->get_backend

$backend = $g->get_backend ();

Return the current backend.

This handle property was previously called the "attach method" ๐Ÿท๏ธ

See $g->set_backend and "BACKEND" in guestfs(3).

๐ŸŽ€ $g->get_backend_setting

$val = $g->get_backend_setting ($name);

Find a backend setting string which is either name or begins with name=. If name, this returns the string "1". If name=, this returns the part after the equals sign (which may be an empty string) ๐Ÿ”

If no such setting is found, this function throws an error. The errno (see $g->last_errno) will be ESRCH in this case ๐Ÿ˜ญ

See "BACKEND" in guestfs(3), "BACKEND SETTINGS" in guestfs(3).

โญ $g->get_backend_settings

@settings = $g->get_backend_settings ();

Return the current backend settings ๐Ÿ“‹

This call returns all backend settings strings. If you want to find a single backend setting, see $g->get_backend_setting.

See "BACKEND" in guestfs(3), "BACKEND SETTINGS" in guestfs(3).

๐Ÿงš $g->get_cachedir

$cachedir = $g->get_cachedir ();

Get the directory used by the handle to store the appliance cache ๐Ÿ“๐Ÿ’–

๐Ÿ’œ $g->get_direct

$direct = $g->get_direct ();

Return the direct appliance mode flag.

โš ๏ธ This function is deprecated. In new code, use the "internal_get_console_socket" call instead.

Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions ๐Ÿ™ˆ

๐Ÿ“ $g->get_e2attrs

$attrs = $g->get_e2attrs ($file);

This returns the file attributes associated with file ๐Ÿท๏ธ

The attributes are a set of bits associated with each inode which affect the behaviour of the file. They're returned as a string of letters (described below). The string may be empty, indicating that no file attributes are set for this file โœจ

These attributes are only present when the file is located on an ext2/3/4 filesystem. Using this call on other filesystem types will result in an error ๐Ÿšซ

The characters (file attributes) in the returned string are currently:

  • 'A' โ€” When the file is accessed, its atime is not modified.
  • 'a' โ€” The file is append-only.
  • 'c' โ€” The file is compressed on-disk.
  • 'D' โ€” (Directories only.) Changes to this directory are written synchronously to disk.
  • 'd' โ€” The file is not a candidate for backup (see dump(8)).
  • 'E' โ€” The file has compression errors.
  • 'e' โ€” The file is using extents.
  • 'h' โ€” The file is storing its blocks in units of the filesystem blocksize instead of sectors.
  • 'I' โ€” (Directories only.) The directory is using hashed trees.
  • 'i' โ€” The file is immutable. It cannot be modified, deleted or renamed. No link can be created to this file. Fr locked down ๐Ÿ”’
  • 'j' โ€” The file is data-journaled.
  • 's' โ€” When the file is deleted, all its blocks will be zeroed.
  • 'S' โ€” Changes to this file are written synchronously to disk.
  • 'T' โ€” (Directories only.) This is a hint to the block allocator that subdirectories contained in this directory should be spread across blocks. If not present, the block allocator will try to group subdirectories together.
  • 't' โ€” For a file, this disables tail-merging. (Not used by upstream implementations of ext2.)
  • 'u' โ€” When the file is deleted, its blocks will be saved, allowing the file to be undeleted.
  • 'X' โ€” The raw contents of the compressed file may be accessed.
  • 'Z' โ€” The compressed file is dirty.

More file attributes may be added to this list later, bestie. Not all file attributes may be set for all kinds of files. For detailed information, consult the chattr(1) man page.

See also "$g->set_e2attrs".

Don't confuse these attributes with extended attributes (see "$g->getxattr"). ๐Ÿ’…


$generation = $g->get_e2generation ($file);

This returns the ext2 file generation of a file. The generation (which used to be called the "version") is a number associated with an inode. This is most commonly used by NFS servers.

The generation is only present when the file is located on an ext2/3/4 filesystem. Using this call on other filesystem types will result in an error. ๐Ÿ˜ญ

See "$g->set_e2generation".

$label = $g->get_e2label ($device);

This returns the ext2/3/4 filesystem label of the filesystem on "device".

โš ๏ธ This function is deprecated. In new code, use the "vfs_label" call instead.

Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions.

$uuid = $g->get_e2uuid ($device);

This returns the ext2/3/4 filesystem UUID of the filesystem on "device".

โš ๏ธ This function is deprecated. In new code, use the "vfs_uuid" call instead.

Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions.

$hv = $g->get_hv ();

Return the current hypervisor binary.

This is always non-NULL. If it wasn't set already, then this will return the default qemu binary name. โœจ

$identifier = $g->get_identifier ();

Get the handle identifier. See "$g->set_identifier".

$challenge = $g->get_libvirt_requested_credential_challenge ($index);

Get the challenge (provided by libvirt) for the "index"'th requested credential. If libvirt did not provide a challenge, this returns the empty string "". ๐Ÿซถ

See "LIBVIRT AUTHENTICATION" in guestfs(3) for documentation and example code.

$defresult = $g->get_libvirt_requested_credential_defresult ($index);

Get the default result (provided by libvirt) for the "index"'th requested credential. If libvirt did not provide a default result, this returns the empty string "". ๐Ÿ’–

See "LIBVIRT AUTHENTICATION" in guestfs(3) for documentation and example code.

$prompt = $g->get_libvirt_requested_credential_prompt ($index);

Get the prompt (provided by libvirt) for the "index"'th requested credential. If libvirt did not provide a prompt, this returns the empty string "". ๐ŸŒธ

See "LIBVIRT AUTHENTICATION" in guestfs(3) for documentation and example code.

@creds = $g->get_libvirt_requested_credentials ();

This should only be called during the event callback for events of type "GUESTFS_EVENT_LIBVIRT_AUTH".

Return the list of credentials requested by libvirt. Possible values are a subset of the strings provided when you called "$g->set_libvirt_supported_credentials".

See "LIBVIRT AUTHENTICATION" in guestfs(3) for documentation and example code.

$memsize = $g->get_memsize ();

This gets the memory size in megabytes allocated to the hypervisor. ๐Ÿง 

If "$g->set_memsize" was not called on this handle, and if "LIBGUESTFS_MEMSIZE" was not set, then this returns the compiled-in default value for memsize.

For more information on the architecture of libguestfs, see guestfs(3).

$network = $g->get_network ();

This returns the enable network flag. ๐ŸŒ

$path = $g->get_path ();

Return the current search path.

This is always non-NULL. If it wasn't set already, then this will return the default path.

$pgroup = $g->get_pgroup ();

This returns the process group flag.

$pid = $g->get_pid ();

Return the process ID of the hypervisor. If there is no hypervisor running, then this will return an error. ๐Ÿ˜ญ

This is an internal call used for debugging and testing.

$program = $g->get_program ();

Get the program name. See "$g->set_program".

$hv = $g->get_qemu ();

Return the current hypervisor binary (usually qemu).

This is always non-NULL. If it wasn't set already, then this will return the default qemu binary name.

โš ๏ธ This function is deprecated. In new code, use the "get_hv" call instead.

Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions.

$recoveryproc = $g->get_recovery_proc ();

Return the recovery process enabled flag.

$selinux = $g->get_selinux ();

This returns the current setting of the selinux flag which is passed to the appliance at boot time. See "$g->set_selinux".

For more information on the architecture of libguestfs, see guestfs(3).

โš ๏ธ This function is deprecated. In new code, use the "selinux_relabel" call instead.

Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions.

$smp = $g->get_smp ();

This returns the number of virtual CPUs assigned to the appliance. ๐Ÿ”ฅ

$sockdir = $g->get_sockdir ();

Get the directory used by the handle to store temporary socket and PID files.

This is different from "$g->get_tmpdir", as we need shorter paths for sockets (due to the limited buffers of filenames for UNIX sockets), and "$g->get_tmpdir" may be too long for them. Furthermore, sockets and PID files must be accessible to such background services started by libguestfs that may not have permission to access the temporary directory returned by "$g->get_tmpdir".

The environment variable "XDG_RUNTIME_DIR" controls the default value: If "XDG_RUNTIME_DIR" is set, then that is the default. Else /tmp is the default. ๐ŸŒˆ

$state = $g->get_state ();

This returns the current state as an opaque integer. This is only useful for printing debug and internal error messages.

For more information on states, see guestfs(3).

$tmpdir = $g->get_tmpdir ();

Get the directory used by the handle to store temporary files.

$trace = $g->get_trace ();

Return the command trace flag.

$mask = $g->get_umask ();

Return the current umask. By default the umask is 022 unless it has been set by calling "$g->umask".

$verbose = $g->get_verbose ();

This returns the verbose messages flag. ๐Ÿ’ฌ

$context = $g->getcon ();

This gets the SELinux security context of the daemon.

See the documentation about SELINUX in guestfs(3), and "$g->setcon".

This function depends on the feature "selinux". See also "$g->feature-available".

โš ๏ธ This function is deprecated. In new code, use the "selinux_relabel" call instead.

Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions.

$xattr = $g->getxattr ($path, $name);

Get a single extended attribute from file "path" named "name". This call follows symlinks. If you want to lookup an extended attribute for the symlink itself, use "$g->lgetxattr".

Normally it is better to get all extended attributes from a file in one go by calling "$g->getxattrs". However some Linux filesystem implementations are buggy and do not provide a way to list out attributes. For these filesystems (notably ntfs-3g) you have to know the names of the extended attributes you want in advance and call this function. ๐Ÿซ 

Extended attribute values are blobs of binary data. If there is no extended attribute named "name", this returns an error.

See also: "$g->getxattrs", "$g->lgetxattr", attr(5).

This function depends on the feature "linuxxattrs". See also "$g->feature-available".

@xattrs = $g->getxattrs ($path);

This call lists the extended attributes of the file or directory "path".

At the system call level, this is a combination of the listxattr(2) and getxattr(2) calls.

See also: "$g->lgetxattrs", attr(5).

This function depends on the feature "linuxxattrs". See also "$g->feature-available".

@paths = $g->glob_expand ($pattern [, directoryslash => $directoryslash]);

This command searches for all the pathnames matching "pattern" according to the wildcard expansion rules used by the shell. ๐Ÿš

If no paths match, then this returns an empty list (note: not an error). Slay.

It is just a wrapper around the C glob(3) function with flags "GLOB_MARK|GLOB_BRACE". See that manual page for more details.

"directoryslash" controls whether use the "GLOB_MARK" flag for glob(3), and it defaults to true. It can be explicitly set as off to return no trailing slashes in filenames of directories.

Notice that there is no equivalent command for expanding a device name (eg. /dev/sd*). Use "$g->list_devices", "$g->list_partitions" etc functions instead.

@paths = $g->glob_expand_opts ($pattern [, directoryslash => $directoryslash]);

This is an alias of "glob_expand". ๐Ÿ’…

@lines = $g->grep ($regex, $path [, extended => $extended] [, fixed => $fixed] [, insensitive => $insensitive] [, compressed => $compressed]);

This calls the external grep(1) program and returns the matching lines. ๐Ÿ”

The optional flags are:

  • "extended" โ€” Use extended regular expressions. This is the same as using the -E flag.
  • "fixed" โ€” Match fixed (don't use regular expressions). This is the same as using the -F flag.
  • "insensitive" โ€” Match case-insensitive. This is the same as using the -i flag.
  • "compressed" โ€” Use zgrep(1) instead of grep(1). This allows the input to be compress- or gzip-compressed.

๐Ÿ’… the rest of the METHODS, bestie, we're still going

grep_opts

@lines = $g->grep_opts ($regex, $path [, extended => $extended] [, fixed => $fixed] [, insensitive => $insensitive] [, compressed => $compressed]);

okay so this one is literally just an alias of "grep". that's it. that's the whole vibe โœจ

grepi

@lines = $g->grepi ($regex, $path);

this one calls the external grep -i program and returns the matching lines ๐ŸŒธ

quick heads up: because of the message protocol, there is a transfer limit of somewhere between 2MB and 4MB. see "PROTOCOL LIMITS" in guestfs(3) ๐Ÿซถ

deprecated alert ๐Ÿšจ this function is deprecated. in new code, use the "grep" call instead.

and like, to be clear: deprecated functions will not be removed from the API โ€” but the fact that they're deprecated indicates that there are problems with correct use of these functions. so, yk, use the new one ๐Ÿ’€

grub_install

$g->grub_install ($root, $device);

this command installs GRUB 1 (the Grand Unified Bootloader) on device, with the root directory being root ๐Ÿ‘‘

Notes, and these matter:

  • there is currently no way in the API to install grub2, which is used by most modern Linux guests. it is possible to run the grub2 command from the guest, although see the caveats in "RUNNING COMMANDS" in guestfs(3).
  • this uses grub-install(8) from the host. unfortunately grub is not always compatible with itself, so this only works in rather narrow circumstances. careful testing with each guest version is advisable ๐Ÿงช
  • if grub-install reports the error "No suitable drive was found in the generated device map." it may be that you need to create a /boot/grub/device.map file first that contains the mapping between grub device names and Linux device names. it is usually sufficient to create a file containing:
 (hd0) /dev/vda

replacing /dev/vda with the name of the installation device.

this function depends on the feature grub. see also $g->feature-available. ๐Ÿ’œ

@lines = $g->head ($path);

returns up to the first 10 lines of a file, as a list of strings ๐ŸŽ€

because of the message protocol, there is a transfer limit of somewhere between 2MB and 4MB. see "PROTOCOL LIMITS" in guestfs(3).

head_n

@lines = $g->head_n ($nrlines, $path);

the mood of this one depends entirely on the sign of nrlines, fr:

  • if nrlines is a positive number โ†’ returns the first nrlines lines of the file path ๐ŸŒฑ
  • if nrlines is a negative number โ†’ returns lines from the file path, excluding the last nrlines lines โœ‚๏ธ
  • if nrlines is zero โ†’ returns an empty list. that's it. nothing. empty. void ๐Ÿ•ณ๏ธ

because of the message protocol, there is a transfer limit of somewhere between 2MB and 4MB. see "PROTOCOL LIMITS" in guestfs(3).

hexdump

$dump = $g->hexdump ($path);

runs hexdump -C on the given path, and the result is the human-readable, canonical hex dump of the file ๐Ÿ”ฅ

because of the message protocol, there is a transfer limit of somewhere between 2MB and 4MB. see "PROTOCOL LIMITS" in guestfs(3).

hivex_close

$g->hivex_close ();

closes the current hivex handle. bye bestie ๐Ÿ‘‹

this is a wrapper around the hivex(3) call of the same name.

this function depends on the feature hivex. see also $g->feature-available.

hivex_commit

$g->hivex_commit ($filename);

commits (writes) changes to the hive ๐Ÿ’พ

if the optional filename parameter is null, then the changes are written back to the same hive that was opened. if this is not null, then they're written to the alternate filename you gave and the original hive is left untouched. slay, nondestructive ๐Ÿฆ‹

this is a wrapper around the hivex(3) call of the same name.

this function depends on the feature hivex. see also $g->feature-available.

hivex_node_add_child

$nodeh = $g->hivex_node_add_child ($parent, $name);

adds a child node to parent named name ๐ŸŒฑ

this is a wrapper around the hivex(3) call of the same name.

this function depends on the feature hivex. see also $g->feature-available.

hivex_node_children

@nodehs = $g->hivex_node_children ($nodeh);

returns the list of nodes which are subkeys of nodeh ๐Ÿ‘‘

this is a wrapper around the hivex(3) call of the same name.

this function depends on the feature hivex. see also $g->feature-available.

hivex_node_delete_child

$g->hivex_node_delete_child ($nodeh);

deletes nodeh, recursively if necessary ๐Ÿ’€ (it said what it said)

this is a wrapper around the hivex(3) call of the same name.

this function depends on the feature hivex. see also $g->feature-available.

hivex_node_get_child

$child = $g->hivex_node_get_child ($nodeh, $name);

returns the child of nodeh with the name name, if it exists. and heads up โ€” this can return 0, meaning the name was not found ๐Ÿ™ˆ

this is a wrapper around the hivex(3) call of the same name.

this function depends on the feature hivex. see also $g->feature-available.

hivex_node_get_value

$valueh = $g->hivex_node_get_value ($nodeh, $key);

returns the value attached to nodeh which has the name key, if it exists. this can return 0, meaning the key was not found ๐Ÿ”

this is a wrapper around the hivex(3) call of the same name.

this function depends on the feature hivex. see also $g->feature-available.

hivex_node_name

$name = $g->hivex_node_name ($nodeh);

returns the name of nodeh ๐Ÿท๏ธ

this is a wrapper around the hivex(3) call of the same name.

this function depends on the feature hivex. see also $g->feature-available.

hivex_node_parent

$parent = $g->hivex_node_parent ($nodeh);

returns the parent node of nodeh ๐Ÿซถ

this is a wrapper around the hivex(3) call of the same name.

this function depends on the feature hivex. see also $g->feature-available.

hivex_node_set_value

$g->hivex_node_set_value ($nodeh, $key, $t, $val);

sets or replaces a single value under the node nodeh. the key is the name, t is the type, and val is the data โœ๏ธ

this is a wrapper around the hivex(3) call of the same name.

this function depends on the feature hivex. see also $g->feature-available.

hivex_node_values

@valuehs = $g->hivex_node_values ($nodeh);

returns the array of (key, datatype, data) tuples attached to nodeh ๐Ÿ“ฆ

this is a wrapper around the hivex(3) call of the same name.

this function depends on the feature hivex. see also $g->feature-available.

hivex_open

$g->hivex_open ($filename [, verbose => $verbose] [, debug => $debug] [, write => $write] [, unsafe => $unsafe]);

opens the Windows Registry hive file named filename ๐ŸชŸ if there was any previous hivex handle associated with this guestfs session, then it gets closed. out with the old, in with the new, periodt โœจ

this is a wrapper around the hivex(3) call of the same name.

this function depends on the feature hivex. see also $g->feature-available.

hivex_root

$nodeh = $g->hivex_root ();

returns the root node of the hive ๐ŸŒณ

this is a wrapper around the hivex(3) call of the same name.

this function depends on the feature hivex. see also $g->feature-available.

hivex_value_key

$key = $g->hivex_value_key ($valueh);

returns the key (name) field of a (key, datatype, data) tuple ๐Ÿ”‘

this is a wrapper around the hivex(3) call of the same name.

this function depends on the feature hivex. see also $g->feature-available.

hivex_value_string

$databuf = $g->hivex_value_string ($valueh);

okay so this calls $g->hivex_value_value (which returns the data field from a hivex value tuple). it then assumes that the field is a UTF-16LE string and converts the result to UTF-8 โ€” or, if this is not possible, it returns an error ๐Ÿ˜ญ

this is useful for reading strings out of the Windows registry. however it is not foolproof, because the registry is not strongly-typed and fields can contain arbitrary or unexpected data. so like, vibe check your data before you trust it ๐Ÿ’…

this function depends on the feature hivex. see also $g->feature-available.

hivex_value_type

$datatype = $g->hivex_value_type ($valueh);

returns the data type field from a (key, datatype, data) tuple ๐Ÿท๏ธ

this is a wrapper around the hivex(3) call of the same name.

this function depends on the feature hivex. see also $g->feature-available.

hivex_value_utf8

$databuf = $g->hivex_value_utf8 ($valueh);

this calls $g->hivex_value_value (which returns the data field from a hivex value tuple). it then assumes that the field is a UTF-16LE string and converts the result to UTF-8 โ€” or, if this is not possible, it returns an error ๐Ÿ˜ญ

this is useful for reading strings out of the Windows registry. however it is not foolproof, because the registry is not strongly-typed and fields can contain arbitrary or unexpected data.

this function depends on the feature hivex. see also $g->feature-available.

deprecated, bestie ๐Ÿšจ in new code, use the "hivex_value_string" call instead.

and again, for the people in the back: deprecated functions will not be removed from the API, but the fact that they're deprecated indicates that there are problems with correct use of these functions ๐Ÿ’€

hivex_value_value

$databuf = $g->hivex_value_value ($valueh);

returns the data field of a (key, datatype, data) tuple ๐Ÿ“ฆ

this is a wrapper around the hivex(3) call of the same name.

see also: $g->hivex_value_utf8.

this function depends on the feature hivex. see also $g->feature-available.

initrd_cat

$content = $g->initrd_cat ($initrdpath, $filename);

this command unpacks the file filename from the initrd file called initrdpath. the filename must be given without the initial / character, okay? ๐ŸŽ€

for example, in guestfish you could use the following command to examine the boot script (usually called /init) contained in a Linux initrd or initramfs image:

initrd-cat /boot/initrd-<version>.img init

see also $g->initrd_list ๐Ÿ‘€

because of the message protocol, there is a transfer limit of somewhere between 2MB and 4MB. see "PROTOCOL LIMITS" in guestfs(3).

initrd_list

@filenames = $g->initrd_list ($path);

this command lists out files contained in an initrd ๐Ÿ“‹

the files are listed without any initial / character. the files are listed in the order they appear (not necessarily alphabetical). directory names are listed as separate items. iykyk ๐ŸŒˆ

old Linux kernels (2.4 and earlier) used a compressed ext2 filesystem as initrd. we only support the newer initramfs format (compressed cpio files) โ€” so if you're rolling up with a kernel from 2002, that's a no from us ๐Ÿซ 

inotify_add_watch

$wd = $g->inotify_add_watch ($path, $mask);

watches path for the events listed in mask ๐Ÿ‘๏ธโœจ

note that if path is a directory, then events within that directory are watched โ€” but this does not happen recursively (so, not in subdirectories). highkey important, don't forget it ๐Ÿ’…

Note for non-C or non-Linux besties: the inotify events are defined by the Linux kernel ABI and are listed in /usr/include/sys/inotify.h. iykyk ๐Ÿ’…

This function depends on the feature "inotify". See also "$g->feature-available".


$g->inotify_close ();

Closes the inotify handle that was opened earlier by inotify_init. It's the cleanup era โœจ โ€” it removes all the watches, yeets any pending events into the void, and deallocates all the resources. Nothing left behind, no cap.

This function depends on the feature "inotify". See also "$g->feature-available".


@paths = $g->inotify_files ();

Okay so this is the lowkey lazy-girl version of "$g->inotify_read" โ€” it just hands you back a list of pathnames of the objects that got touched. And the returned pathnames are sorted and deduplicated, which is honestly so thoughtful of it ๐ŸŽ€.

This function depends on the feature "inotify". See also "$g->feature-available".


$g->inotify_init ($maxevents);

This command creates a brand new inotify handle. The inotify subsystem is the vibe-check system for your guest filesystem โ€” it tells you what events happen to objects in there ๐Ÿ’–.

maxevents is the maximum number of events that will get queued up between calls to "$g->inotify_read" or "$g->inotify_files". If you pass it as 0, then the kernel (or whatever default was set before) gets used. For Linux 2.6.29 the default was 16384 events. Past that limit, the kernel literally throws events away ๐Ÿ˜ญ โ€” but it does record the fact that it threw them away by setting a flag IN_Q_OVERFLOW in the returned structure list (see "$g->inotify_read"). So at least it's honest about the L.

Before any events are generated, you have to add some watches to the internal watch list. See: "$g->inotify_add_watch" and "$g->inotify_rm_watch".

Queued up events should be read periodically by calling "$g->inotify_read" (or "$g->inotify_files", which is just a helpful wrapper around "$g->inotify_read"). If you don't read the events out often enough then you risk the internal queue overflowing โ€” and we already know how the kernel feels about that ๐Ÿ™ˆ.

The handle should be closed after use by calling "$g->inotify_close". That also removes any watches automatically. Slay, one less thing.

See also inotify(7) for an overview of the inotify interface as exposed by the Linux kernel, which is roughly what we expose via libguestfs. Note that there is one global inotify handle per libguestfs instance โ€” main character energy, but only one of her ๐Ÿ‘‘.

This function depends on the feature "inotify". See also "$g->feature-available".


@events = $g->inotify_read ();

Returns the complete queue of events that have happened since the previous read call.

If no events have happened, this returns an empty list. Peaceful. Serene. ๐Ÿฆ‹

Heads up, bestie: to make sure you've literally read all the events, you have to call this function repeatedly until it returns an empty list. The reason is that the call reads events up to the maximum appliance-to-host message size and leaves the remaining events in the queue. So one call is not the moment โ€” loop it fr fr.

This function depends on the feature "inotify". See also "$g->feature-available".


$g->inotify_rm_watch ($wd);

Removes a previously defined inotify watch. Like unfollowing, but for files. See "$g->inotify_add_watch".

This function depends on the feature "inotify". See also "$g->feature-available".


$arch = $g->inspect_get_arch ($root);

Returns the architecture of the inspected operating system. The possible return values are listed under "$g->file_architecture".

If the architecture could not be determined, then the string "unknown" is returned. (She said "idk" ๐Ÿ’€.)

Please read "INSPECTION" in guestfs(3) for more details.


$buildid = $g->inspect_get_build_id ($root);

Returns the build ID of the system, or the string "unknown" if the system doesn't have one.

For Windows, this gets the build number. Even though it's returned as a string, it is (so far) always a number โ€” quirky but we love her. See <https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions> for some possible values.

For Linux, this returns the "BUILD_ID" string from /etc/os-release, although this is not often used. It's giving "I'm in the file but nobody reads me" ๐ŸŽ€.

Please read "INSPECTION" in guestfs(3) for more details.


$distro = $g->inspect_get_distro ($root);

Returns the distro (distribution) of the inspected operating system. Currently defined distros are, in no particular order but very much all here ๐Ÿ’…:

  • "alpinelinux" โ€” Alpine Linux.
  • "altlinux" โ€” ALT Linux.
  • "archlinux" โ€” Arch Linux.
  • "buildroot" โ€” Buildroot-derived distro, but not one we specifically recognize.
  • "centos" โ€” CentOS.
  • "circle" โ€” Circle Linux.
  • "cirros" โ€” Cirros.
  • "coreos" โ€” CoreOS.
  • "debian" โ€” Debian.
  • "fedora" โ€” Fedora.
  • "freebsd" โ€” FreeBSD.
  • "freedos" โ€” FreeDOS.
  • "frugalware" โ€” Frugalware.
  • "gentoo" โ€” Gentoo.
  • "kalilinux" โ€” Kali Linux.
  • "kylin" โ€” Kylin.
  • "linuxmint" โ€” Linux Mint.
  • "mageia" โ€” Mageia.
  • "mandriva" โ€” Mandriva.
  • "meego" โ€” MeeGo.
  • "msdos" โ€” Microsoft DOS.
  • "neokylin" โ€” NeoKylin.
  • "netbsd" โ€” NetBSD.
  • "openbsd" โ€” OpenBSD.
  • "openeuler" โ€” openEuler.
  • "openmandriva" โ€” OpenMandriva Lx.
  • "opensuse" โ€” OpenSUSE.
  • "oraclelinux" โ€” Oracle Linux.
  • "pardus" โ€” Pardus.
  • "pldlinux" โ€” PLD Linux.
  • "redhat-based" โ€” Some Red Hat-derived distro.
  • "rhel" โ€” Red Hat Enterprise Linux.
  • "rocky" โ€” Rocky Linux.
  • "scientificlinux" โ€” Scientific Linux.
  • "slackware" โ€” Slackware.
  • "sles" โ€” SuSE Linux Enterprise Server or Desktop.
  • "suse-based" โ€” Some openSuSE-derived distro.
  • "ttylinux" โ€” ttylinux.
  • "ubuntu" โ€” Ubuntu.
  • "unknown" โ€” The distro could not be determined.
  • "voidlinux" โ€” Void Linux.
  • "windows" โ€” Windows does not have distributions. This string is returned if the OS type is Windows.

Future versions of libguestfs may return other strings here. The caller should be prepared to handle any string โ€” so like, don't hardcode your faves, bestie ๐Ÿ™ˆ.

Please read "INSPECTION" in guestfs(3) for more details.


%drives = $g->inspect_get_drive_mappings ($root);

This call is useful for Windows, which uses a primitive system of assigning drive letters (like C:\) to partitions. Bestie, it's giving 1981 but go off. This inspection API examines the Windows Registry to find out how disks/partitions are mapped to drive letters, and returns a hash table as in the example below:

 C      =>     /dev/vda2
 E      =>     /dev/vdb1
 F      =>     /dev/vdc1

Note that keys are drive letters. For Windows, the key is case insensitive and just contains the drive letter, without the customary colon separator character. So C, not C: โ€” important detail, don't skip it โœจ.

In future we may support other operating systems that also used drive letters, but the keys for those might not be case insensitive and might be longer than 1 character. For example in OS-9, hard drives were named "h0", "h1" etc.

For Windows guests, currently only hard drive mappings are returned. Removable disks (eg. DVD-ROMs) are ignored. ๐Ÿ’€

For guests that do not use drive mappings, or if the drive mappings could not be determined, this returns an empty hash table. Empty. Void. A little sad but valid.

Please read "INSPECTION" in guestfs(3) for more details. See also "$g->inspect_get_mountpoints", "$g->inspect_get_filesystems".


@filesystems = $g->inspect_get_filesystems ($root);

Returns a list of all the filesystems that we think are associated with this operating system. That includes the root filesystem, other ordinary filesystems, and non-mounted devices like swap partitions.

In the case of a multi-boot virtual machine, it's possible for a filesystem to be shared between operating systems โ€” sharing is caring ๐Ÿซถ.

Please read "INSPECTION" in guestfs(3) for more details. See also "$g->inspect_get_mountpoints".


$format = $g->inspect_get_format ($root);

Okay, lore time: before libguestfs 1.38, there was some unreliable support for detecting installer CDs. This API would return:

  • "installed" โ€” This is an installed operating system.
  • "installer" โ€” The disk image being inspected is not an installed operating system, but a bootable install disk, live CD, or similar.
  • "unknown" โ€” The format of this disk image is not known.

In libguestfs โ‰ฅ 1.38, this only returns "installed". Use libosinfo directly to detect installer CDs โ€” she's moved on, the old way is not the moment.

Please read "INSPECTION" in guestfs(3) for more details.

This function is deprecated. There is no replacement. Consult the API documentation in guestfs(3) for further information.

Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions. So like, use at your own risk, bestie ๐Ÿ˜ญ.


$hostname = $g->inspect_get_hostname ($root);

Returns the hostname of the operating system as found by inspection of the guestโ€™s configuration files.

If the hostname could not be determined, then the string "unknown" is returned.

Please read "INSPECTION" in guestfs(3) for more details.


$icon = $g->inspect_get_icon ($root [, favicon => $favicon] [, highquality => $highquality]);

This function returns an icon corresponding to the inspected operating system ๐Ÿ’–โœจ. The icon comes back as a buffer containing a PNG image (re-encoded to PNG if necessary โ€” she'll make it work).

If it was not possible to get an icon, this function returns a zero-length (non-NULL) buffer. Callers must check for this case. Yes, really โ€” zero-length but not NULL, so check the length, not just whether it exists ๐Ÿ™ˆ.

Libguestfs will start by looking for a file called /etc/favicon.png or C:\etc\favicon.png, and if it has the correct format, the contents of this file will be returned. You can disable favicons by passing the optional "favicon" boolean as false (default is true).

If finding the favicon fails, then we look in other places in the guest for a suitable icon. Resourceful queen ๐Ÿ‘‘.

If the optional "highquality" boolean is true then only high quality icons are returned, which means only icons of high resolution with an alpha channel. The default (false) is to return any icon we can, even if it is of substandard quality. No judgement here ๐Ÿ’….

Notes:

Okay so, the icon notes keep going ๐Ÿ’…:

  • Unlike most other inspection API calls, the guestโ€™s disks must be mounted up before you call this, since it needs to read information from the guest filesystem during the call.
  • Security: the icon data comes from the untrusted guest, and should be treated with caution. PNG files have been known to contain exploits. Ensure that libpng (or other relevant libraries) are fully up to date before trying to process or display the icon.
  • The PNG image returned can be any size. It might not be square. Libguestfs tries to return the largest, highest quality icon available. The application must scale the icon to the required size.
  • Extracting icons from Windows guests requires the external wrestool(1) program from the "icoutils" package, and several programs (bmptopnm(1), pnmtopng(1), pamcut(1)) from the "netpbm" package. These must be installed separately.
  • Operating system icons are usually trademarks. Seek legal advice before using trademarks in applications.

$major = $g->inspect_get_major_version ($root);

This returns the major version number of the inspected operating system. โœจ

Windows uses a consistent versioning scheme which is not reflected in the popular public names used by the operating system. Notably the operating system known as "Windows 7" is really version 6.1 (ie. major = 6, minor = 1). You can find out the real versions corresponding to releases of Windows by consulting Wikipedia or MSDN.

If the version could not be determined, then 0 is returned.

Please read "INSPECTION" in guestfs(3) for more details.

$minor = $g->inspect_get_minor_version ($root);

This returns the minor version number of the inspected operating system.

If the version could not be determined, then 0 is returned.

Please read "INSPECTION" in guestfs(3) for more details. See also $g->inspect_get_major_version.

%mountpoints = $g->inspect_get_mountpoints ($root);

This returns a hash of where we think the filesystems associated with this operating system should be mounted. Callers should note that this is at best an educated guess made by reading configuration files such as /etc/fstab. In particular note that this may return filesystems which are non-existent or not mountable and callers should be prepared to handle or ignore failures if they try to mount them.

Each element in the returned hashtable has a key which is the path of the mountpoint (eg. /boot) and a value which is the filesystem that would be mounted there (eg. /dev/sda1).

Non-mounted devices such as swap devices are not returned in this list.

For operating systems like Windows which still use drive letters, this call will only return an entry for the first drive "mounted on" /. For information about the mapping of drive letters to partitions, see $g->inspect_get_drive_mappings.

Please read "INSPECTION" in guestfs(3) for more details. See also $g->inspect_get_filesystems.

$id = $g->inspect_get_osinfo ($root);

This function returns a possible short ID for libosinfo corresponding to the guest.

Note: The returned ID is only a guess by libguestfs, and nothing ensures that it actually exists in osinfo-db.

If no ID could be determined, then the string "unknown" is returned.

$packageformat = $g->inspect_get_package_format ($root);

This function and $g->inspect_get_package_management return the package format and package management tool used by the inspected operating system. For example for Fedora these functions would return "rpm" (package format), and "yum" or "dnf" (package management).

This returns the string "unknown" if we could not determine the package format or if the operating system does not have a real packaging system (eg. Windows).

Possible strings include: "rpm", "deb", "ebuild", "pisi", "pacman", "pkgsrc", "apk", "xbps". Future versions of libguestfs may return other strings.

Please read "INSPECTION" in guestfs(3) for more details.

$packagemanagement = $g->inspect_get_package_management ($root);

$g->inspect_get_package_format and this function return the package format and package management tool used by the inspected operating system. For example for Fedora these functions would return "rpm" (package format), and "yum" or "dnf" (package management).

This returns the string "unknown" if we could not determine the package management tool or if the operating system does not have a real packaging system (eg. Windows).

Possible strings include: "yum", "dnf", "up2date", "apt" (for all Debian derivatives), "portage", "pisi", "pacman", "urpmi", "zypper", "apk", "xbps". Future versions of libguestfs may return other strings.

Please read "INSPECTION" in guestfs(3) for more details.

$product = $g->inspect_get_product_name ($root);

This returns the product name of the inspected operating system. The product name is generally some freeform string which can be displayed to the user, but should not be parsed by programs.

If the product name could not be determined, then the string "unknown" is returned.

Please read "INSPECTION" in guestfs(3) for more details.

$variant = $g->inspect_get_product_variant ($root);

This returns the product variant of the inspected operating system.

For Windows guests, this returns the contents of the Registry key "HKLM\Software\Microsoft\Windows NT\CurrentVersion" "InstallationType" which is usually a string such as "Client" or "Server" (other values are possible). This can be used to distinguish consumer and enterprise versions of Windows that have the same version number (for example, Windows 7 and Windows 2008 Server are both version 6.1, but the former is "Client" and the latter is "Server").

For enterprise Linux guests, in future we intend this to return the product variant such as "Desktop", "Server" and so on. But this is not implemented at present.

If the product variant could not be determined, then the string "unknown" is returned.

Please read "INSPECTION" in guestfs(3) for more details. See also $g->inspect_get_product_name, $g->inspect_get_major_version.

@roots = $g->inspect_get_roots ();

This function is a convenient way to get the list of root devices, as returned from a previous call to $g->inspect_os, but without redoing the whole inspection process.

This returns an empty list if either no root devices were found or the caller has not called $g->inspect_os.

Please read "INSPECTION" in guestfs(3) for more details.

$name = $g->inspect_get_type ($root);

This returns the type of the inspected operating system. Currently defined types are:

  • "linux" โ€” Any Linux-based operating system.
  • "windows" โ€” Any Microsoft Windows operating system.
  • "freebsd" โ€” FreeBSD.
  • "netbsd" โ€” NetBSD.
  • "openbsd" โ€” OpenBSD.
  • "hurd" โ€” GNU/Hurd.
  • "dos" โ€” MS-DOS, FreeDOS and others.
  • "minix" โ€” MINIX.
  • "unknown" โ€” The operating system type could not be determined.

Future versions of libguestfs may return other strings here. The caller should be prepared to handle any string.

Please read "INSPECTION" in guestfs(3) for more details.

$controlset = $g->inspect_get_windows_current_control_set ($root);

This returns the Windows CurrentControlSet of the inspected guest. The CurrentControlSet is a registry key name such as "ControlSet001".

This call assumes that the guest is Windows and that the Registry could be examined by inspection. If this is not the case then an error is returned.

Please read "INSPECTION" in guestfs(3) for more details.

$path = $g->inspect_get_windows_software_hive ($root);

This returns the path to the hive (binary Windows Registry file) corresponding to HKLM\SOFTWARE.

This call assumes that the guest is Windows and that the guest has a software hive file with the right name. If this is not the case then an error is returned. This call does not check that the hive is a valid Windows Registry hive.

You can use $g->hivex_open to read or write to the hive.

Please read "INSPECTION" in guestfs(3) for more details.

$path = $g->inspect_get_windows_system_hive ($root);

This returns the path to the hive (binary Windows Registry file) corresponding to HKLM\SYSTEM.

This call assumes that the guest is Windows and that the guest has a system hive file with the right name. If this is not the case then an error is returned. This call does not check that the hive is a valid Windows Registry hive.

You can use $g->hivex_open to read or write to the hive.

Please read "INSPECTION" in guestfs(3) for more details.

$systemroot = $g->inspect_get_windows_systemroot ($root);

This returns the Windows systemroot of the inspected guest. The systemroot is a directory path such as /WINDOWS.

This call assumes that the guest is Windows and that the systemroot could be determined by inspection. If this is not the case then an error is returned.

Please read "INSPECTION" in guestfs(3) for more details.

$live = $g->inspect_is_live ($root);

This is deprecated and always returns "false".

Please read "INSPECTION" in guestfs(3) for more details.

Deprecated alert ๐Ÿšจ This function is deprecated. There is no replacement. Consult the API documentation in guestfs(3) for further information.

Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions.

$multipart = $g->inspect_is_multipart ($root);

This is deprecated and always returns "false".

Please read "INSPECTION" in guestfs(3) for more details.

Deprecated alert ๐Ÿšจ This function is deprecated. There is no replacement. Consult the API documentation in guestfs(3) for further information.

Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions.

$netinst = $g->inspect_is_netinst ($root);

This is deprecated and always returns "false".

Please read "INSPECTION" in guestfs(3) for more details.

okay so real talk bestie, this one is deprecated โ€” no replacement, nothing to migrate to. You gotta consult the API documentation in guestfs(3) for the full tea. ๐Ÿ’€

Deprecated functions will not be removed from the API, but the fact that they're deprecated is basically the codebase going "yeah there are problems with using these correctly" โ€” so like, proceed with awareness. ๐Ÿ™ˆ


๐Ÿงธ @applications = $g->inspect_list_applications ($root);

Returns the list of applications installed in the operating system. โœจ

โš ๏ธ Read this before you go off: this call works differently from the other parts of the inspection API. You have to call $g->inspect_os first, then $g->inspect_get_mountpoints, then mount up the disks, and only then call this. Listing applications is a significantly more difficult operation which requires access to the full filesystem. Also note โ€” and this is the iconique part โ€” unlike the other $g->inspect_get_* calls which are just returning data cached in the libguestfs handle, this call actually reads parts of the mounted filesystems during the call. ๐Ÿ’…

It returns an empty list if the inspection code wasn't able to determine the list of applications.

The application structure contains the following fields:

  • "app_name" โ€” the name of the application. For Linux guests, this is the package name. ๐Ÿท๏ธ
  • "app_display_name" โ€” the display name of the application, sometimes localized to the install language of the guest operating system. If unavailable this is returned as an empty string "". Callers needing to display something can use "app_name" instead.
  • "app_epoch" โ€” for package managers which use epochs, this contains the epoch of the package (an integer). If unavailable, this is returned as 0.
  • "app_version" โ€” the version string of the application or package. If unavailable this is returned as an empty string "".
  • "app_release" โ€” the release string of the application or package, for package managers that use this. If unavailable this is returned as an empty string "".
  • "app_install_path" โ€” the installation path of the application (on operating systems such as Windows which use installation paths). This path is in the format used by the guest operating system, it is not a libguestfs path. If unavailable this is returned as an empty string "".
  • "app_trans_path" โ€” the install path translated into a libguestfs path. If unavailable this is returned as an empty string "".
  • "app_publisher" โ€” the name of the publisher of the application, for package managers that use this. If unavailable this is returned as an empty string "".
  • "app_url" โ€” the URL (eg. upstream URL) of the application. If unavailable this is returned as an empty string "".
  • "app_source_package" โ€” for packaging systems which support this, the name of the source package. If unavailable this is returned as an empty string "".
  • "app_summary" โ€” a short (usually one line) description of the application or package. If unavailable this is returned as an empty string "".
  • "app_description" โ€” a longer description of the application or package. If unavailable this is returned as an empty string "".

Please read "INSPECTION" in guestfs(3) for more details. ๐Ÿฆ‹

And yeah โ€” this function is deprecated. In new code, use the "inspect_list_applications2" call instead. โœจ

Deprecated functions will not be removed from the API, but the fact that they're deprecated indicates that there are problems with correct use of these functions.


๐ŸŒธ @applications2 = $g->inspect_list_applications2 ($root);

Return the list of applications installed in the operating system. Same mission, shinier struct. ๐Ÿซถ

โš ๏ธ Same warning as before, because it's literally the same rule: this call works differently from other parts of the inspection API. You have to call $g->inspect_os, then $g->inspect_get_mountpoints, then mount up the disks, before calling this. Listing applications is a significantly more difficult operation which requires access to the full filesystem. And again โ€” unlike the other $g->inspect_get_* calls which are just returning data cached in the libguestfs handle, this call actually reads parts of the mounted filesystems during the call.

Returns an empty list if the inspection code was not able to determine the list of applications.

The application structure contains the following fields:

  • "app2_name" โ€” the name of the application. For Linux guests, this is the package name. ๐Ÿท๏ธ
  • "app2_display_name" โ€” the display name of the application, sometimes localized to the install language of the guest operating system. If unavailable this is returned as an empty string "". Callers needing to display something can use "app2_name" instead.
  • "app2_epoch" โ€” for package managers which use epochs, this contains the epoch of the package (an integer). If unavailable, this is returned as 0.
  • "app2_version" โ€” the version string of the application or package. If unavailable this is returned as an empty string "".
  • "app2_release" โ€” the release string of the application or package, for package managers that use this. If unavailable this is returned as an empty string "".
  • "app2_arch" โ€” the architecture string of the application or package, for package managers that use this. If unavailable this is returned as an empty string "".
  • "app2_install_path" โ€” the installation path of the application (on operating systems such as Windows which use installation paths). This path is in the format used by the guest operating system, it is not a libguestfs path. If unavailable this is returned as an empty string "".
  • "app2_trans_path" โ€” the install path translated into a libguestfs path. If unavailable this is returned as an empty string "".
  • "app2_publisher" โ€” the name of the publisher of the application, for package managers that use this. If unavailable this is returned as an empty string "".
  • "app2_url" โ€” the URL (eg. upstream URL) of the application. If unavailable this is returned as an empty string "".
  • "app2_source_package" โ€” for packaging systems which support this, the name of the source package. If unavailable this is returned as an empty string "".
  • "app2_summary" โ€” a short (usually one line) description of the application or package. If unavailable this is returned as an empty string "".
  • "app2_description" โ€” a longer description of the application or package. If unavailable this is returned as an empty string "".

Please read "INSPECTION" in guestfs(3) for more details. ๐Ÿ’–


๐Ÿ” @roots = $g->inspect_os ();

This one's the main character fr fr ๐Ÿ‘‘ โ€” it uses other libguestfs functions and certain heuristics to inspect the disk(s) (usually disks belonging to a virtual machine), looking for operating systems.

The list returned is empty if no operating systems were found.

If one operating system was found, then this returns a list with a single element, which is the name of the root filesystem of this operating system. It's also possible for this function to return a list containing more than one element, indicating a dual-boot or multi-boot virtual machine, with each element being the root filesystem of one of the operating systems. ๐ŸŒˆ

You can pass the root string(s) returned to other $g->inspect_get_* functions in order to query further information about each operating system, such as the name and version.

๐Ÿซถ Heads up, this function uses other libguestfs features such as $g->mount_ro and $g->umount_all in order to mount and unmount filesystems and look at the contents. This should be called with no disks currently mounted. The function may also use Augeas, so any existing Augeas handle will be closed.

This function cannot decrypt encrypted disks. The caller must do that first (supplying the necessary keys) if the disk is encrypted. ๐Ÿ”‘

Please read "INSPECTION" in guestfs(3) for more details.

See also $g->list_filesystems. โœจ


Returns "true" if and only if there is a block device with the given "path" name.

If the optional flag "followsymlinks" is true, then a symlink (or chain of symlinks) that ends with a block device also causes the function to return true.

๐Ÿ’€ This call only looks at files within the guest filesystem. Libguestfs partitions and block devices (eg. /dev/sda) cannot be used as the "path" parameter of this call.

See also $g->stat.


This is an alias of "is_blockdev". Same energy, different name. ๐Ÿ’…


โณ $busy = $g->is_busy ();

This always returns false. This function is deprecated with no replacement. Do not use this function. ๐Ÿ˜ญ

For more information on states, see guestfs(3).


This returns "true" if and only if there is a character device with the given "path" name.

If the optional flag "followsymlinks" is true, then a symlink (or chain of symlinks) that ends with a chardev also causes the function to return true. ๐Ÿ”—

See also $g->stat.


This is an alias of "is_chardev". ๐ŸŽ€


โš™๏ธ $config = $g->is_config ();

This returns true iff this handle is being configured (in the "CONFIG" state).

For more information on states, see guestfs(3).


This returns "true" if and only if there is a directory with the given "path" name. Note that it returns false for other objects like files โ€” so don't come for it expecting "is this a path" behaviour, it's strictly directory-coded. ๐Ÿ—‚๏ธ

If the optional flag "followsymlinks" is true, then a symlink (or chain of symlinks) that ends with a directory also causes the function to return true.

See also $g->stat.


This is an alias of "is_dir". โœจ


This returns "true" if and only if there is a FIFO (named pipe) with the given "path" name. Named pipes stay iconic ngl. ๐Ÿ’œ


  • $flag = $g->is_fifo ($path [, followsymlinks => $followsymlinks]); โ€” the tail end of this one bestie: if the optional flag followsymlinks is true, then a symlink (or a whole chain of symlinks) that ends with a FIFO also makes the function return true. ๐Ÿ’…

See also $g->stat.

Lowkey this is just a whole alias of is_fifo. Same energy, different name. โœจ

Returns true if and only if there's a regular file sitting at that path name. And like, note that it returns false for other objects โ€” directories, for example, are not it. ๐Ÿ™ˆ

If the optional flag followsymlinks is true, then a symlink (or chain of symlinks) that ends with a file also causes the function to return true. Slay.

See also $g->stat.

Alias of is_file, no cap. ๐Ÿซถ

$launching = $g->is_launching ();

Returns true iff this handle is currently launching the subprocess โ€” i.e. it's in the LAUNCHING state. It's giving "hold on, I'm booting" energy. โญ

For more information on states, see guestfs(3).

$lvflag = $g->is_lv ($mountable);

Tests whether mountable is a logical volume, and returns true iff that's the case. LVM girlies rise. ๐Ÿ‘‘

$ready = $g->is_ready ();

Returns true iff this handle is ready to accept commands โ€” that's the READY state, the main character state fr fr. ๐Ÿ’–

For more information on states, see guestfs(3).

Returns true if and only if there's a Unix domain socket with that path name. ๐Ÿฆ‹

If the optional flag followsymlinks is true, then a symlink (or chain of symlinks) that ends with a socket also causes the function to return true.

See also $g->stat.

This is an alias of is_socket.

Returns true if and only if there's a symbolic link with that path name. Note: no followsymlinks option here, bestie โ€” it's about the link itself, periodt. ๐Ÿ”ฅ

See also $g->stat.

$flag = $g->is_whole_device ($device);

Returns true if and only if device refers to a whole block device โ€” meaning not a partition and not a logical device. Whole, unbothered, in its lane. ๐Ÿ’…

$zeroflag = $g->is_zero ($path);

Returns true iff the file exists and the file is empty or it contains all zero bytes. Zero-byte legend behavior. ๐ŸŽ€

$zeroflag = $g->is_zero_device ($device);

Returns true iff the device exists and contains all zero bytes.

Heads up: for large devices this can take a long time to run. Like, go make a snack. ๐Ÿ˜ญ

%isodata = $g->isoinfo ($isofile);

Same as $g->isoinfo_device, except it works for an ISO file located inside some other mounted filesystem. But ngl, in the common case where you've added an ISO file as a libguestfs device, you would not call this โ€” instead you'd call $g->isoinfo_device. โœจ

%isodata = $g->isoinfo_device ($device);

device is an ISO device. This returns a struct of information read from the primary volume descriptor (the ISO equivalent of the superblock) of the device. ๐ŸŒธ

Usually it's more efficient to use the isoinfo(1) command with the -d option on the host to analyze ISO files, instead of going through libguestfs.

For information on the primary volume descriptor fields, see <https://wiki.osdev.org/ISO_9660#The_Primary_Volume_Descriptor>

$g->journal_close ();

Close the journal handle. Bye bestie ๐Ÿ‘‹

This function depends on the feature journal. See also $g->feature-available.

@fields = $g->journal_get ();

Read the current journal entry. This returns all the fields in the journal as a set of (attrname, attrval) pairs. The attrname is the field name (a string). ๐Ÿฆ‹

The attrval is the field value (a binary blob, often but not always a string). Please note that attrval is a byte array, not a \0-terminated C string. That distinction is doing a lot of work here, iykyk.

The length of data may be truncated to the data threshold (see: $g->journal_set_data_threshold, $g->journal_get_data_threshold).

If you set the data threshold to unlimited (0), then this call can read a journal entry of any size, ie. it's not limited by the libguestfs protocol. ๐Ÿ’œ

This function depends on the feature journal. See also $g->feature-available.

$threshold = $g->journal_get_data_threshold ();

Get the current data threshold for reading journal entries. It's a hint to the journal that it may truncate data fields to this size when reading them (and note it also may not truncate them โ€” it's a hint, not a promise, fr fr). If this returns 0, then the threshold is unlimited. ๐ŸŒˆ

See also $g->journal_set_data_threshold.

This function depends on the feature journal. See also $g->feature-available.

$usec = $g->journal_get_realtime_usec ();

Get the realtime (wallclock) timestamp of the current journal entry. Clock girlie behavior. โญ

This function depends on the feature journal. See also $g->feature-available.

$more = $g->journal_next ();

Move to the next journal entry. You have to call this at least once after opening the handle before you're able to read data โ€” like, you can't just skip to the reading part, bestie. ๐Ÿ’€

The returned boolean tells you if there are any more journal records to read. true means you can read the next record (eg. using $g->journal_get), and false means you've reached the end of the journal.

This function depends on the feature journal. See also $g->feature-available.

$g->journal_open ($directory);

Open the systemd journal located in directory. Any previously opened journal handle is closed โ€” out with the old. โœจ

The contents of the journal can be read using $g->journal_next and $g->journal_get.

After you've finished using the journal, you should close the handle by calling $g->journal_close. Clean up after yourself, icon behavior.

This function depends on the feature journal. See also $g->feature-available.

$g->journal_set_data_threshold ($threshold);

Set the data threshold for reading journal entries. This is a hint to the journal that it may truncate data fields to this size when reading them (again โ€” it may also not truncate them). If you set this to 0, then the threshold is unlimited. ๐Ÿซถ

See also $g->journal_get_data_threshold.

This function depends on the feature journal. See also $g->feature-available.

$rskip = $g->journal_skip ($skip);

Skip forwards (skip โ‰ฅ 0) or backwards (skip < 0) in the journal. Direction queen. ๐ŸŽ€

The number of entries actually skipped is returned (note rskip โ‰ฅ 0). If this isn't the same as the absolute value of the skip parameter (|skip|) you passed in, then it means you've reached the end or the start of the journal. So like, do the math and you'll know. ๐Ÿ’…

This function depends on the feature journal. See also $g->feature-available.

$g->kill_subprocess ();

This kills the hypervisor.

Do not call this. See: $g->shutdown instead. ๐Ÿ™ˆ

This function is deprecated. In new code, use the shutdown call instead.

Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions. So like, it's still there, but it's giving red flag.

$g->launch ();

You should call this after configuring the handle (eg. adding drives) but before performing any actions. Setup first, actions second, that's the order. ๐ŸŒธ

Do not call $g->launch twice on the same handle. Although it will not give an error (for historical reasons), the precise behaviour when you do this is not well defined. ๐Ÿ˜ญ Handles are very cheap to create, so just create a new one for each launch โ€” problem solved, bestie.

$g->lchown ($owner, $group, $path);

Change the file owner to owner and group to group. This is like $g->chown, but if path is a symlink then the link itself is changed, not the target. Sneaky but correct. ๐Ÿฆ‹

Only numeric uid and gid are supported. If you want to use names, you'll need to locate and parse the password file yourself (Augeas support makes this relatively easy). Okay but honestly Augeas is kind of iconic for this.

$g->ldmtool_create_all ();

This function scans all block devices looking for Windows dynamic disk volumes and partitions, and creates devices for any that were found. ๐Ÿช„

Call $g->list_ldm_volumes and $g->list_ldm_partitions to return all devices.

Note that you don't normally need to call this explicitly, since it's done automatically at $g->launch time. It just happens, like magic.

This function depends on the feature ldm. See also $g->feature-available.

@disks = $g->ldmtool_diskgroup_disks ($diskgroup);

Return the disks in a Windows dynamic disk group. The diskgroup parameter should be the GUID of a disk group โ€” one element from the list returned by $g->ldmtool_scan. ๐Ÿ’œ

This function depends on the feature ldm. See also $g->feature-available.

$name = $g->ldmtool_diskgroup_name ($diskgroup);

Return the name of a Windows dynamic disk group. The diskgroup parameter should be the GUID of a disk group, one element from the list returned by $g->ldmtool_scan. โญ

This function depends on the feature ldm. See also $g->feature-available.

@volumes = $g->ldmtool_diskgroup_volumes ($diskgroup);

Return the volumes in a Windows dynamic disk group. The diskgroup parameter should be the GUID of a disk group, one element from the list returned by $g->ldmtool_scan. ๐Ÿ”ฅ

This function depends on the feature ldm. See also $g->feature-available.

$g->ldmtool_remove_all ();

This is essentially the opposite of $g->ldmtool_create_all. It removes the device mapper mappings for all Windows dynamic disk volumes. Undo culture. ๐Ÿ’…

This function depends on the feature ldm. See also $g->feature-available.

@guids = $g->ldmtool_scan ();

This function scans for Windows dynamic disks. It returns a list of identifiers (GUIDs) for all disk groups that were found. These identifiers can be passed to other $g->ldmtool_* functions. ๐Ÿ‘‘

This function scans all block devices. To scan a subset of block devices, call $g->ldmtool_scan_devices instead.

This function depends on the feature ldm. See also $g->feature-available.

@guids = $g->ldmtool_scan_devices (\@devices);

This function scans for Windows dynamic disks. It returns a list of identifiers (GUIDs) for all disk groups that were found. These identifiers can be passed to other $g->ldmtool_* functions. ๐ŸŒˆ

The parameter devices is a list of block devices which are scanned. If this list is empty, all block devices are scanned. Empty list = no filter = everybody's invited. โœจ

This function depends on the feature ldm. See also $g->feature-available.

๐Ÿ’ซ $hint = $g->ldmtool_volume_hint ($diskgroup, $volume);

Okay so this one grabs the hint field of the volume named volume in the disk group whose GUID is diskgroup. It may not be defined, and in that case you get the empty string back. The hint field is often โ€” though not always โ€” the name of a Windows drive, eg. E:.

This function depends on the feature ldm. See also $g->feature-available.


๐ŸŽ€ @partitions = $g->ldmtool_volume_partitions ($diskgroup, $volume);

Returns the list of partitions in the volume named volume in the disk group with GUID diskgroup โœจ

This function depends on the feature ldm. See also $g->feature-available.


๐Ÿ’… $voltype = $g->ldmtool_volume_type ($diskgroup, $volume);

Returns the type of the volume named volume in the disk group with GUID diskgroup, no cap.

Possible volume types that can be returned here include: simple, spanned, striped, mirrored, raid5. Other types may also be returned, so donโ€™t act surprised if you see something else ๐Ÿ‘€

This function depends on the feature ldm. See also $g->feature-available.


๐Ÿฆ‹ $xattr = $g->lgetxattr ($path, $name);

Get a single extended attribute from file path named name. If path is a symlink, then this call returns an extended attribute from the symlink.

Normally it is better to get all extended attributes from a file in one go by calling $g->getxattrs. However some Linux filesystem implementations are buggy and do not provide a way to list out attributes. For these filesystems (notably ntfs-3g) you have to know the names of the extended attributes you want in advance and call this function. Annoying? Lowkey yes ๐Ÿ˜ญ

Extended attribute values are blobs of binary data. If there is no extended attribute named name, this returns an error.

See also: $g->lgetxattrs, $g->getxattr, attr(5).

This function depends on the feature linuxxattrs. See also $g->feature-available.


๐ŸŒธ @xattrs = $g->lgetxattrs ($path);

This is the same as $g->getxattrs, but if path is a symbolic link, then it returns the extended attributes of the link itself. Link energy only, bestie ๐Ÿ’…

This function depends on the feature linuxxattrs. See also $g->feature-available.


๐Ÿ’€ @mounttags = $g->list_9p ();

This call does nothing and returns an error. Thatโ€™s it. Thatโ€™s the whole vibe check. ๐Ÿ™ˆ

This function is deprecated. There is no replacement. Consult the API documentation in guestfs(3) for further information. Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions.

๐Ÿ‘‘ @devices = $g->list_devices ();

List all the block devices. The full block device names are returned, eg. /dev/sda.

See also $g->list_filesystems.


๐Ÿ“ %labels = $g->list_disk_labels ();

If you add drives using the optional label parameter of $g->add_drive_opts, you can use this call to map between disk labels, and raw block device and partition names (like /dev/sda and /dev/sda1). So useful, fr fr ๐Ÿซถ

This returns a hashtable, where keys are the disk labels (without the /dev/disk/guestfs prefix), and the values are the full raw block device and partition names (eg. /dev/sda and /dev/sda1).


๐Ÿงš @devices = $g->list_dm_devices ();

List all device mapper devices.

The returned list contains /dev/mapper/* devices, eg. ones created by a previous call to $g->luks_open.

Device mapper devices which correspond to logical volumes are not returned in this list. Call $g->lvs if you want to list logical volumes. Important distinction, bestie ๐Ÿ’–


๐ŸŒˆ %fses = $g->list_filesystems ();

This inspection command looks for filesystems on partitions, block devices and logical volumes, returning a list of mountables containing filesystems and their type. Inspection era โœจ

The return value is a hash, where the keys are the devices containing filesystems, and the values are the filesystem types. For example:

"/dev/sda1" => "ntfs"
"/dev/sda2" => "ext2"
"/dev/vg_guest/lv_root" => "ext4"
"/dev/vg_guest/lv_swap" => "swap"

The key is not necessarily a block device. It may also be an opaque โ€˜mountableโ€™ string which can be passed to $g->mount.

The value can have the special value unknown, meaning the content of the device is undetermined or empty. swap means a Linux swap partition.

In libguestfs โ‰ค 1.36 this command ran other libguestfs commands, which might have included $g->mount and $g->umount, and therefore you had to use this soon after launch and only when nothing else was mounted. This restriction is removed in libguestfs โ‰ฅ 1.38. Glow-up moment ๐Ÿ’…

โš ๏ธ Not all of the filesystems returned will be mountable. In particular, swap partitions are returned in the list. Also this command does not check that each filesystem found is valid and mountable, and some filesystems might be mountable but require special options. Filesystems may not all belong to a single logical operating system (use $g->inspect_os to look for OSes).

๐Ÿ’œ @devices = $g->list_ldm_partitions ();

This function returns all Windows dynamic disk partitions that were found at launch time. It returns a list of device names.

This function depends on the feature ldm. See also $g->feature-available.


โญ @devices = $g->list_ldm_volumes ();

This function returns all Windows dynamic disk volumes that were found at launch time. It returns a list of device names.

This function depends on the feature ldm. See also $g->feature-available.


๐Ÿ”ฅ @devices = $g->list_md_devices ();

List all Linux md devices. Short and sweet, we love a concise icon ๐ŸŽ€


๐ŸŒธ @partitions = $g->list_partitions ();

List all the partitions detected on all block devices.

The full partition device names are returned, eg. /dev/sda1

This does not return logical volumes. For that you will need to call $g->lvs.

See also $g->list_filesystems.


๐Ÿฆ‹ $listing = $g->ll ($directory);

List the files in directory (relative to the root directory, there is no cwd) in the format of ls -la.

This command is mostly useful for interactive sessions. It is not intended that you try to parse the output string. Chatting with it? Fun. Parsing it? Donโ€™t. ๐Ÿ˜ญ


๐Ÿ’€ $listing = $g->llz ($directory);

List the files in directory in the format of ls -laZ.

This command is mostly useful for interactive sessions. It is not intended that you try to parse the output string.

This function is deprecated. In new code, use the lgetxattrs call instead. Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions.

๐Ÿซถ $g->ln ($target, $linkname);

This command creates a hard link. Classic, reliable, no drama ๐Ÿ’…


โœจ $g->ln_f ($target, $linkname);

This command creates a hard link, removing the link linkname if it exists already. So itโ€™s giving โ€œmake it work, no duplicatesโ€ energy.


๐ŸŽ€ $g->ln_s ($target, $linkname);

This command creates a symbolic link using the ln -s command.


๐ŸŒˆ $g->ln_sf ($target, $linkname);

This command creates a symbolic link using the ln -sf command, and the -f option removes the link (linkname) if it exists already.


๐Ÿ’– $g->lremovexattr ($xattr, $path);

This is the same as $g->removexattr, but if path is a symbolic link, then it removes an extended attribute of the link itself.

This function depends on the feature linuxxattrs. See also $g->feature-available.


๐ŸŒธ @listing = $g->ls ($directory);

List the files in directory (relative to the root directory, there is no cwd). The . and .. entries are not returned, but hidden files are shown. Hidden files stay iconic ๐Ÿ‘‘


๐Ÿงš $g->ls0 ($dir, $filenames);

This specialized command is used to get a listing of the filenames in the directory dir. The list of filenames is written to the local file filenames (on the host).

In the output file, the filenames are separated by "\0" characters.

. and .. are not returned. The filenames are not sorted. Very โ€œtake me as I amโ€ of them ๐Ÿ’…


๐Ÿ“ $g->lsetxattr ($xattr, $val, $vallen, $path);

This is the same as $g->setxattr, but if path is a symbolic link, then it sets an extended attribute of the link itself.

This function depends on the feature linuxxattrs. See also $g->feature-available.


๐Ÿ’œ %statbuf = $g->lstat ($path);

Returns file information for the given path.

This is the same as $g->stat except that if path is a symbolic link, then the link is stat-ed, not the file it refers to. Link gets the attention this time ๐Ÿซถ

This is the same as the lstat(2) system call.

This function is deprecated. In new code, use the lstatns call instead. Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions.

โญ @statbufs = $g->lstatlist ($path, \@names);

This call allows you to perform the $g->lstat operation on multiple files, where all files are in the directory path. names is the list of files from this directory.

On return you get a list of stat structs, with a one-to-one correspondence to the names list. If any name did not exist or could not be lstat'd, then the st_ino field of that structure is set to -1. Good to know, bestie ๐Ÿ˜ญ

This call is intended for programs that want to efficiently list a directory contents without making many round-trips. See also $g->lxattrlist for a similarly efficient call for getting extended attributes.

This function is deprecated. In new code, use the lstatnslist call instead. Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions.

๐Ÿ”ฅ %statbuf = $g->lstatns ($path);

Returns file information for the given path.

This is the same as $g->statns except that if path is a symbolic link, then the link is stat-ed, not the file it refers to.

This is the same as the lstat(2) system call.


๐Ÿฆ‹ @statbufs = $g->lstatnslist ($path, \@names);

This call allows you to perform the $g->lstatns operation on multiple files, where all files are in the directory path. names is the list of files from this directory.

On return you get a list of stat structs, with a one-to-one correspondence to the names list. If any name did not exist or could not be lstat'd, then the st_ino field of that structure is set to -1.

This call is lowkey for the programs that wanna list a whole directory's contents efficiently, without making, like, a million round-trips ๐Ÿ’… See also $g->lxattrlist for a similarly efficient call that gets you the extended attributes.


๐ŸŽ€ $g->luks_add_key ($device, $key, $newkey, $keyslot);

This one adds a brand-new key onto the LUKS device device ๐Ÿ”‘ key is literally any existing key, and it's the thing used to get access to the device. newkey is the new key you're adding. keyslot is the key slot that's gonna get replaced.

Heads up bestie: if keyslot already has a key in it, this command will fail. You gotta run $g->luks_kill_slot first to remove that key. No cap. ๐Ÿ˜ญ

This function depends on the feature luks. See also $g->feature-available.


๐ŸŒธ $g->luks_close ($device);

Closes a LUKS device that was created earlier by $g->luks_open or $g->luks_open_ro โœจ The device parameter has to be the name of the LUKS mapping device (ie. /dev/mapper/mapname) and not the name of the underlying block device. Like, don't get it twisted ๐Ÿซถ

This function depends on the feature luks. See also $g->feature-available.

This function is deprecated. In new code, use the cryptsetup_close call instead.

Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions. (So like, it still works butโ€ฆ why would you ๐Ÿ’€)


โญ $g->luks_format ($device, $key, $keyslot);

This command erases existing data on device and formats the device as a LUKS encrypted device ๐Ÿ˜ณ key is the initial key, which gets added to key slot keyslot. (LUKS supports 8 key slots, numbered 0-7, iykyk.)

This function depends on the feature luks. See also $g->feature-available.


๐Ÿฆ‹ $g->luks_format_cipher ($device, $key, $keyslot, $cipher);

Same energy as $g->luks_format, except it also lets you set the cipher that gets used โœจ

This function depends on the feature luks. See also $g->feature-available.


๐Ÿ’œ $g->luks_kill_slot ($device, $key, $keyslot);

Deletes the key in key slot keyslot from the encrypted LUKS device device ๐Ÿ—‘๏ธ key must be one of the other keys (like, one that actually still exists, bestie).

This function depends on the feature luks. See also $g->feature-available.


๐Ÿ”ฅ $g->luks_open ($device, $key, $mapname);

Opens a block device that's been encrypted according to the Linux Unified Key Setup (LUKS) standard ๐Ÿ‘‘

device is the encrypted block device or partition.

The caller has to supply one of the keys associated with the LUKS block device, in the key parameter.

This creates a new block device called /dev/mapper/mapname. Reads and writes to this block device are decrypted from and encrypted to the underlying device respectively. It's giving translator ๐Ÿงš

If this block device contains LVM volume groups, then calling $g->lvm_scan with the activate parameter true will make them visible.

Use $g->list_dm_devices to list all device mapper devices.

This function depends on the feature luks. See also $g->feature-available.

This function is deprecated. In new code, use the cryptsetup_open call instead.

Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions.


๐Ÿ’– $g->luks_open_ro ($device, $key, $mapname);

Literally the same as $g->luks_open, except a read-only mapping is created ๐Ÿ™ˆ

This function depends on the feature luks. See also $g->feature-available.

This function is deprecated. In new code, use the cryptsetup_open call instead.

Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions.


๐Ÿ“ $uuid = $g->luks_uuid ($device);

Returns the UUID of the LUKS device device โœจ

This function depends on the feature luks. See also $g->feature-available.


๐ŸŒˆ $g->lvcreate ($logvol, $volgroup, $mbytes);

Creates an LVM logical volume called logvol on the volume group volgroup, with size megabytes ๐Ÿ’…

This function depends on the feature lvm2. See also $g->feature-available.


๐ŸŽ€ $g->lvcreate_free ($logvol, $volgroup, $percent);

Creates an LVM logical volume called /dev/volgroup/logvol, using approximately percent % of the free space remaining in the volume group ๐Ÿ‘‘ Most usefully, when percent is 100 this will create the largest possible LV. Slay.

This function depends on the feature lvm2. See also $g->feature-available.


๐Ÿฆ‹ $lv = $g->lvm_canonical_lv_name ($lvname);

Converts alternative naming schemes for LVs that you might find into the canonical name โœจ For example, /dev/mapper/VG-LV gets converted to /dev/VG/LV.

This command returns an error if the lvname parameter doesn't refer to a logical volume. In this case errno will be set to EINVAL ๐Ÿ˜ญ

See also $g->is_lv, $g->canonical_device_name.


๐Ÿงš $g->lvm_clear_filter ();

Undoes the effect of $g->lvm_set_filter. After this, LVM will be able to see every block device ๐Ÿ‘€

This command also clears the LVM cache and performs a volume group scan.


๐Ÿ’€ $g->lvm_remove_all ();

Removes all LVM logical volumes, volume groups and physical volumes. Like, everything. Gone. Not me being dramatic, that's literally what it does ๐Ÿ˜ณ

This function depends on the feature lvm2. See also $g->feature-available.


โญ $g->lvm_scan ($activate);

Scans all block devices and rebuilds the list of LVM physical volumes, volume groups and logical volumes ๐Ÿ”

If the activate parameter is true then newly found volume groups and logical volumes are activated, meaning the LV /dev/VG/LV devices become visible.

When a libguestfs handle is launched it scans for existing devices, so you don't normally need to use this API. But it's super useful when you've added a new device or deleted an existing device (such as when the $g->luks_open API is used) ๐Ÿ’…


๐ŸŒธ $g->lvm_set_filter (\@devices);

Sets the LVM device filter so that LVM will only be able to "see" the block devices in the list devices, and will ignore all other attached block devices ๐Ÿ™ˆ

Where disk image(s) contain duplicate PVs or VGs, this command is useful to get LVM to ignore the duplicates, otherwise LVM can get confused. Note also there are two types of duplication possible: either cloned PVs/VGs which have identical UUIDs; or VGs that are not cloned but just happen to have the same name. In normal operation you cannot create this situation, but you can do it outside LVM, eg. by cloning disk images or by bit twiddling inside the LVM metadata. (Chaotic behaviour, honestly.)

This command also clears the LVM cache and performs a volume group scan.

You can filter whole block devices or individual partitions.

You cannot use this if any VG is currently in use (eg. contains a mounted filesystem), even if you are not filtering out that VG. Periodt.

This function depends on the feature lvm2. See also $g->feature-available.


๐Ÿ”‘ $g->lvremove ($device);

Removes an LVM logical volume device, where device is the path to the LV, such as /dev/VG/LV ๐Ÿ—‘๏ธ

You can also remove all LVs in a volume group by specifying the VG name, /dev/VG. Convenient!

This function depends on the feature lvm2. See also $g->feature-available.


๐ŸŽ€ $g->lvrename ($logvol, $newlogvol);

Renames a logical volume logvol with the new name newlogvol โœจ


๐Ÿ’œ $g->lvresize ($device, $mbytes);

Resizes (expands or shrinks) an existing LVM logical volume to mbytes ๐Ÿ“ When reducing, data in the reduced part is lost. Like, actually gone. Be careful ๐Ÿ˜ญ

This function depends on the feature lvm2. See also $g->feature-available.


๐Ÿฆ‹ $g->lvresize_free ($lv, $percent);

Expands an existing logical volume lv so that it fills pc % of the remaining free space in the volume group ๐ŸŒฑ Commonly you'd call this with pc = 100, which expands the logical volume as much as possible, using all remaining free space in the volume group. Maximum vibes, maximum LV.

This function depends on the feature lvm2. See also $g->feature-available.


โญ @logvols = $g->lvs ();

Lists all the logical volumes detected ๐Ÿ‘‘ This is the equivalent of the lvs(8) command.

It returns a list of the logical volume device names (eg. /dev/VolGroup00/LogVol00).

See also $g->lvs_full, $g->list_filesystems.

This function depends on the feature lvm2. See also $g->feature-available.


โœจ @logvols = $g->lvs_full ();

Lists all the logical volumes detected. Same equivalence to the lvs(8) command as above, but the full version includes all fields ๐Ÿ’…

This function depends on the feature lvm2. See also $g->feature-available.


๐ŸŒˆ $uuid = $g->lvuuid ($device);

Returns the UUID of the LVM LV device โœจ


๐Ÿ“ @xattrs = $g->lxattrlist ($path, \@names);

Lets you get the extended attributes of multiple files, where all the files are in the directory path ๐Ÿ’– names is the list of files from this directory.

On return you get a flat list of xattr structs which must be interpreted sequentially. The first xattr struct always has a zero-length attrname. attrval in this struct is zero-length to indicate there was an error doing $g->lgetxattr for this file, or is a C string which is a decimal number (the number of following attributes for this file, which could be 0). Then after the first xattr struct are the zero or more attributes for the first named file. This repeats for the second and subsequent files. Okay so it's giving nesting-doll energy, but you got this ๐Ÿซถ

This call is intended for programs that want to efficiently list a directory contents without making many round-trips. See also $g->lstatlist for a similarly efficient call for getting standard stats.

This function depends on the feature linuxxattrs. See also $g->feature-available.


๐Ÿ‘‘ $disks = $g->max_disks ();

Returns the maximum number of disks that may be added to a handle (eg. by $g->add_drive_opts and similar calls) ๐Ÿ’…

This function was added in libguestfs 1.19.7. In previous versions of libguestfs the limit was 25. Iconic history lesson, honestly.

See "MAXIMUM NUMBER OF DISKS" in guestfs(3) for additional information on this topic.

$g->md_create

$g->md_create ($name, \@devices [, missingbitmap => $missingbitmap] [,
nrdevices => $nrdevices] [, spare => $spare] [, chunk => $chunk] [,
level => $level]);

Okay so this one builds you a whole Linux md (RAID) device, bestie. It's named name and it lives on the devices in the list devices. Very main character energy.

The optional parameters are:

  • missingbitmap โ€” a bitmap of missing devices ๐Ÿ’€. If a bit is set, that means a missing device gets added to the array. The least significant bit corresponds to the first device in the array. Some examples so it actually clicks: if devices = ["/dev/sda"] and missingbitmap = 0x1 then the resulting array would be [<missing>, "/dev/sda"]. And if devices = ["/dev/sda"] and missingbitmap = 0x2 then the resulting array would be ["/dev/sda", <missing>]. Defaults to 0 (no missing devices, we love a complete set). The length of devices + the number of bits set in missingbitmap must equal nrdevices + spare โ€” that's the math, no cap.
  • nrdevices โ€” the number of active RAID devices. If you don't set it, it defaults to the length of devices plus the number of bits set in missingbitmap.
  • spare โ€” the number of spare devices. Not set? Defaults to 0.
  • chunk โ€” the chunk size in bytes. Warning though: the chunk parameter does not make sense, and should not be specified, when level is raid1 (which is the default; see below). So likeโ€ฆ don't.
  • level โ€” the RAID level, which can be one of: linear, raid0, 0, stripe, raid1, 1, mirror, raid4, 4, raid5, 5, raid6, 6, raid10, 10. Some of these are synonymous, and more levels may be added in future. If not set, this defaults to raid1.

This function depends on the feature mdadm. See also $g->feature-available.


%info = $g->md_detail

%info = $g->md_detail ($md);

This command exposes the output of mdadm -DY <md>. The following fields are usually present in the returned hash. Other fields may also be present (surprise bonus fields, we love that for us):

  • level โ€” the raid level of the MD device.
  • devices โ€” the number of underlying devices in the MD device.
  • metadata โ€” the metadata version used.
  • uuid โ€” the UUID of the MD device.
  • name โ€” the name of the MD device.

This function depends on the feature mdadm. See also $g->feature-available.


@devices = $g->md_stat

@devices = $g->md_stat ($md);

This call returns a list of the underlying devices which make up the single software RAID array device md. ๐Ÿงš

To get a list of software RAID devices, call $g->list_md_devices.

Each structure returned corresponds to one device along with additional status information:

  • mdstat_device โ€” the name of the underlying device.
  • mdstat_index โ€” the index of this device within the array.
  • mdstat_flags โ€” flags associated with this device. This is a string containing (in no specific order) zero or more of the following flags:
    • W write-mostly
    • F device is faulty
    • S device is a RAID spare
    • R replacement

This function depends on the feature mdadm. See also $g->feature-available.


$g->md_stop

$g->md_stop ($md);

This command deactivates the MD array named md. The device is stopped, but it is not destroyed or zeroed โ€” so it's giving "napping, not gone" energy. ๐Ÿ˜ด

This function depends on the feature mdadm. See also $g->feature-available.


$g->mkdir

$g->mkdir ($path);

Create a directory named path. Simple, iconic, does exactly what it says. ๐ŸŽ€


$g->mkdir_mode

$g->mkdir_mode ($path, $mode);

This command creates a directory, setting the initial permissions of the directory to mode.

For common Linux filesystems, the actual mode which is set will be mode & ~umask & 01777. Non-native-Linux filesystems may interpret the mode in other ways (they're quirky like that, no judgement).

See also $g->mkdir, $g->umask.


$g->mkdir_p

$g->mkdir_p ($path);

Create a directory named path, creating any parent directories as necessary. This is like the mkdir -p shell command โ€” parents included, zero extra effort. โœจ


$dir = $g->mkdtemp

$dir = $g->mkdtemp ($tmpl);

This command creates a temporary directory. The tmpl parameter should be a full pathname for the temporary directory name with the final six characters being XXXXXX. Six X's, that's the vibe check.

For example: /tmp/myprogXXXXXX or /Temp/myprogXXXXXX, the second one being suitable for Windows filesystems.

The name of the temporary directory that was created is returned.

The temporary directory is created with mode 0700 and is owned by root. ๐Ÿ”’

The caller is responsible for deleting the temporary directory and its contents after use โ€” yes, you, bestie. Clean up your mess.

See also: mkdtemp(3)


$g->mke2fs

$g->mke2fs ($device [, blockscount => $blockscount] [, blocksize =>
$blocksize] [, fragsize => $fragsize] [, blockspergroup =>
$blockspergroup] [, numberofgroups => $numberofgroups] [, bytesperinode
=> $bytesperinode] [, inodesize => $inodesize] [, journalsize =>
$journalsize] [, numberofinodes => $numberofinodes] [, stridesize =>
$stridesize] [, stripewidth => $stripewidth] [, maxonlineresize =>
$maxonlineresize] [, reservedblockspercentage =>
$reservedblockspercentage] [, mmpupdateinterval => $mmpupdateinterval]
[, journaldevice => $journaldevice] [, label => $label] [,
lastmounteddir => $lastmounteddir] [, creatoros => $creatoros] [, fstype
=> $fstype] [, usagetype => $usagetype] [, uuid => $uuid] [, forcecreate
=> $forcecreate] [, writesbandgrouponly => $writesbandgrouponly] [,
lazyitableinit => $lazyitableinit] [, lazyjournalinit =>
$lazyjournalinit] [, testfs => $testfs] [, discard => $discard] [,
quotatype => $quotatype] [, extent => $extent] [, filetype => $filetype]
[, flexbg => $flexbg] [, hasjournal => $hasjournal] [, journaldev =>
$journaldev] [, largefile => $largefile] [, quota => $quota] [,
resizeinode => $resizeinode] [, sparsesuper => $sparsesuper] [, uninitbg
=> $uninitbg]);

mke2fs is used to create an ext2, ext3, or ext4 filesystem on device. Look at that option list โ€” she's THRIVING. ๐Ÿซถ

The optional blockscount is the size of the filesystem in blocks. If omitted it defaults to the size of device. Note if the filesystem is too small to contain a journal, mke2fs will silently create an ext2 filesystem instead. Silently. Rude, but okay. ๐Ÿ™ˆ


$g->mke2fs_J

$g->mke2fs_J ($fstype, $blocksize, $device, $journal);

This creates an ext2/3/4 filesystem on device with an external journal on journal. It is equivalent to the command:

mke2fs -t fstype -b blocksize -J device=<journal> <device>

See also $g->mke2journal.

This function is deprecated. In new code, use the mke2fs call instead. Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions. So likeโ€ฆ it still works, but it's giving legacy energy. ๐Ÿ’€

$g->mke2fs_JL

$g->mke2fs_JL ($fstype, $blocksize, $device, $label);

This creates an ext2/3/4 filesystem on device with an external journal on the journal labeled label.

See also $g->mke2journal_L.

This function is deprecated. In new code, use the mke2fs call instead. Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions.

$g->mke2fs_JU

$g->mke2fs_JU ($fstype, $blocksize, $device, $uuid);

This creates an ext2/3/4 filesystem on device with an external journal on the journal with UUID uuid.

See also $g->mke2journal_U.

This function depends on the feature linuxfsuuid. See also $g->feature-available.

This function is deprecated. In new code, use the mke2fs call instead. Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions.

$g->mke2journal

$g->mke2journal ($blocksize, $device);

This creates an ext2 external journal on device. It is equivalent to the command:

mke2fs -O journal_dev -b blocksize device
This function is deprecated. In new code, use the mke2fs call instead. Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions.

$g->mke2journal_L

$g->mke2journal_L ($blocksize, $label, $device);

This creates an ext2 external journal on device with label label.

This function is deprecated. In new code, use the mke2fs call instead. Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions.

$g->mke2journal_U

$g->mke2journal_U ($blocksize, $uuid, $device);

This creates an ext2 external journal on device with UUID uuid.

This function depends on the feature linuxfsuuid. See also $g->feature-available.

This function is deprecated. In new code, use the mke2fs call instead. Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions.

$g->mkfifo

$g->mkfifo ($mode, $path);

This call creates a FIFO (named pipe) called path with mode mode. It is just a convenient wrapper around $g->mknod. ๐ŸŽ€

Unlike with $g->mknod, mode must contain only permissions bits.

The mode actually set is affected by the umask.

This function depends on the feature mknod. See also $g->feature-available.


$g->mkfs

$g->mkfs ($fstype, $device [, blocksize => $blocksize] [, features =>
$features] [, inode => $inode] [, sectorsize => $sectorsize] [, label =>
$label]);

This function creates a filesystem on device. The filesystem type is fstype, for example ext3.

The optional arguments are:

  • blocksize โ€” the filesystem block size. Supported block sizes depend on the filesystem type, but typically they are 1024, 2048 or 4096 for Linux ext2/3 filesystems. For VFAT and NTFS the blocksize parameter is treated as the requested cluster size. For UFS block sizes, please see mkfs.ufs(8).
  • features โ€” this passes the -O parameter to the external mkfs program. For certain filesystem types, this allows extra filesystem features to be selected. See mke2fs(8) and mkfs.ufs(8) for more details. You cannot use this optional parameter with the gfs or gfs2 filesystem type. ๐Ÿšซ
  • "inode" โ€” this one passes the -I parameter straight through to the external mke2fs(8) program, and that's what sets the inode size (only for ext2/3/4 filesystems at the moment, iykyk). โœจ
  • "sectorsize" โ€” and this cutie passes the -S parameter to the external mkfs.ufs(8) program, which sets the sector size for the ufs filesystem. ๐Ÿ’…
$g->mkfs_opts ($fstype, $device [, blocksize => $blocksize] [, features => $features] [, inode => $inode] [, sectorsize => $sectorsize] [, label => $label]);

okay so this is literally just an alias of "mkfs". that's it. that's the whole tea. ๐Ÿ“

$g->mkfs_b ($fstype, $blocksize, $device);

Very similar vibe to "$g->mkfs", except this one lets you control the block size of the filesystem you're making ๐ŸŽ€. Which block sizes are supported depends on the filesystem type, but bestie, typically it's only 1024, 2048 or 4096. no cap.

For VFAT and NTFS, the "blocksize" parameter gets treated as the requested cluster size. noted. ๐Ÿ“

This function is deprecated ๐Ÿ˜ญ. In new code, use the "mkfs" call instead. Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions. so like. be aware. ๐Ÿ’€
$g->mkfs_btrfs (\@devices [, allocstart => $allocstart] [, bytecount => $bytecount] [, datatype => $datatype] [, leafsize => $leafsize] [, label => $label] [, metadata => $metadata] [, nodesize => $nodesize] [, sectorsize => $sectorsize]);

Create a btrfs filesystem, with every single configurable available to you โ€” main character energy fr fr ๐Ÿ‘‘. For more info on what all those optional arguments actually do, go see mkfs.btrfs(8).

Since btrfs filesystems can span multiple devices, this call takes a non-empty list of devices โ€” plural, bestie, don't come at it with just one device and expect the world. ๐ŸŒˆ

If you just want to create general filesystems, use "$g->mkfs".

This function depends on the feature "btrfs". See also "$g->feature-available". ๐Ÿ”ฅ


$g->mklost_and_found ($mountpoint);

Makes the "lost+found" directory โ€” the one that's normally chilling in the root directory of an ext2/3/4 filesystem. "mountpoint" is the directory under which we try to create the "lost+found" directory. cute. ๐ŸŽ€


$g->mkmountpoint ($exemptpath);

Okay so "$g->mkmountpoint" and "$g->rmmountpoint" are these specialized calls you can use to create extra mountpoints before you mount the first filesystem. Very niche, very "i have a specific problem", love that for you. ๐Ÿฆ‹

These calls are only necessary in some very limited circumstances, mainly the case where you want to mount a mix of unrelated and/or read-only filesystems together.

For example โ€” live CDs often contain a "Russian doll" nest of filesystems: an ISO outer layer, with a squashfs image inside, with an ext2/3 image inside that. nesting dolls but make it storage ๐Ÿ’…. You can unpack it like this in guestfish:

add-ro Fedora-11-i686-Live.iso
run
mkmountpoint /cd
mkmountpoint /sqsh
mkmountpoint /ext3fs
mount /dev/sda /cd
mount-loop /cd/LiveOS/squashfs.img /sqsh
mount-loop /sqsh/LiveOS/ext3fs.img /ext3fs

And now the inner filesystem is unpacked under the /ext3fs mountpoint. slay. โœจ

Heads up bestie: "$g->mkmountpoint" is not compatible with "$g->umount_all". Mix these calls and you may get unexpected errors ๐Ÿ˜ญ. It is safest to manually unmount filesystems and remove mountpoints after use. fr fr, do it manually.

"$g->umount_all" unmounts filesystems by sorting the paths longest first, so for this to work with manual mountpoints, you must make sure the innermost mountpoints have the longest pathnames โ€” exactly like in the example code above. ๐Ÿ‘€

For more details see https://bugzilla.redhat.com/show_bug.cgi?id=599503

Autosync [see "$g->set_autosync", this is set by default on handles] can cause "$g->umount_all" to be called when the handle is closed, which can also trigger these issues. so like. keep that in mind. ๐Ÿ™ˆ


$g->mknod ($mode, $devmajor, $devminor, $path);

This call creates block or character special devices, or named pipes (FIFOs). very giving "i make the filesystem itself" ๐ŸŽ€

The "mode" parameter should be the mode, using the standard constants. "devmajor" and "devminor" are the device major and minor numbers โ€” only used when creating block and character special devices.

Note that, just like mknod(2), the mode must be bitwise OR'd with S_IFBLK, S_IFCHR, S_IFIFO or S_IFSOCK (otherwise this call just creates a regular file ๐Ÿ˜ญ). These constants are available in the standard Linux header files, or you can use "$g->mknod_b", "$g->mknod_c" or "$g->mkfifo" โ€” those are wrappers around this command which bitwise OR in the appropriate constant for you. they do the math so u don't have to ๐Ÿ’…

The mode actually set is affected by the umask.

This function depends on the feature "mknod". See also "$g->feature-available". ๐Ÿ”ฅ


$g->mknod_b ($mode, $devmajor, $devminor, $path);

Creates a block device node called "path" with mode "mode" and device major/minor "devmajor" and "devminor". It's just a convenient little wrapper around "$g->mknod". ๐Ÿซถ

Unlike with "$g->mknod", "mode" must contain only permissions bits. no sneaky type bits in here.

The mode actually set is affected by the umask.

This function depends on the feature "mknod". See also "$g->feature-available".


$g->mknod_c ($mode, $devmajor, $devminor, $path);

Same deal, but this one creates a char device node called "path" with mode "mode" and device major/minor "devmajor" and "devminor". Also just a convenient wrapper around "$g->mknod". โญ

Unlike with "$g->mknod", "mode" must contain only permissions bits.

The mode actually set is affected by the umask.

This function depends on the feature "mknod". See also "$g->feature-available".


$g->mksquashfs ($path, $filename [, compress => $compress] [, excludes => $excludes]);

Create a squashfs filesystem for the specified "path". ๐Ÿฆ‹

The optional "compress" flag controls compression. If it's not given, then the output gets compressed using "gzip". Otherwise, one of these strings may be given to select the compression type of the squashfs: "gzip", "lzma", "lzo", "lz4", "xz". pick ur fighter ๐Ÿ’…

The other optional arguments are:

  • "excludes" โ€” a list of wildcards. Files are excluded if they match any of the wildcards.
Please note that this API may fail when used to compress directories with large files, such as the resulting squashfs being over 3GB big ๐Ÿ˜ญ. like. it's giving "we tried".

This function depends on the feature "squashfs". See also "$g->feature-available".


$g->mkswap ($device [, label => $label] [, uuid => $uuid]);

Create a Linux swap partition on "device". ๐ŸŽ€

The option arguments "label" and "uuid" allow you to set the label and/or UUID of the new swap partition. so organized of you.


$g->mkswap_opts ($device [, label => $label] [, uuid => $uuid]);

This is literally an alias of "mkswap". same thing, different name, we love a rebrand. โœจ


$g->mkswap_L ($label, $device);

Create a swap partition on "device" with label "label". ๐Ÿท๏ธ

Note that you cannot attach a swap label to a block device (eg. /dev/sda), just to a partition. This appears to be a limitation of the kernel or swap tools. so like. not us. it's them. ๐Ÿ’€
This function is deprecated. In new code, use the "mkswap" call instead. Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions.

$g->mkswap_U ($uuid, $device);

Create a swap partition on "device" with UUID "uuid". ๐Ÿ†”

This function depends on the feature "linuxfsuuid". See also "$g->feature-available".

This function is deprecated. In new code, use the "mkswap" call instead. Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions.

$g->mkswap_file ($path);

Create a swap file. ๐ŸŒธ

This command just writes a swap file signature to an existing file โ€” it does not make the file for you, bestie. To create the file itself, use something like "$g->fallocate". ๐Ÿ’…


$path = $g->mktemp ($tmpl [, suffix => $suffix]);

This command creates a temporary file. ๐ŸŽ€ The "tmpl" parameter should be a full pathname for the temporary directory name, with the final six characters being "XXXXXX".

For example: "/tmp/myprogXXXXXX" or "/Temp/myprogXXXXXX" โ€” the second one being suitable for Windows filesystems. thoughtful. โœจ

The name of the temporary file that was created is returned. ๐Ÿ‘‘

The temporary file is created with mode 0600 and is owned by root.

The caller is responsible for deleting the temporary file after use. yes, you. it's you. don't leave it there ๐Ÿ˜ญ

If the optional "suffix" parameter is given, then the suffix (eg. ".txt") is appended to the temporary name.

See also: "$g->mkdtemp". ๐Ÿซถ


$g->modprobe ($modulename);

This loads a kernel module in the appliance. very "i know what i'm doing" of it ๐Ÿ”ฅ

This function depends on the feature "linuxmodules". See also "$g->feature-available".


$g->mount ($mountable, $mountpoint);

Mount a guest disk at a position in the filesystem. ๐Ÿ’– Block devices are named /dev/sda, /dev/sdb and so on, exactly as they were added to the guest. If those block devices contain partitions, they'll have the usual names (eg. /dev/sda1). Also LVM /dev/VG/LV-style names can be used, or 'mountable' strings returned by "$g->list_filesystems" or "$g->inspect_get_mountpoints". lots of options, all valid, we love flexibility. ๐ŸŒˆ

The rules are the same as for mount(2): a filesystem must first be mounted on / before others can be mounted. Other filesystems can only be mounted on directories which already exist. no inventing directories out of thin air, bestie. โœ‹

The mounted filesystem is writable, if we have sufficient permissions on the underlying device.

Before libguestfs 1.13.16, this call implicitly added the options "sync" and "noatime". The "sync" option greatly slowed writes and caused many problems for users ๐Ÿ˜ญ. If your program might need to work with older versions of libguestfs, use "$g->mount_options" instead (using an empty string for the first parameter if you don't want any options). iykyk.

$g->mount_9p ($mounttag, $mountpoint [, options => $options]);

This call does nothing and returns an error. ๐Ÿ’€ like it's literally not doing the thing. it's giving "we don't do that here".

This function is deprecated. There is no replacement. Consult the API documentation in guestfs(3) for further information. Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions.

$g->mount_local ($localmountpoint [, readonly => $readonly] [, options => $options] [, cachetimeout => $cachetimeout] [, debugcalls => $debugcalls]);

This call exports the libguestfs-accessible filesystem to a local mountpoint (directory) called "localmountpoint". ๐ŸŽ€ Ordinary reads and writes to files and directories under "localmountpoint" are redirected through libguestfs. it's giving "portal to another filesystem" ๐ŸŒ€

If the optional "readonly" flag is set to true, then writes to the filesystem return error "EROFS". no writing for u. ๐Ÿ™ˆ

Okay so "options" is a comma-separated list of mount options โ€” peep guestmount(1) for some genuinely useful ones. ๐Ÿ‘€

"cachetimeout" sets the timeout (in seconds) for cached directory entries, and the default is 60 seconds. guestmount(1) has the further tea. โ˜•

And if "debugcalls" is set to true, then you get additional debugging information generated for every FUSE call. Every single one. ๐Ÿซถ

When $g->mount_local returns, the filesystem is ready but not processing requests โ€” meaning access to it will block. ๐Ÿ˜ญ You have to call $g->mount_local_run to run the main loop. Full documentation lives in "MOUNT LOCAL" in guestfs(3). ๐Ÿ’…


$g->mount_local_run ();

Runs the main loop which translates kernel calls to libguestfs calls. ๐Ÿ”ฅ

This should only be called after $g->mount_local returns successfully, and the call will not return until the filesystem is unmounted. It's giving commitment, honestly.

Note: you must not make concurrent libguestfs calls on the same handle from another thread. Fr fr, don't do it, bestie. ๐Ÿ’€

You may call this from a different thread than the one which called $g->mount_local, subject to the usual rules for threads and libguestfs (see "MULTIPLE HANDLES AND MULTIPLE THREADS" in guestfs(3)).

See "MOUNT LOCAL" in guestfs(3) for full documentation. โœจ

$g->mount_loop ($file, $mountpoint);

This one lets you mount file (a filesystem image in a file) on a mount point. It's entirely equivalent to:

mount -o loop file mountpoint

No cap, that's literally it. ๐ŸŽ€

$g->mount_options ($options, $mountable, $mountpoint);

Same as $g->mount, but it lets you set the mount options like the mount(8) -o flag. Slay.

If options is an empty string, then no options are passed โ€” everything defaults to whatever the filesystem uses. ๐Ÿฆ‹

$g->mount_ro ($mountable, $mountpoint);

Same as $g->mount, except it mounts the filesystem with the read-only (-o ro) flag. Protecting your fave filesystem like a true main character. ๐Ÿ’–

$g->mount_vfs ($options, $vfstype, $mountable, $mountpoint);

Same as $g->mount, but it lets you set both the mount options and the vfstype, like the mount(8) -o and -t flags. ๐ŸŒˆ

$device = $g->mountable_device ($mountable);

Returns the device name of a mountable. In quite a lot of cases, the mountable is the device name.

But that does not apply for btrfs subvolumes, where the mountable is a combination of both the device name and the subvolume path (see also $g->mountable_subvolume to extract the subvolume path of the mountable, if any). ๐Ÿงš

$subvolume = $g->mountable_subvolume ($mountable);

Returns the subvolume path of a mountable. Btrfs subvolume mountables are a combination of both the device name and the subvolume path (see also $g->mountable_device to extract the device of the mountable). โœจ

If the mountable does not represent a btrfs subvolume, then this function fails and the errno is set to EINVAL. ๐Ÿ’€

%mps = $g->mountpoints ();

This call is similar to $g->mounts โ€” but that one returns a list of devices. This one returns a hash table (map) of device name to directory where the device is mounted. Map girlie behavior, honestly. ๐Ÿ—บ๏ธ

@devices = $g->mounts ();

Returns the list of currently mounted filesystems โ€” specifically the list of devices (eg. /dev/sda1, /dev/VG/LV). ๐Ÿ‘‘

Some internal mounts are not shown. ๐Ÿ™ˆ

See also: $g->mountpoints.

$g->mv ($src, $dest);

Moves a file from src to dest, where dest is either a destination filename or a destination directory. ๐Ÿ’…

See also: $g->rename.

$nrdisks = $g->nr_devices ();

Returns the number of whole block devices that were added. This is the same as the number of devices that would be returned if you called $g->list_devices. ๐ŸŽ€

Wanna find out the maximum number of devices that could be added? Call $g->max_disks. Iconic. โœจ

$status = $g->ntfs_3g_probe ($rw, $device);

Runs the ntfs-3g.probe(8) command, which probes an NTFS device for mountability. Not all NTFS volumes can be mounted read-write, and some cannot be mounted at all. ๐Ÿ˜ญ

rw is a boolean flag. Set it to true if you want to test whether the volume can be mounted read-write, and false if you want to test whether it can be mounted read-only.

The return value is an integer: 0 if the operation would succeed, or some non-zero value documented in the ntfs-3g.probe(8) manual page.

This function depends on the feature "ntfs3g". See also $g->feature-available. ๐Ÿฆ‹

$g->ntfscat_i ($device, $inode, $filename);

Downloads a file given its inode from an NTFS filesystem, and saves it as filename on the local machine. ๐ŸŒธ

This lets you download some otherwise inaccessible files โ€” like the ones within the $Extend folder. Yes, that folder. ๐Ÿ‘€

The filesystem from which to extract the file must be unmounted, otherwise the call will fail. No cap.

$g->ntfsclone_in ($backupfile, $device);

Restores backupfile (from a previous call to $g->ntfsclone_out) to device, overwriting any existing contents of this device. ๐Ÿ’€

This function depends on the feature "ntfs3g". See also $g->feature-available.

$g->ntfsclone_out ($device, $backupfile [, metadataonly => $metadataonly] [, rescue => $rescue] [, ignorefscheck => $ignorefscheck] [, preservetimestamps => $preservetimestamps] [, force => $force]);

Streams the NTFS filesystem device to the local file backupfile. The format used for the backup file is the special format used by the ntfsclone(8) tool. โœจ

If the optional metadataonly flag is true, then only the metadata is saved โ€” losing all the user data. It's useful for diagnosing some filesystem problems, fr.

The optional rescue, ignorefscheck, preservetimestamps and force flags have precise meanings detailed in the ntfsclone(8) man page. Don't just vibe-guess them, bestie. ๐Ÿซถ

Use $g->ntfsclone_in to restore the file back to a libguestfs device.

This function depends on the feature "ntfs3g". See also $g->feature-available.

$g->ntfsfix ($device [, clearbadsectors => $clearbadsectors]);

Repairs some fundamental NTFS inconsistencies, resets the NTFS journal file, and schedules an NTFS consistency check for the first boot into Windows. ๐Ÿ”ฅ

This is not an equivalent of Windows chkdsk โ€” it does not scan the filesystem for inconsistencies. Important distinction, okay? ๐Ÿ’…

The optional clearbadsectors flag clears the list of bad sectors, which is useful after cloning a disk with bad sectors to a new disk. ๐Ÿฉน

This function depends on the feature "ntfs3g". See also $g->feature-available.

$g->ntfsresize ($device [, size => $size] [, force => $force]);

Resizes an NTFS filesystem, expanding or shrinking it to the size of the underlying device. ๐ŸŽ€

The optional parameters are:

  • "size" โ€” the new size (in bytes) of the filesystem. If omitted, the filesystem is resized to fit the container (eg. partition).
  • "force" โ€” if this option is true, then force the resize of the filesystem even if the filesystem is marked as requiring a consistency check.

After the resize operation, the filesystem is always marked as requiring a consistency check (for safety). You have to boot into Windows to perform this check and clear this condition. If you don't set the force option, then it is not possible to call $g->ntfsresize multiple times on a single filesystem without booting into Windows between each resize. ๐Ÿ˜ญ

See also ntfsresize(8).

This function depends on the feature "ntfsprogs". See also $g->feature-available.

$g->ntfsresize_opts ($device [, size => $size] [, force => $force]);

This is an alias of "ntfsresize". Same energy, different name. ๐Ÿ’ซ

$g->ntfsresize_size ($device, $size);

Same as $g->ntfsresize, except it lets you specify the new size (in bytes) explicitly. ๐ŸŽฏ

This function depends on the feature "ntfsprogs". See also $g->feature-available.

Deprecated, bestie. In new code, use the "ntfsresize" call instead. Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions. So likeโ€ฆ don't. ๐Ÿ’€

$g->parse_environment ();

Parses the program's environment and sets flags in the handle accordingly. For example, if LIBGUESTFS_DEBUG=1, then the 'verbose' flag is set in the handle. โœจ

Most programs do not need to call this โ€” it is done implicitly when you call $g->create.

See "ENVIRONMENT VARIABLES" in guestfs(3) for a list of environment variables that can affect libguestfs handles. See also "guestfs_create_flags" in guestfs(3), and $g->parse_environment_list. ๐ŸŒˆ

$g->parse_environment_list (\@environment);

Parses the list of strings in the argument environment and sets flags in the handle accordingly. For example, if LIBGUESTFS_DEBUG=1 is a string in the list, then the 'verbose' flag is set in the handle. ๐Ÿงš

This is the same as $g->parse_environment, except it parses an explicit list of strings instead of the program's environment. ๐Ÿ’…

$g->part_add ($device, $prlogex, $startsect, $endsect);

Adds a partition to device. If there is no partition table on the device, call $g->part_init first. ๐Ÿ› ๏ธ

prlogex is the type of partition. Normally you should pass "p" or "primary" here, but MBR partition tables also support "l" (or "logical") and "e" (or "extended") partition types.

startsect and endsect are the start and end of the partition in sectors. endsect may be negative, which means it counts backwards from the end of the disk (-1 is the last sector). ๐Ÿ”ฅ

Creating a partition which covers the whole disk is not so easy โ€” use $g->part_disk to do that.

$g->part_del ($device, $partnum);

Deletes the partition numbered partnum on device. ๐Ÿ—‘๏ธ

Heads up, bestie: in the case of MBR partitioning, deleting an extended partition also deletes any logical partitions it contains. Bye bye. ๐Ÿ’€

$g->part_disk ($device, $parttype);

This command is simply a combination of $g->part_init followed by $g->part_add, creating a single primary partition covering the whole disk. ๐Ÿ‘‘

parttype is the partition table type, usually "mbr" or "gpt", but other possible values are described in $g->part_init. ๐ŸŒŸ

$g->part_expand_gpt ($device);

Okay this one is literally the "make room, bestie" of partition surgery ๐Ÿฉบโœจ It moves your backup GPT data structures to the end of the disk, which slaps in the very specific case of an in-place image expand โ€” because, lowkey annoying, the disk space after the backup GPT header just isn't usable otherwise. It's exactly equivalent to sgdisk -e. Periodt.

See also sgdisk(8).

This function depends on the feature "gdisk". See also $g->feature-available.


$bootable = $g->part_get_bootable ($device, $partnum);

Returns true if partition partnum on device has the bootable flag set. Like, does this partition have main character energy at boot time or not ๐Ÿ’…

See also $g->part_set_bootable.

$guid = $g->part_get_disk_guid ($device);

Returns the disk identifier (GUID) of a GPT-partitioned device. Heads up though: behaviour is undefined for other partition types, so don't come crying to me if you run this on a non-GPT disk ๐Ÿ˜ญ

$attributes = $g->part_get_gpt_attributes ($device, $partnum);

Returns the attribute flags of numbered GPT partition partnum. If you try this on MBR partitions you get an error โ€” no attributes for you, bestie ๐Ÿšซ

$guid = $g->part_get_gpt_guid ($device, $partnum);

Returns the GUID of numbered GPT partition partnum. That's it, that's the whole vibe ๐ŸŽ€

$guid = $g->part_get_gpt_type ($device, $partnum);

Returns the type GUID of numbered GPT partition partnum. Different thing from the partition GUID, iykyk.

$idbyte = $g->part_get_mbr_id ($device, $partnum);

Returns the MBR type byte (also known as the ID byte) from the numbered partition partnum.

โš ๏ธ Note that only MBR (old DOS-style) partitions have type bytes. You will get undefined results for other partition table types (see $g->part_get_parttype). So fr fr, check your table type first.

$partitiontype = $g->part_get_mbr_part_type ($device, $partnum);

Returns the partition type of an MBR partition numbered partnum on device device.

It returns "primary", "logical", or "extended" โ€” the classic trio ๐ŸŒˆ

$name = $g->part_get_name ($device, $partnum);

Gets the partition name on partition numbered partnum on device device. And yeah, partitions are numbered from 1, not 0, before anyone @s me ๐Ÿ™ˆ

The partition name can only be read on certain types of partition table โ€” this works on "gpt" but not on "mbr" partitions. Sorry MBR girlies ๐Ÿ’€

$parttype = $g->part_get_parttype ($device);

This one examines the partition table on device and returns the partition table type (format) being used. A little vibe check for your disk ๐Ÿ”

Common return values include: "msdos" (a DOS/Windows style MBR partition table) and "gpt" (a GPT/EFI-style partition table). Other values are possible, although unusual. See $g->part_init for a full list.


$g->part_init ($device, $parttype);

This creates an empty partition table on device of one of the partition types listed below. Usually parttype should be either "msdos" or "gpt" (for large disks).

Initially there are no partitions โ€” it's a blank canvas, bestie ๐ŸŽจ Following this, you should call $g->part_add for each partition required.

Possible values for parttype are:

  • "efi", "gpt" โ€” Intel EFI / GPT partition table. This is recommended for >= 2 TB partitions that will be accessed from Linux and Intel-based Mac OS X. It also has limited backwards compatibility with the "mbr" format.
  • "mbr", "msdos" โ€” The standard PC "Master Boot Record" (MBR) format used by MS-DOS and Windows. This partition type will only work for device sizes up to 2 TB. For large disks we recommend using "gpt".

Other partition table types that may work but are not supported include:

  • "aix" โ€” AIX disk labels.
  • "amiga", "rdb" โ€” Amiga "Rigid Disk Block" format.
  • "bsd" โ€” BSD disk labels.
  • "dasd" โ€” DASD, used on IBM mainframes.
  • "dvh" โ€” MIPS/SGI volumes.
  • "mac" โ€” Old Mac partition format. Modern Macs use "gpt".
  • "pc98" โ€” NEC PC-98 format, common in Japan apparently.
  • "sun" โ€” Sun disk labels.

@partitions = $g->part_list ($device);

This parses the partition table on device and returns the list of partitions found. The receipts, bestie ๐Ÿงพโœจ

The fields in the returned structure are:

  • "part_num" โ€” Partition number, counting from 1.
  • "part_start" โ€” Start of the partition in bytes. To get sectors you have to divide by the device's sector size, see $g->blockdev_getss.
  • "part_end" โ€” End of the partition in bytes.
  • "part_size" โ€” Size of the partition in bytes.

$g->part_resize ($device, $partnum, $endsect);

Resizes the partition numbered partnum on device by moving the end position ๐Ÿ“

โš ๏ธ Note that this does not modify any filesystem present in the partition. If you wish to do this, you will need to use filesystem resizing commands like $g->resize2fs.

And here's the order-of-operations tea โ˜•: when growing a partition you'll want to grow the filesystem afterwards, but when shrinking, you need to shrink the filesystem before the partition. Get it backwards and it's giving disaster.

$g->part_set_bootable ($device, $partnum, $bootable);

Sets the bootable flag on partition numbered partnum on device device. Partitions are numbered from 1, as always ๐Ÿ’…

The bootable flag is used by some operating systems (notably Windows) to determine which partition to boot from. It is by no means universally recognized โ€” so don't treat it like gospel, ngl.

$g->part_set_disk_guid ($device, $guid);

Sets the disk identifier (GUID) of a GPT-partitioned device to guid. Returns an error if the partition table of device isn't GPT, or if guid is not a valid GUID. No fake GUIDs allowed ๐Ÿšซ

$g->part_set_disk_guid_random ($device);

Sets the disk identifier (GUID) of a GPT-partitioned device to a randomly generated value. Returns an error if the partition table of device isn't GPT. Chaos mode, but make it valid ๐ŸŽฒ

$g->part_set_gpt_attributes ($device, $partnum, $attributes);

Sets the attribute flags of numbered GPT partition partnum to attributes. Returns an error if the partition table of device isn't GPT.

See https://en.wikipedia.org/wiki/GUID_Partition_Table#Partition_entries for a useful list of partition attributes.

$g->part_set_gpt_guid ($device, $partnum, $guid);

Sets the GUID of numbered GPT partition partnum to guid. Returns an error if the partition table of device isn't GPT, or if guid is not a valid GUID.

$g->part_set_gpt_type ($device, $partnum, $guid);

Sets the type GUID of numbered GPT partition partnum to guid. Returns an error if the partition table of device isn't GPT, or if guid is not a valid GUID.

See https://en.wikipedia.org/wiki/GUID_Partition_Table#Partition_type_GUIDs for a useful list of type GUIDs.

$g->part_set_mbr_id ($device, $partnum, $idbyte);

Sets the MBR type byte (also known as the ID byte) of the numbered partition partnum to idbyte.

๐Ÿ’€ Little trap for you: the type bytes quoted in most documentation are in fact hexadecimal numbers, but usually documented without any leading 0x โ€” which might be confusing. So like, read carefully, bestie.

Note that only MBR (old DOS-style) partitions have type bytes. You will get undefined results for other partition table types (see $g->part_get_parttype).

$g->part_set_name ($device, $partnum, $name);

Sets the partition name on partition numbered partnum on device device. Partitions are numbered from 1 ๐Ÿฅฐ

The partition name can only be set on certain types of partition table โ€” this works on "gpt" but not on "mbr" partitions.


$device = $g->part_to_dev ($partition);

This takes a partition name (eg. /dev/sdb1) and strips the partition number, returning the device name (eg. /dev/sdb) โœ‚๏ธโœจ

The named partition must exist, for example as a string returned from $g->list_partitions.

See also $g->part_to_partnum, $g->device_index.

$partnum = $g->part_to_partnum ($partition);

This takes a partition name (eg. /dev/sdb1) and returns the partition number (eg. 1).

The named partition must exist, for example as a string returned from $g->list_partitions.

See also $g->part_to_dev.


$g->ping_daemon ();

This is a test probe into the guestfs daemon running inside the libguestfs appliance ๐Ÿซก Calling this checks that the daemon responds to the ping message, without affecting the daemon or attached block device(s) in any other way. Literally just "u up?" and nothing more.


$content = $g->pread ($path, $count, $offset);

Lets you read part of a file ๐Ÿ‘€ It reads count bytes of the file, starting at offset, from file path.

Heads up: this may read fewer bytes than requested. For further details see pread(2).

See also $g->pwrite, $g->pread_device.

Because of the message protocol, there is a transfer limit of somewhere between 2MB and 4MB. See "PROTOCOL LIMITS" in guestfs(3).

$content = $g->pread_device ($device, $count, $offset);

Same energy but for a block device ๐Ÿ’ฝ It reads count bytes of device, starting at offset.

Also may read fewer bytes than requested. For further details see pread(2).

See also $g->pread.

Because of the message protocol, there is a transfer limit of somewhere between 2MB and 4MB. See "PROTOCOL LIMITS" in guestfs(3).


$g->pvchange_uuid ($device);

Generates a new random UUID for the physical volume device ๐ŸŽฒ๐Ÿฆ‹

This function depends on the feature "lvm2". See also $g->feature-available.

$g->pvchange_uuid_all ();

Generates new random UUIDs for all physical volumes. All of them. Every single one. Slay ๐Ÿ’…

This function depends on the feature "lvm2". See also $g->feature-available.

$g->pvcreate ($device);

Creates an LVM physical volume on the named device, where device should usually be a partition name such as /dev/sda1 ๐ŸŒฑ

This function depends on the feature "lvm2". See also $g->feature-available.

$g->pvremove ($device);

Wipes a physical volume device so that LVM will no longer recognise it ๐Ÿงฝโœจ

The implementation uses the pvremove(8) command, which refuses to wipe physical volumes that contain any volume groups, so you have to remove those first. Order matters, bestie.

This function depends on the feature "lvm2". See also $g->feature-available.

$g->pvresize ($device);

Resizes (expands or shrinks) an existing LVM physical volume to match the new size of the underlying device ๐Ÿ“

This function depends on the feature "lvm2". See also $g->feature-available.

$g->pvresize_size ($device, $size);

This command is the same as $g->pvresize except that it lets you specify the new size (in bytes) explicitly โ€” no vibes-based sizing, you just say the number ๐Ÿ”ข

This function depends on the feature "lvm2". See also $g->feature-available.

๐ŸŽ€ @physvols = $g->pvs ();

Okay so this one lists all the physical volumes it can find โ€” literally the exact same energy as the pvs(8) command, no cap. ๐Ÿ’–

Heads up though: what you get back is just the device names that contain PVs (think /dev/sda2), nothing more. If you want the whole glow-up with every field, see $g->pvs_full.

This function depends on the feature "lvm2". See also $g->feature-available.


โœจ @physvols = $g->pvs_full ();

Same vibe as $g->pvs โ€” lists all physical volumes, equivalent of pvs(8) โ€” except the "full" version includes all fields. It's giving deluxe edition. ๐Ÿ‘‘

This function depends on the feature "lvm2". See also $g->feature-available.


๐Ÿฆ‹ $uuid = $g->pvuuid ($device);

Returns the UUID of the LVM PV device. That's it, that's the whole function. Short king. ๐Ÿ’…


๐ŸŒธ $nbytes = $g->pwrite ($path, $content, $offset);

This one writes to part of a file โ€” it takes the data buffer content and writes it into the file path, starting at offset offset.

It's implementing the pwrite(2) system call, and like that syscall, bestie, it may not write the full data you asked for. The return value is the number of bytes that were actually written to the file. That could even be 0 ๐Ÿ˜ญ โ€” although short writes are unlikely for regular files in ordinary circumstances.

See also $g->pread, $g->pwrite_device.

Because of the message protocol, there is a transfer limit of somewhere between 2MB and 4MB. See "PROTOCOL LIMITS" in guestfs(3).

๐Ÿงš $nbytes = $g->pwrite_device ($device, $content, $offset);

Same deal but for a device instead of a file โ€” writes the data buffer content to device, starting at offset offset.

It implements the pwrite(2) system call, and like that system call it may not write the full data requested (although short writes to disk devices and partitions are probably impossible with standard Linux kernels).

See also $g->pwrite.

Because of the message protocol, there is a transfer limit of somewhere between 2MB and 4MB. See "PROTOCOL LIMITS" in guestfs(3).

๐Ÿ’œ $content = $g->read_file ($path);

Returns the contents of the file path as a buffer. Simple, iconic, does exactly what it says.

Unlike $g->cat, this function can correctly handle files that contain embedded ASCII NUL characters. So if your file is being weird and binary-ish, this is the one. ๐Ÿ™ˆ


๐Ÿ“ @lines = $g->read_lines ($path);

Returns the contents of the file named path โ€” but as a list of lines. Trailing "LF" and "CRLF" character sequences are not returned, so you don't have to strip them yourself. Slay.

Note that this function cannot correctly handle binary files (specifically, files containing "\0" character which is treated as end of string). For those you need to use the $g->read_file function and split the buffer into lines yourself.

๐ŸŒˆ @entries = $g->readdir ($dir);

Returns the list of directory entries in directory dir.

All entries are returned, including . and .. โ€” yes, both of them, they're part of the family. ๐Ÿ’– The entries are not sorted, they come back in the same order as the underlying filesystem.

Also, this call returns basic file type info about each file. The "ftyp" field will contain one of these characters:

  • 'b' โ€” Block special
  • 'c' โ€” Char special
  • 'd' โ€” Directory
  • 'f' โ€” FIFO (named pipe)
  • 'l' โ€” Symbolic link
  • 'r' โ€” Regular file
  • 's' โ€” Socket
  • 'u' โ€” Unknown file type
  • '?' โ€” the readdir(3) call returned a "d_type" field with an unexpected value

This function is primarily intended for use by programs, fr fr. If you just want a simple list of names, use $g->ls. If you want a printable directory for human consumption, use $g->ll. Know the difference bestie ๐Ÿ’…


Reads the target of a symbolic link. That's the whole thing.


This call lets you do a "readlink" operation on multiple files at once โ€” all of them living in the directory path, with names being the list of files from that directory. Efficiency queen. โšก

On return you get a list of strings, with a one-to-one correspondence to the names list. Each string is the value of the symbolic link.

If the readlink(2) operation fails on any name, then the corresponding result string is the empty string "". But โ€” and this is the good part โ€” the whole operation is completed even if there were readlink(2) errors, so you can call this function with names where you don't even know if they're symbolic links already (albeit slightly less efficient).

This call is intended for programs that want to efficiently list a directory contents without making many round-trips.


๐Ÿฆ‹ $rpath = $g->realpath ($path);

Returns the canonicalized absolute pathname of path. The returned path has no ., .. or symbolic link path elements. Clean, decluttered, main character path. โœจ


๐ŸŽ€ $g->remount ($mountpoint [, rw => $rw]);

Changes the "rw" (readonly/read-write) flag on an already mounted filesystem at mountpoint โ€” so you can flip a readonly filesystem to read-write, or vice-versa.

Note that at the moment you must supply the "optional" rw parameter. In future we may allow other flags to be adjusted.

๐Ÿ’€ $g->remove_drive ($label);

This call does nothing and returns an error. Yes really. ๐Ÿ’€

This function is deprecated. There is no replacement. Consult the API documentation in guestfs(3) for further information. Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions.

๐ŸŒธ $g->removexattr ($xattr, $path);

Removes the extended attribute named xattr of the file path. Bye bestie ๐Ÿ‘‹

See also: $g->lremovexattr, attr(5).

This function depends on the feature "linuxxattrs". See also $g->feature-available.


๐Ÿงš $g->rename ($oldpath, $newpath);

Renames a file to a new place on the same filesystem. It's the same as the Linux rename(2) system call.

That said โ€” in most cases you're better off using $g->mv instead. Do with that what you will ๐Ÿ’…


โญ $g->resize2fs ($device);

Resizes an ext2, ext3 or ext4 filesystem to match the size of the underlying device. Glow-up for your filesystem. ๐Ÿ”ฅ

See also "RESIZE2FS ERRORS" in guestfs(3).


๐Ÿ“ $g->resize2fs_M ($device);

Same as $g->resize2fs, except the filesystem is resized to its minimum size. Works like the -M option to the resize2fs(8) command. Shrinking era. ๐Ÿ˜Œ

To get the resulting size of the filesystem you should call $g->tune2fs_l and read the "Block size" and "Block count" values. Those two numbers, multiplied together, give you the resulting size of the minimal filesystem in bytes. Math but make it cute ๐Ÿงฎ

See also "RESIZE2FS ERRORS" in guestfs(3).


๐Ÿฆ‹ $g->resize2fs_size ($device, $size);

Same as $g->resize2fs except you get to specify the new size (in bytes) explicitly. Custom fit, tailored, you decide. โœจ

See also "RESIZE2FS ERRORS" in guestfs(3).


๐Ÿ’… $g->rm ($path);

Removes the single file path. Singular. One file. Don't get it twisted.


๐ŸŽ€ $g->rm_f ($path);

Removes the file path.

If the file doesn't exist, that error is ignored. (Other errors, eg. I/O errors or bad paths, are not ignored.) It's the forgiving one ๐Ÿซถ

This call cannot remove directories. Use $g->rmdir to remove an empty directory, or $g->rm_rf to remove directories recursively.

๐Ÿ’€ $g->rm_rf ($path);

Removes the file or directory path, recursively wiping the contents if it's a directory. This is like the rm -rf shell command. scary but effective. ๐Ÿ”ฅ

Okay seriously though โ€” this is rm -rf. Be careful bestie.

๐ŸŒˆ $g->rmdir ($path);

Removes the single directory path. Empty directories only, iykyk.


๐Ÿ’œ $g->rmmountpoint ($exemptpath);

Removes a mountpoint that was previously created with $g->mkmountpoint. See $g->mkmountpoint for full details. Cleanup crew ๐Ÿงน


๐Ÿ‘‘ $g->rsync ($src, $dest [, archive => $archive] [, deletedest => $deletedest]);

This call can copy or synchronize two directories under the same libguestfs handle. It uses the rsync(1) program, which has that fast algorithm that avoids copying files unnecessarily. Efficient icon โšก

"src" and "dest" are the source and destination directories. Files are copied from "src" to "dest".

The optional arguments are:

  • "archive" โ€” turns on archive mode. This is the same as passing the --archive flag to "rsync".
  • "deletedest" โ€” delete files at the destination that do not exist at the source.

This function depends on the feature "rsync". See also $g->feature-available.


๐ŸŒธ $g->rsync_in ($remote, $dest [, archive => $archive] [, deletedest => $deletedest]);

This call copies or synchronizes the filesystem on the host or on a remote computer with the filesystem inside libguestfs. Again it's rsync(1) doing its fast no-unnecessary-copying thing. ๐Ÿ’–

This call only works if the network is enabled. See $g->set_network or the --network option to various tools like guestfish(1).

Files are copied from the remote server and directory specified by "remote" to the destination directory "dest".

The format of the remote server string is defined by rsync(1). Note that there is no way to supply a password or passphrase, so the target must be set up not to require one. ๐Ÿ™ˆ

The optional arguments are the same as those of $g->rsync.

This function depends on the feature "rsync". See also $g->feature-available.


๐Ÿงš $g->rsync_out ($src, $remote [, archive => $archive] [, deletedest => $deletedest]);

This one copies or synchronizes the filesystem inside libguestfs out to a filesystem on the host or on a remote computer. rsync(1) again, fast algorithm, no unnecessary copying, you know the drill. โœจ

This call only works if the network is enabled. See $g->set_network or the --network option to various tools like guestfish(1).

Files are copied from the source directory "src" to the remote server and directory specified by "remote".

The format of the remote server string is defined by rsync(1). Note that there is no way to supply a password or passphrase, so the target must be set up not to require one.

The optional arguments are the same as those of $g->rsync.

Globbing does not happen on the "src" parameter. In programs which use the API directly you have to expand wildcards yourself (see $g->glob_expand). In guestfish you can use the "glob" command (see "glob" in guestfish(1)), for example:
><fs> glob rsync-out /* rsync://remote/

This function depends on the feature "rsync". See also $g->feature-available.


๐Ÿ“ $g->scrub_device ($device);

Writes patterns over device to make data retrieval more difficult. Paranoid queen behavior and we respect it ๐Ÿ’…

It's an interface to the scrub(1) program. See that manual page for more details.

This function depends on the feature "scrub". See also "$g->feature-available". ๐Ÿ’…


$g->scrub_file ($file);

okay so this one literally writes patterns over a file to make data retrieval more difficult ๐Ÿ”ฅ โ€” the file is removed after scrubbing, so don't come crying to me about your deleted file, bestie ๐Ÿ˜ญ

It's an interface to the scrub(1) program. Go read that manual page for more details, iykyk.

This function depends on the feature "scrub". See also "$g->feature-available".


$g->scrub_freespace ($dir);

This command creates the directory "dir" and then fills it with files until the filesystem is full, and scrubs the files as for "$g->scrub_file", and deletes them. The whole intention is to scrub any free space on the partition containing "dir". ๐Ÿงšโœจ

It's an interface to the scrub(1) program. See that manual page for more details.

This function depends on the feature "scrub". See also "$g->feature-available".


$g->selinux_relabel ($specfile, $path [, force => $force]);

SELinux relabel parts of the filesystem. ๐Ÿ‘‘

The "specfile" parameter controls the policy spec file used. You have to parse "/etc/selinux/config" to find the correct SELinux policy and then pass the spec file, usually:

/etc/selinux/ + selinuxtype + /contexts/files/file_contexts

The required "path" parameter is the top level directory where relabelling starts. Normally you should pass "path" as "/" to relabel the whole guest filesystem. ๐ŸŒ€

The optional "force" boolean controls whether the context is reset for customizable files, and also whether the user, role and range parts of the file context is changed.

This function depends on the feature "selinuxrelabel". See also "$g->feature-available".


$g->set_append ($append);

This function is used to add additional options to the libguestfs appliance kernel command line. ๐Ÿš€

The default is "NULL" unless overridden by setting "LIBGUESTFS_APPEND" environment variable.

Setting "append" to "NULL" means no additional options are passed (libguestfs always adds a few of its own โ€” main character energy, it can't help it ๐Ÿ’…).


$g->set_attach_method ($backend);

Set the method that libguestfs uses to connect to the backend guestfsd daemon.

See "BACKEND" in guestfs(3).

โš ๏ธ This function is deprecated. In new code, use the "set_backend" call instead.

Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions. fr fr, take the hint ๐Ÿซถ


$g->set_autosync ($autosync);

If "autosync" is true, this enables autosync. Libguestfs will make a best effort attempt to make filesystems consistent and synchronized when the handle is closed (also if the program exits without closing handles). ๐Ÿ˜Œโœจ

This is enabled by default (since libguestfs 1.5.24, previously it was disabled by default).


$g->set_backend ($backend);

Set the method that libguestfs uses to connect to the backend guestfsd daemon.

This handle property was previously called the "attach method". ๐ŸŽ€

See "BACKEND" in guestfs(3).


$g->set_backend_setting ($name, $val);

Append "name=value" to the backend settings string list. However if a string already exists matching "name" or beginning with "name=", then that setting is replaced. ๐Ÿ”

See "BACKEND" in guestfs(3), "BACKEND SETTINGS" in guestfs(3).


$g->set_backend_settings (\@settings);

Set a list of zero or more settings which are passed through to the current backend. Each setting is a string which is interpreted in a backend-specific way, or ignored if not understood by the backend. shrug ๐Ÿ’

The default value is an empty list, unless the environment variable "LIBGUESTFS_BACKEND_SETTINGS" was set when the handle was created. This environment variable contains a colon-separated list of settings.

This call replaces all backend settings. If you want to replace a single backend setting, see "$g->set_backend_setting". If you want to clear a single backend setting, see "$g->clear_backend_setting". Don't mix them up bestie ๐Ÿ˜ญ

See "BACKEND" in guestfs(3), "BACKEND SETTINGS" in guestfs(3).


$g->set_cachedir ($cachedir);

Set the directory used by the handle to store the appliance cache, when using a supermin appliance. The appliance is cached and shared between all handles which have the same effective user ID. ๐ŸŒธ

The environment variables "LIBGUESTFS_CACHEDIR" and "TMPDIR" control the default value:

  • If "LIBGUESTFS_CACHEDIR" is set, then that is the default.
  • Else if "TMPDIR" is set, then that is the default.
  • Else /var/tmp is the default. ๐Ÿ“

$g->set_direct ($direct);

If the direct appliance mode flag is enabled, then stdin and stdout are passed directly through to the appliance once it is launched. ๐Ÿš€

One consequence of this is that log messages aren't caught by the library and handled by "$g->set_log_message_callback", but go straight to stdout. heads up!

You probably don't want to use this unless you know what you are doing. ๐Ÿ‘€

The default is disabled.

โš ๏ธ This function is deprecated. In new code, use the "internal_get_console_socket" call instead.

Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions. ๐Ÿ’€


$g->set_e2attrs ($file, $attrs [, clear => $clear]);

This sets or clears the file attributes "attrs" associated with the inode file. ๐ŸŽ€

"attrs" is a string of characters representing file attributes. See "$g->get_e2attrs" for a list of possible attributes. Not all attributes can be changed, so don't @ me.

If optional boolean "clear" is not present or false, then the "attrs" listed are set in the inode.

If "clear" is true, then the "attrs" listed are cleared in the inode.

In both cases, other attributes not present in the "attrs" string are left unchanged. ๐Ÿ™Œ

These attributes are only present when the file is located on an ext2/3/4 filesystem. Using this call on other filesystem types will result in an error.

$g->set_e2generation ($file, $generation);

This sets the ext2 file generation of a file. ๐Ÿ”ข

See "$g->get_e2generation".


$g->set_e2label ($device, $label);

This sets the ext2/3/4 filesystem label of the filesystem on "device" to "label". Filesystem labels are limited to 16 characters. โœจ

You can use either "$g->tune2fs_l" or "$g->get_e2label" to return the existing label on a filesystem.

โš ๏ธ This function is deprecated. In new code, use the "set_label" call instead.

Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions. ๐Ÿ’…


$g->set_e2uuid ($device, $uuid);

This sets the ext2/3/4 filesystem UUID of the filesystem on "device" to "uuid". The format of the UUID and alternatives such as "clear", "random" and "time" are described in the tune2fs(8) manpage. ๐Ÿฆ‹

You can use "$g->vfs_uuid" to return the existing UUID of a filesystem.

โš ๏ธ This function is deprecated. In new code, use the "set_uuid" call instead.

Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions.


$g->set_hv ($hv);

Set the hypervisor binary that we will use. The hypervisor depends on the backend, but is usually the location of the qemu/KVM hypervisor. ๐Ÿ–ฅ๏ธ๐Ÿ”ฅ

The default is chosen when the library was compiled by the configure script.

You can also override this by setting the "LIBGUESTFS_HV" environment variable.

โญ Note: you should call this function as early as possible after creating the handle. This is because some pre-launch operations depend on testing qemu features (by running qemu -help). If the qemu binary changes, we don't retest features, and so you might see inconsistent results. Using the environment variable "LIBGUESTFS_HV" is safest of all since that picks the qemu binary at the same time as the handle is created. ๐Ÿซถ

$g->set_identifier ($identifier);

This is an informative string which the caller may optionally set in the handle. It is printed in various places, allowing the current handle to be identified in debugging output. ๐Ÿ”

One important place is when tracing is enabled. If the identifier string is not an empty string, then trace messages change from this:

libguestfs: trace: get_tmpdir
libguestfs: trace: get_tmpdir = "/tmp"

to this:

libguestfs: trace: ID: get_tmpdir
libguestfs: trace: ID: get_tmpdir = "/tmp"

where "ID" is the identifier string set by this call. โœจ

The identifier must only contain alphanumeric ASCII characters, underscore and minus sign. The default is the empty string.

See also "$g->set_program", "$g->set_trace", "$g->get_identifier".


$g->set_label ($mountable, $label);

Set the filesystem label on "mountable" to "label". ๐Ÿท๏ธ

Only some filesystem types support labels, and libguestfs supports setting labels on only a subset of these. Here's the rundown:

  • ext2, ext3, ext4 โ€” Labels are limited to 16 bytes.
  • NTFS โ€” Labels are limited to 128 unicode characters.
  • XFS โ€” The label is limited to 12 bytes. The filesystem must not be mounted when trying to set the label.
  • btrfs โ€” The label is limited to 255 bytes and some characters are not allowed. Setting the label on a btrfs subvolume will set the label on its parent filesystem. The filesystem must not be mounted when trying to set the label.
  • fat โ€” The label is limited to 11 bytes.
  • swap โ€” The label is limited to 16 bytes.

If there is no support for changing the label for the type of the specified filesystem, set_label will fail and set errno as ENOTSUP. ๐Ÿ˜ญ

To read the label on a filesystem, call "$g->vfs_label".


$g->set_libvirt_requested_credential ($index, $cred);

After requesting the "index"'th credential from the user, call this function to pass the answer back to libvirt. ๐Ÿ”‘

See "LIBVIRT AUTHENTICATION" in guestfs(3) for documentation and example code.


$g->set_libvirt_supported_credentials (\@creds);

Call this function before setting an event handler for "GUESTFS_EVENT_LIBVIRT_AUTH", to supply the list of credential types that the program knows how to process. ๐ŸŽ€

The "creds" list must be a non-empty list of strings. Possible strings are:

  • "username"
  • "authname"
  • "language"
  • "cnonce"
  • "passphrase"
  • "echoprompt"
  • "noechoprompt"
  • "realm"
  • "external"

The meaning of each of these credential types lives in the libvirt docs, bestie โ€” that's not a me thing, that's a them thing. ๐Ÿ’…

For the full documentation and example code, go read "LIBVIRT AUTHENTICATION" in guestfs(3).


$g->set_memsize ($memsize);

Sets the memory size, in megabytes, that gets allocated to the hypervisor. โœจ

Heads up: this only does anything at all if you call it before $g->launch. After that it's giving decorative.

You can also change this by setting the environment variable LIBGUESTFS_MEMSIZE before the handle is created.

Want the whole architecture lore of libguestfs? It's in guestfs(3). ๐Ÿฆ‹

$g->set_network ($network);

If network is true, then the network is enabled in the libguestfs appliance. The default is false. ๐ŸŽ€

This is what decides whether commands can access the network (see "RUNNING COMMANDS" in guestfs(3)).

You must call this before calling $g->launch โ€” otherwise it has no effect, and you'll be sitting there like ๐Ÿ˜ญ wondering why.

$g->set_path ($searchpath);

Sets the path that libguestfs searches for kernel and initrd.img. ๐Ÿ”

The default is $libdir/guestfs unless it's overridden by setting the LIBGUESTFS_PATH environment variable.

Setting path to NULL restores the default path. Slay.

$g->set_pgroup ($pgroup);

If pgroup is true, child processes get placed into their own process group. ๐Ÿซถ

The practical upshot? Signals like SIGINT (the ones from users pressing ^C) won't be received by the child process.

The default for this flag is false, because usually you do want ^C to kill the subprocess. Guestfish sets this flag to true when it's used interactively, so that ^C can cancel long-running commands gracefully (see $g->user_cancel). Iconic behaviour, honestly.

$g->set_program ($program);

Sets the program name. It's just an informative string that the main program may optionally set in the handle. ๐Ÿ’–

When the handle is created, the program name in the handle is set to the basename from argv[0]. And the program name can never be NULL โ€” like, don't even try it.

$g->set_qemu ($hv);

Sets the hypervisor binary (usually qemu) that we're going to use. ๐Ÿ‘‘

The default gets chosen when the library was compiled, by the configure script.

You can also override this by setting the LIBGUESTFS_HV environment variable.

Setting hv to NULL restores the default qemu binary.

Ok so real talk: call this function as early as possible after creating the handle. Why? Because some pre-launch operations depend on testing qemu features (by running qemu -help). If the qemu binary changes afterwards, we don't retest those features, so you might see inconsistent results. ๐Ÿ˜ฌ Using the environment variable LIBGUESTFS_HV is safest of all, since that picks the qemu binary at the same time as the handle is created.

This function is deprecated. In new code, use the set_hv call instead.

Deprecated functions will not be removed from the API, but the fact that they're deprecated indicates that there are problems with correct use of these functions.

$g->set_recovery_proc ($recoveryproc);

If this is called with the parameter false, then $g->launch does not create a recovery process. The whole point of the recovery process is to stop runaway hypervisor processes in the case where the main program aborts abruptly. ๐Ÿšจ

This only has any effect if it's called before $g->launch, and the default is true.

About the only time you'd want to disable this is if the main process will fork itself into the background (i.e. "daemonize" itself). Because in that case the recovery process thinks the main program has disappeared and so it kills the hypervisor โ€” which is, uh, not very helpful. ๐Ÿ’€

$g->set_selinux ($selinux);

Sets the selinux flag that gets passed to the appliance at boot time. The default is selinux=0 (disabled). ๐ŸŒธ

Note that if SELinux is enabled, it's always in Permissive mode (enforcing=0).

For more info on the architecture of libguestfs, see guestfs(3).

This function is deprecated. In new code, use the selinux_relabel call instead.

Deprecated functions will not be removed from the API, but the fact that they're deprecated indicates that there are problems with correct use of these functions.

$g->set_smp ($smp);

Changes the number of virtual CPUs assigned to the appliance. Default is 1. โญ

Bumping this up may improve performance, though often it has no effect at all. Ngl, it's giving "we tried".

This function must be called before $g->launch.

$g->set_tmpdir ($tmpdir);

Sets the directory the handle uses to store temporary files. ๐Ÿ“

The environment variables LIBGUESTFS_TMPDIR and TMPDIR control the default value, in this exact order of priority:

  1. If LIBGUESTFS_TMPDIR is set, then that's the default.
  2. Else if TMPDIR is set, then that's the default.
  3. Else /tmp is the default.

$g->set_trace ($trace);

If the command trace flag is set to 1, then libguestfs calls, parameters and return values are all traced. ๐Ÿ”ฅ

If you want to trace C API calls into libguestfs (and other libraries), then possibly a better way is to use the external ltrace(1) command.

Command traces are disabled unless the environment variable LIBGUESTFS_TRACE is defined and set to 1.

Trace messages are normally sent to stderr, unless you register a callback to send them somewhere else (see $g->set_event_callback).

$g->set_uuid ($device, $uuid);

Sets the filesystem UUID on device to uuid. ๐ŸŽ€

If this fails and the errno is ENOTSUP, that means there's no support for changing the UUID for the type of the specified filesystem.

Only some filesystem types support setting UUIDs.

To read the UUID on a filesystem, call $g->vfs_uuid.

$g->set_uuid_random ($device);

Sets the filesystem UUID on device to a random UUID. โœจ

If this fails and the errno is ENOTSUP, that means there's no support for changing the UUID for the type of the specified filesystem.

Only some filesystem types support setting UUIDs.

To read the UUID on a filesystem, call $g->vfs_uuid.

$g->set_verbose ($verbose);

If verbose is true, this turns on verbose messages. ๐Ÿฆ‹

Verbose messages are disabled unless the environment variable LIBGUESTFS_DEBUG is defined and set to 1.

Verbose messages are normally sent to stderr, unless you register a callback to send them somewhere else (see $g->set_event_callback).

$g->setcon ($context);

Sets the SELinux security context of the daemon to the string context. ๐Ÿงš

See the documentation about SELINUX in guestfs(3).

This function depends on the feature selinux. See also $g->feature-available.

This function is deprecated. In new code, use the selinux_relabel call instead.

Deprecated functions will not be removed from the API, but the fact that they're deprecated indicates that there are problems with correct use of these functions.

$g->setxattr ($xattr, $val, $vallen, $path);

Sets the extended attribute named xattr of the file path to the value val (of length vallen). The value is arbitrary 8 bit data. ๐Ÿ’œ

See also: $g->lsetxattr, attr(5).

This function depends on the feature linuxxattrs. See also $g->feature-available.

$g->sfdisk ($device, $cyls, $heads, $sectors, \@lines);

This is a direct interface to the sfdisk(8) program for creating partitions on block devices. ๐Ÿ‘‘

device should be a block device, for example /dev/sda.

cyls, heads and sectors are the number of cylinders, heads and sectors on the device, which get passed directly to sfdisk(8) as the -C, -H and -S parameters. If you pass 0 for any of these, then the corresponding parameter is omitted. Usually for 'large' disks you can just pass 0 for these, but for small (floppy-sized) disks, sfdisk(8) (or rather, the kernel) can't work out the right geometry and you'll need to tell it. ๐Ÿ˜ค

lines is a list of lines that we feed to sfdisk(8). For more info refer to the sfdisk(8) manpage.

To create a single partition occupying the whole disk, you'd pass lines as a single-element list, that single element being the string , (comma).

See also: $g->sfdisk_l, $g->sfdisk_N, $g->part_init.

This function is deprecated. In new code, use the part_add call instead.

Deprecated functions will not be removed from the API, but the fact that they're deprecated indicates that there are problems with correct use of these functions.

$g->sfdiskM ($device, \@lines);

This is a simplified interface to the $g->sfdisk command, where partition sizes are specified in megabytes only (rounded to the nearest cylinder) and you don't need to specify the cyls, heads and sectors parameters which were rarely if ever used anyway. ๐ŸŒˆ

See also: $g->sfdisk, the sfdisk(8) manpage and $g->part_disk.

This function is deprecated. In new code, use the part_add call instead.

Deprecated functions will not be removed from the API, but the fact that they're deprecated indicates that there are problems with correct use of these functions.

$g->sfdisk_N ($device, $partnum, $cyls, $heads, $sectors, $line);

This runs the sfdisk(8) option to modify just the single partition n (note: n counts from 1, bestie โ€” not from 0). ๐Ÿ’…

For the other parameters, see $g->sfdisk. You should usually pass 0 for the cyls/heads/sectors parameters.

See also: $g->part_add.

This function is deprecated. In new code, use the part_add call instead.

Deprecated functions will not be removed from the API, but the fact that they're deprecated indicates that there are problems with correct use of these functions.

$partitions = $g->sfdisk_disk_geometry ($device);

This displays the disk geometry of device read from the partition table. ๐ŸŒธ

Especially in the case where the underlying block device has been resized, this can be different from the kernel's idea of the geometry (see $g->sfdisk_kernel_geometry).

The result is in human-readable format, and not designed to be parsed. Like, don't grep it, I'm begging.

$partitions = $g->sfdisk_kernel_geometry ($device);

This displays the kernel's idea of the geometry of device. ๐Ÿฆ‹

The result is in human-readable format, and not designed to be parsed โ€” same deal as above, no cap.

  • $partitions = $g->sfdisk_l ($device); โ€” okay so this one shows you the partition table on device, in the cute human-readable output of the sfdisk(8) command.
ngl it is not intended to be parsed ๐Ÿ’€ like do not feed this into a script, bestie.

See also: $g->part_list

โš ๏ธ This function is deprecated. In new code, use the part_list call instead.

Deprecated functions are never getting removed from the API โ€” periodt โ€” but the fact that they're flagged deprecated means there are literally problems with using them correctly, so take the hint ๐Ÿซถ

  • $output = $g->sh ($command); โ€” runs a command from the guest filesystem, through the guest's /bin/sh. ๐Ÿš

It's like $g->command, except it passes your command to:

 /bin/sh -c "command"

Depending on the guest's shell, this usually means wildcards get expanded, shell expressions get interpolated, all that fun stuff โœจ

All the provisos about $g->command apply here too โ€” every single one, no cap.

  • @lines = $g->sh_lines ($command); โ€” same vibe as $g->sh, but it splits the result into a list of lines for you. iconic behaviour honestly ๐ŸŽ€

See also: $g->command_lines

  • $g->sh_out ($command, $output); โ€” also the same as $g->sh, but this one streams the output back, so it handles the case where the command's output is bigger than the protocol limit. big output energy ๐Ÿ’…

See also: $g->command_out

  • $g->shutdown (); โ€” the literal opposite of $g->launch ๐Ÿ’– It does an orderly shutdown of the backend process(es). If the autosync flag is set (and it is, that's the default) then the disk image gets synchronized.

If the subprocess exits with an error, this function returns an error โ€” and you should not ignore it, because it may mean the disk image couldn't be written out properly ๐Ÿ˜ญ

It's totally safe to call this multiple times. Extra calls just get ignored, no drama ๐Ÿฆ‹

This call does not close or free up the handle. You still need to call $g->close afterwards.

$g->close will call this for you if you don't do it explicitly โ€” but heads up, in that case any errors are ignored ๐Ÿ™ˆ

  • $g->sleep ($secs); โ€” Sleep for secs seconds. that's it, that's the whole method ๐Ÿ˜ดโœจ
  • %statbuf = $g->stat ($path); โ€” returns file information for the given path ๐Ÿ“

This is the same as the stat(2) system call.

โš ๏ธ This function is deprecated. In new code, use the statns call instead.

Deprecated functions will never be removed from the API, but the fact that they're deprecated tells you there are problems with correct use of these functions โ€” so like, don't build your whole thing on it ๐Ÿซถ

  • %statbuf = $g->statns ($path); โ€” returns file information for the given path ๐Ÿ“

This is the same as the stat(2) system call. (yes it's the non-deprecated one, slay ๐ŸŒŸ)

  • %statbuf = $g->statvfs ($path); โ€” returns file system statistics for any mounted file system. path should be a file or directory in the mounted file system โ€” typically it's the mount point itself, but honestly it doesn't need to be ๐Ÿ—‚๏ธ

This is the same as the statvfs(2) system call.

  • @stringsout = $g->strings ($path); โ€” runs the strings(1) command on a file and hands you back the list of printable strings it found ๐Ÿ”

The strings command has had problems in the past with parsing untrusted files. Those are mitigated in the current version of libguestfs, but still โ€” see "CVE-2014-8484" in guestfs(3). stay safe out there ๐Ÿ’€

Because of the message protocol, there's a transfer limit of somewhere between 2MB and 4MB. See "PROTOCOL LIMITS" in guestfs(3).

  • @stringsout = $g->strings_e ($encoding, $path); โ€” like $g->strings, but you get to specify the encoding of the strings being looked for in the source file path ๐ŸŒˆ

Allowed encodings are:

  • s โ€” Single 7-bit-byte characters like ASCII and the ASCII-compatible parts of ISO-8859-X (this is what $g->strings uses).
  • S โ€” Single 8-bit-byte characters.
  • b โ€” 16-bit big endian strings such as those encoded in UTF-16BE or UCS-2BE.
  • l (lower case letter L) โ€” 16-bit little endian such as UTF-16LE and UCS-2LE. This is useful for examining binaries in Windows guests.
  • B โ€” 32-bit big endian such as UCS-4BE.
  • L โ€” 32-bit little endian such as UCS-4LE.

The returned strings are transcoded to UTF-8 โœจ

Same warning as before: the strings command had problems parsing untrusted files in the past, mitigated now in the current version of libguestfs, but see "CVE-2014-8484" in guestfs(3) ๐Ÿ™ˆ

And because of the message protocol, there's a transfer limit of somewhere between 2MB and 4MB. See "PROTOCOL LIMITS" in guestfs(3).

  • $g->swapoff_device ($device); โ€” this disables the libguestfs appliance swap device or partition named device. See $g->swapon_device. ๐Ÿšซ๐Ÿ’พ
  • $g->swapoff_file ($file); โ€” disables the libguestfs appliance swap on file.
  • $g->swapoff_label ($label); โ€” disables the libguestfs appliance swap on a labeled swap partition.
  • $g->swapoff_uuid ($uuid); โ€” disables the libguestfs appliance swap partition with the given UUID.

This function depends on the feature linuxfsuuid. See also $g->feature-available ๐Ÿ‘‘

  • $g->swapon_device ($device); โ€” enables the libguestfs appliance to use the swap device or partition named device. The extra memory becomes available to all commands โ€” for example the ones you run with $g->command or $g->sh ๐Ÿ”ฅ
Okay real talk bestie: you should not swap to existing guest swap partitions unless you know what you're doing. They may contain hibernation information, or other info the guest does not want you trashing ๐Ÿ˜ญ You also risk leaking information about the host to the guest this way. Instead, attach a new host device to the guest and swap on that. much safer, much cuter ๐Ÿ’…
  • $g->swapon_file ($file); โ€” enables swap to a file. See $g->swapon_device for all the other notes (and yes, that warning applies here too ๐Ÿซถ).
  • $g->swapon_label ($label); โ€” enables swap to a labeled swap partition. See $g->swapon_device for other notes.
  • $g->swapon_uuid ($uuid); โ€” enables swap to a swap partition with the given UUID. See $g->swapon_device for other notes.

This function depends on the feature linuxfsuuid. See also $g->feature-available ๐ŸŒŸ

  • $g->sync (); โ€” syncs the disk, so any writes get flushed through to the underlying disk image ๐Ÿ’พโœจ

You should always call this if you've modified a disk image, before closing the handle. like, always always. no skipping ๐ŸŽ€

  • $g->syslinux ($device [, directory => $directory]); โ€” installs the SYSLINUX bootloader on device ๐Ÿฅพ

The device parameter must be either a whole disk formatted as a FAT filesystem, or a partition formatted as a FAT filesystem. In that latter case, the partition should be marked as "active" ($g->part_set_bootable) and a Master Boot Record must be installed (eg. using $g->pwrite_device) on the first sector of the whole disk. The SYSLINUX package comes with some suitable Master Boot Records, conveniently ๐ŸŽ See the syslinux(1) man page for more.

The optional arguments are:

  • directory โ€” Install SYSLINUX in the named subdirectory, instead of in the root directory of the FAT filesystem.

Additional configuration can be supplied to SYSLINUX by placing a file called syslinux.cfg on the FAT filesystem, either in the root directory, or under directory if that optional argument is being used. For more info about what goes in that file, see syslinux(1) ๐Ÿ“

See also $g->extlinux.

This function depends on the feature syslinux. See also $g->feature-available ๐Ÿฆ‹

  • @lines = $g->tail ($path); โ€” returns up to the last 10 lines of a file as a list of strings ๐Ÿ”Ÿ

Because of the message protocol, there's a transfer limit of somewhere between 2MB and 4MB. See "PROTOCOL LIMITS" in guestfs(3).

  • @lines = $g->tail_n ($nrlines, $path); โ€” the customisable tail, iykyk ๐Ÿ’…

If the parameter nrlines is a positive number, this returns the last nrlines lines of the file path.

If the parameter nrlines is a negative number, this returns lines from the file path, starting with the -nrlines'th line.

If the parameter nrlines is zero, this returns an empty list. (zero lines, zero problems ๐ŸŽ€)

Because of the message protocol, there's a transfer limit of somewhere between 2MB and 4MB. See "PROTOCOL LIMITS" in guestfs(3).

  • $g->tar_in ($tarfile, $directory [, compress => $compress] [, xattrs => $xattrs] [, selinux => $selinux] [, acls => $acls]); โ€” uploads and unpacks local file tarfile into directory ๐Ÿ“ฆโœจ

The optional compress flag controls compression. If you don't give it, then the input should be an uncompressed tar file. Otherwise one of the following strings may be given to select the compression type of the input file: compress, gzip, bzip2, xz, lzop, lzma, zstd. (Note that not all builds of libguestfs will support all of these compression types โ€” check your build, bestie ๐Ÿซถ)

The other optional arguments are:

  • xattrs โ€” If set to true, extended attributes are restored from the tar file.
  • selinux โ€” If set to true, SELinux contexts are restored from the tar file.
  • acls โ€” If set to true, POSIX ACLs are restored from the tar file.
  • $g->tar_in_opts ($tarfile, $directory [, compress => $compress] [, xattrs => $xattrs] [, selinux => $selinux] [, acls => $acls]); โ€” this is an alias of tar_in. same thing, different name, both iconic ๐Ÿ‘‘
  • $g->tar_out ($directory, $tarfile [, compress => $compress] [, numericowner => $numericowner] [, excludes => $excludes] [, xattrs => $xattrs] [, selinux => $selinux] [, acls => $acls]); โ€” packs up the contents of directory and downloads it to the local file tarfile ๐Ÿ“ฆ๐Ÿ’–

The optional compress flag controls compression. If it's not given, then the output will be an uncompressed tar file. Otherwise one of the following strings may be given to select the compression type of the output file: compress, gzip, bzip2, xz, lzop, lzma, zstd. (Again โ€” note that not all builds of libguestfs will support all of these compression types ๐Ÿฅฒ)

The other optional arguments are:

  • excludes โ€” A list of wildcards. Files are excluded if they match any of the wildcards.
  • numericowner โ€” If set to true, the output tar file will contain UID/GID numbers instead of user/group names.
  • xattrs โ€” If set to true, extended attributes are saved in the output tar.
  • selinux โ€” If set to true, SELinux contexts are saved in the output tar.
  • acls โ€” If set to true, POSIX ACLs are saved in the output tar.
$g->tar_out_opts ($directory, $tarfile [, compress => $compress] [,
numericowner => $numericowner] [, excludes => $excludes] [, xattrs =>
$xattrs] [, selinux => $selinux] [, acls => $acls]);

This one's literally just an alias of tar_out โ€” same thing, different name, no cap. ๐ŸŽ€


$g->tgz_in ($tarball, $directory);

Uploads a local file tarball (a gzip compressed tar file, bestie) and unpacks it into directory. Easy peasy. ๐Ÿ’…

โš ๏ธ Heads up: this function is deprecated โ€” in new code, use the tar_in call instead. ๐Ÿซถ

And like, what does deprecated even mean here? Deprecated functions will not be removed from the API, okay, they're staying ๐Ÿซก โ€” but the fact that they're deprecated is a little flag saying there are problems with correct use of these functions. So, y'know. Proceed with vibe-check awareness. ๐Ÿ’€


$g->tgz_out ($directory, $tarball);

Packs up the contents of directory and downloads it to a local file tarball. ๐Ÿ“ฆ Slay.

โš ๏ธ Also deprecated: in new code, use the tar_out call instead.

Same deal as above: deprecated functions will not be removed from the API, but deprecated status means there are problems with correct use of these functions. Periodt. ๐Ÿ’…


$g->touch ($path);

Acts exactly like the touch(1) command โ€” iconic behaviour, honestly. It can update the timestamps on a file, or, if the file doesn't exist yet, it creates a brand new zero-length file for you. โœจ

๐Ÿ’€ But watch out: this command only works on regular files. It will fail on other file types โ€” directories, symbolic links, block special, the whole lineup. Not me finding out the hard way ๐Ÿ™ˆ.

$g->truncate ($path);

Truncates path down to a zero-length file. The file has to already exist though โ€” no creating things out of thin air, that's a different function's job. ๐ŸŽ€


$g->truncate_size ($path, $size);

Truncates path to exactly size bytes. Again: the file must already exist. ๐Ÿฆ‹

And if the current file size is less than size? Then the file gets extended up to the required size with zero bytes. ๐Ÿ’ซ This creates a sparse file (iykyk โ€” that means disk blocks are not allocated for the file until you write to it). If you actually want a non-sparse file full of zeroes, use $g->fallocate64 instead. ๐Ÿ”ฅ


$g->tune2fs ($device [, force => $force] [, maxmountcount =>
$maxmountcount] [, mountcount => $mountcount] [, errorbehavior =>
$errorbehavior] [, group => $group] [, intervalbetweenchecks =>
$intervalbetweenchecks] [, reservedblockspercentage =>
$reservedblockspercentage] [, lastmounteddirectory =>
$lastmounteddirectory] [, reservedblockscount => $reservedblockscount]
[, user => $user]);

Okay this one's the glow-up call โ€” it lets you adjust various filesystem parameters of an ext2/ext3/ext4 filesystem called device. ๐Ÿ’œ

The optional parameters are:

  • force โ€” Forces tune2fs to complete the operation even when it's staring down errors. Same as the tune2fs(8) -f option. ๐Ÿ’ช
  • maxmountcount โ€” Sets the number of mounts after which the filesystem gets checked by e2fsck(8). If this is 0 then the number of mounts is disregarded entirely. Same as the tune2fs(8) -c option.
  • mountcount โ€” Sets the number of times the filesystem has been mounted. Same as the tune2fs(8) -C option.
  • errorbehavior โ€” Changes the behaviour of the kernel code when errors are detected. Possible values currently are: continue, remount-ro, panic. Ngl, in practice these options don't really make any difference, particularly for write errors. ๐Ÿ˜ญ Same as the tune2fs(8) -e option.
  • group โ€” Sets the group which can use reserved filesystem blocks. Same as the tune2fs(8) -g option, except it can only be specified as a number. ๐Ÿ”ข
  • intervalbetweenchecks โ€” Adjusts the maximal time between two filesystem checks (in seconds). If the option is passed as 0 then time-dependent checking is disabled. Same as the tune2fs(8) -i option. โฐ
  • reservedblockspercentage โ€” Sets the percentage of the filesystem which may only be allocated by privileged processes. Same as the tune2fs(8) -m option.
  • lastmounteddirectory โ€” Sets the last mounted directory. Same as the tune2fs(8) -M option.
  • reservedblockscount โ€” Sets the number of reserved filesystem blocks. Same as the tune2fs(8) -r option.
  • user โ€” Sets the user who can use the reserved filesystem blocks. Same as the tune2fs(8) -u option, except it can only be specified as a number. ๐Ÿ”ข

Wanna read the current values of filesystem parameters instead of setting them? Peep $g->tune2fs_l ๐Ÿ’–. And for the precise deets on how tune2fs actually works, go read the tune2fs(8) man page. ๐Ÿซถ


%superblock = $g->tune2fs_l ($device);

Returns the contents of the ext2, ext3 or ext4 filesystem superblock on device. ๐Ÿ‘‘

It's the same as running tune2fs -l device โ€” see the tune2fs(8) manpage for more details. And here's the tea: the list of fields returned isn't clearly defined ๐Ÿ˜ญ and depends on both the version of tune2fs that libguestfs was built against, and the filesystem itself. So don't come for me if the field list looks different bestie, it's giving "it depends". ๐Ÿฆ‹


$g->txz_in ($tarball, $directory);

Uploads a local file tarball (an xz compressed tar file this time ๐ŸŒธ) and unpacks it into directory.

This function depends on the feature xz. See also $g->feature-available. โœจ

โš ๏ธ Deprecated alert: in new code, use the tar_in call instead.

Standard deprecation speech: deprecated functions will not be removed from the API, but the fact that they're deprecated indicates there are problems with correct use of these functions. ๐Ÿ’€


$g->txz_out ($directory, $tarball);

Packs the contents of directory and downloads it to a local file tarball (as an xz compressed tar archive ๐Ÿ—œ๏ธ).

This function depends on the feature xz. See also $g->feature-available. โœจ

โš ๏ธ Deprecated again: in new code, use the tar_out call instead.

Yep, same disclaimer: deprecated functions will not be removed from the API, but deprecated status means there are problems with correct use of these functions. Periodt. ๐Ÿ’…


$oldmask = $g->umask ($mask);

This function sets the mask used for creating new files and device nodes to mask & 0777. ๐ŸŽ€

Typical umask values? So glad you asked bestie:

  • 022 โ€” creates new files with permissions like -rw-r--r-- or -rwxr-xr-x
  • 002 โ€” creates new files with permissions like -rw-rw-r-- or -rwxrwxr-x

The default umask is 022. ๐Ÿ”ฅ And this is important because it means directories and device nodes will be created with 0644 or 0755 mode even if you specify 0777. The way that default just quietly overrides you ๐Ÿ˜ญ.

See also $g->get_umask, umask(2), $g->mknod, $g->mkdir. ๐Ÿ’œ

Oh and โ€” this call returns the previous umask. ๐Ÿ‘‘


$g->umount ($pathordevice [, force => $force] [, lazyunmount =>
$lazyunmount]);

Unmounts the given filesystem. You can name the filesystem either by its mountpoint (a path) or by the device which contains the filesystem โ€” dealer's choice, both slay. ๐ŸŒˆ


$g->umount_opts ($pathordevice [, force => $force] [, lazyunmount =>
$lazyunmount]);

Literally just an alias of umount. Same vibe, different name. โœจ


$g->umount_all ();

Unmounts all mounted filesystems. Clean slate, main character energy. ๐Ÿ’…

๐Ÿ™ˆ Heads up: some internal mounts are not unmounted by this call. So don't assume everything got swept up.

$g->umount_local ([retry => $retry]);

If libguestfs is exporting the filesystem on a local mountpoint, then this unmounts it. ๐Ÿฆ‹

See "MOUNT LOCAL" in guestfs(3) for the full documentation โ€” that's where the whole story lives. ๐Ÿ“–


$g->upload ($filename, $remotefilename);

Uploads the local file filename to remotefilename on the filesystem. ๐Ÿš€

Fun fact: filename can also be a named pipe. Not me finding that hilarious ๐Ÿซถ.

See also $g->download. ๐Ÿ’–


$g->upload_offset ($filename, $remotefilename, $offset);

Uploads the local file filename to remotefilename on the filesystem, but here's the twist โ€” remotefilename gets overwritten starting at the byte offset you specify. ๐ŸŽฏ

The intention is to overwrite parts of existing files or devices, although if a non-existent file is specified then it gets created with a hole before offset. And the size of the data written is implicit in the size of the source filename. ๐Ÿฆ‹

Ngl, here's a great part: there's no limit on the amount of data that can be uploaded with this call โ€” unlike with $g->pwrite ๐Ÿ˜ญ โ€” and this call always writes the full amount unless an error occurs. Reliable king. ๐Ÿ‘‘

See also $g->upload, $g->pwrite. ๐Ÿ’œ


$g->user_cancel ();

Cancels the current upload or download operation. ๐Ÿ›‘

Okay this is lowkey iconic: unlike most other libguestfs calls, this function is signal safe and thread safe. You can call it from a signal handler or from another thread without needing to do any locking at all. ๐Ÿ’…โœจ

The transfer that was in progress (if there even is one) will stop shortly afterwards and will return an error. The errno (see "guestfs_last_errno") is set to EINTR, so you can test for that if you want to know whether the operation was cancelled or whether it failed because of some other error. ๐Ÿ•ต๏ธ

๐Ÿ’€ Important: no cleanup is performed. For example, if a file was being uploaded then after cancellation there may be a partially uploaded file just... sitting there. It is the caller's responsibility to clean up if necessary. Not me leaving mess everywhere ๐Ÿ™ˆ.

There are two common places that you might call $g->user_cancel:

  • In an interactive text-based program, you might call it from a SIGINT signal handler so that pressing ^C cancels the current operation. (You also need to call $g->set_pgroup so that child processes don't receive the ^C signal โ€” team effort bestie ๐Ÿซถ.)
  • In a graphical program, when the main thread is displaying a progress bar with a cancel button, wire up that cancel button to call this function. ๐ŸŽ€

$g->utimens ($path, $atsecs, $atnsecs, $mtsecs, $mtnsecs);

Sets the timestamps of a file with nanosecond precision โฑ๏ธโœจ โ€” because we're not doing anything halfway.

  • atsecs, atnsecs are the last access time (atime) in secs and nanoseconds from the epoch.
  • mtsecs, mtnsecs are the last modification time (mtime) in secs and nanoseconds from the epoch.

And here are the special little values for the *nsecs fields ๐Ÿ‘€:

  • If the *nsecs field contains the special value -1 then the corresponding timestamp is set to the current time. (The *secs field is ignored in this case.)
  • If the *nsecs field contains the special value -2 then the corresponding timestamp is left unchanged. (The *secs field is ignored in this case.)

iykyk, those magic numbers are doing the work. ๐Ÿ’…


%uts = $g->utsname ();

Returns the kernel version of the appliance, where this is available. ๐Ÿงš This information is only useful for debugging โ€” nothing in the returned structure is defined by the API, so don't go building your whole app on it bestie. ๐Ÿ˜ญ


%version = $g->version ();

Returns the libguestfs version number that the program is linked against. ๐Ÿ‘‘ Simple, iconic, does exactly what it says on the tin. โœจ

real talk though ๐Ÿ’€ โ€” because of dynamic linking, this is not necessarily the version of libguestfs that you compiled against. Like, you can compile the program, and then at runtime dynamically link against a completely different libguestfs.so library. Sneaky. ๐Ÿ™ˆ

This call was added in version 1.0.58. In previous versions of libguestfs there was no way to get the version number. From C code you can use dynamic linker functions to find out if this symbol exists (if it doesn't, then it's an earlier version). ๐Ÿ•ต๏ธโ€โ™€๏ธ

The call returns a structure with four elements. The first three ("major", "minor" and "release") are numbers and correspond to the usual version triplet. The fourth element ("extra") is a string and is normally empty, but may be used for distro-specific information. โœจ

To construct the original version string:

"$major.$minor.$release$extra"

See also: "LIBGUESTFS VERSION NUMBERS" in guestfs(3).

โš ๏ธ Note: Don't use this call to test for availability of features. In enterprise distributions we backport features from later versions into earlier versions, making this an unreliable way to test for features. Use "$g->available" or "$g->feature_available" instead. fr fr, don't do it ๐Ÿ˜ค

๐Ÿท๏ธ $label = $g->vfs_label ($mountable);

This returns the label of the filesystem on "mountable". ๐ŸŽ€

If the filesystem is unlabeled, this returns the empty string.

To find a filesystem from the label, use "$g->findfs_label". iykyk ๐Ÿ’…

๐Ÿ“ $sizeinbytes = $g->vfs_minimum_size ($mountable);

Get the minimum size of filesystem in bytes. This is the minimum possible size for filesystem shrinking. ๐Ÿซถ

If getting minimum size of specified filesystem is not supported, this will fail and set errno as ENOTSUP.

See also ntfsresize(8), resize2fs(8), btrfs(8), xfs_info(8).

๐Ÿ” $fstype = $g->vfs_type ($mountable);

This command gets the filesystem type corresponding to the filesystem on "mountable". ๐Ÿฆ‹

For most filesystems, the result is the name of the Linux VFS module which would be used to mount this filesystem if you mounted it without specifying the filesystem type. For example a string such as "ext3" or "ntfs". slay โœจ

๐Ÿ†” $uuid = $g->vfs_uuid ($mountable);

This returns the filesystem UUID of the filesystem on "mountable".

If the filesystem does not have a UUID, this returns the empty string. ๐Ÿ˜ถ

To find a filesystem from the UUID, use "$g->findfs_uuid".

โšก $g->vg_activate ($activate, \@volgroups);

This command activates or (if "activate" is false) deactivates all logical volumes in the listed volume groups "volgroups". ๐Ÿ‘‘

This command is the same as running "vgchange -a y|n volgroups..."

Note that if "volgroups" is an empty list then all volume groups are activated or deactivated. ๐ŸŒ€

This function depends on the feature "lvm2". See also "$g->feature-available".

๐ŸŒˆ $g->vg_activate_all ($activate);

This command activates or (if "activate" is false) deactivates all logical volumes in all volume groups. main character energy honestly ๐Ÿ’–

This command is the same as running "vgchange -a y|n"

This function depends on the feature "lvm2". See also "$g->feature-available".

๐ŸŽฒ $g->vgchange_uuid ($vg);

Generate a new random UUID for the volume group "vg". ๐ŸŽฐ

This function depends on the feature "lvm2". See also "$g->feature-available".

๐ŸŽฐ $g->vgchange_uuid_all ();

Generate new random UUIDs for all volume groups. all of them. every single one. ๐Ÿ’…

This function depends on the feature "lvm2". See also "$g->feature-available".

๐Ÿงฑ $g->vgcreate ($volgroup, \@physvols);

This creates an LVM volume group called "volgroup" from the non-empty list of physical volumes "physvols". โœจ

This function depends on the feature "lvm2". See also "$g->feature-available".

๐Ÿ”— @uuids = $g->vglvuuids ($vgname);

Given a VG called "vgname", this returns the UUIDs of all the logical volumes created in this volume group. ๐Ÿงต

You can use this along with "$g->lvs" and "$g->lvuuid" calls to associate logical volumes and volume groups.

See also "$g->vgpvuuids". iykyk ๐Ÿซถ

๐Ÿ“ฆ $metadata = $g->vgmeta ($vgname);

"vgname" is an LVM volume group. This command examines the volume group and returns its metadata. ๐Ÿ”ฌ

โš ๏ธ Note that the metadata is an internal structure used by LVM, subject to change at any time, and is provided for information only. do not build your whole personality on it ๐Ÿ˜ญ

This function depends on the feature "lvm2". See also "$g->feature-available".

๐Ÿงท @uuids = $g->vgpvuuids ($vgname);

Given a VG called "vgname", this returns the UUIDs of all the physical volumes that this volume group resides on. ๐ŸŒธ

You can use this along with "$g->pvs" and "$g->pvuuid" calls to associate physical volumes and volume groups.

See also "$g->vglvuuids".

๐Ÿ—‘๏ธ $g->vgremove ($vgname);

Remove an LVM volume group "vgname", (for example "VG"). ๐Ÿ’€

This also forcibly removes all logical volumes in the volume group (if any). like, gone gone ๐Ÿ˜ณ

This function depends on the feature "lvm2". See also "$g->feature-available".

โœ๏ธ $g->vgrename ($volgroup, $newvolgroup);

Rename a volume group "volgroup" with the new name "newvolgroup". ๐ŸŽ€

๐Ÿ“‹ @volgroups = $g->vgs ();

List all the volumes groups detected. This is the equivalent of the vgs(8) command. ๐Ÿ‘‘

This returns a list of just the volume group names that were detected (eg. "VolGroup00").

See also "$g->vgs_full".

This function depends on the feature "lvm2". See also "$g->feature-available".

๐Ÿ“š @volgroups = $g->vgs_full ();

List all the volumes groups detected. This is the equivalent of the vgs(8) command. The "full" version includes all fields. the deluxe edition ๐Ÿ“

This function depends on the feature "lvm2". See also "$g->feature-available".

๐Ÿ”„ $g->vgscan ();

This rescans all block devices and rebuilds the list of LVM physical volumes, volume groups and logical volumes. ๐ŸŒ€

โš ๏ธ This function is deprecated. In new code, use the "lvm_scan" call instead.

Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions. not me using deprecated calls in 2024 ๐Ÿ’€

๐Ÿ†” $uuid = $g->vguuid ($vgname);

This command returns the UUID of the LVM VG named "vgname". โœจ

๐Ÿ’ค $g->wait_ready ();

This function is a no op. literally does nothing. iconique ๐Ÿ˜Œ

In versions of the API < 1.0.71 you had to call this function just after calling "$g->launch" to wait for the launch to complete. However this is no longer necessary because "$g->launch" now does the waiting. ๐Ÿ’…

If you see any calls to this function in code then you can just remove them, unless you want to retain compatibility with older versions of the API.

โš ๏ธ This function is deprecated. There is no replacement. Consult the API documentation in guestfs(3) for further information.

Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions.

๐Ÿ”ค $chars = $g->wc_c ($path);

This command counts the characters in a file, using the "wc -c" external command. ๐Ÿ”ข

๐Ÿ“„ $lines = $g->wc_l ($path);

This command counts the lines in a file, using the "wc -l" external command. ๐Ÿ“

๐Ÿ’ฌ $words = $g->wc_w ($path);

This command counts the words in a file, using the "wc -w" external command. ๐Ÿ—ฃ๏ธ

๐Ÿงฝ $g->wipefs ($device);

This command erases filesystem or RAID signatures from the specified "device" to make the filesystem invisible to libblkid. ๐Ÿ™ˆ

This does not erase the filesystem itself nor any other data from the "device". okay phew ๐Ÿ˜ฎโ€๐Ÿ’จ

Compare with "$g->zero" which zeroes the first few blocks of a device.

This function depends on the feature "wipefs". See also "$g->feature-available".

โœ๏ธ $g->write ($path, $content);

This call creates a file called "path". The content of the file is the string "content" (which can contain any 8 bit data). ๐Ÿ’–

See also "$g->write_append".

โž• $g->write_append ($path, $content);

This call appends "content" to the end of file "path". If "path" does not exist, then a new file is created. ๐ŸŽ€

See also "$g->write".

๐Ÿ“ $g->write_file ($path, $content, $size);

This call creates a file called "path". The contents of the file is the string "content" (which can contain any 8 bit data), with length "size".

As a special case, if "size" is 0 then the length is calculated using "strlen" (so in this case the content cannot contain embedded ASCII NULs). ๐Ÿซ 

๐Ÿ’€ NB. Owing to a bug, writing content containing ASCII NUL characters does not work, even if the length is specified.

Because of the message protocol, there is a transfer limit of somewhere between 2MB and 4MB. See "PROTOCOL LIMITS" in guestfs(3).

โš ๏ธ This function is deprecated. In new code, use the "write" call instead.

Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions.

๐Ÿ—‚๏ธ $g->xfs_admin ($device [, extunwritten => $extunwritten] [, imgfile => $imgfile] [, v2log => $v2log] [, projid32bit => $projid32bit] [, lazycounter => $lazycounter] [, label => $label] [, uuid => $uuid]);

Change the parameters of the XFS filesystem on "device". ๐Ÿ”ง

Devices that are mounted cannot be modified. Administrators must unmount filesystems before this call can modify parameters. like actually unmount it, bestie ๐Ÿ˜ค

Some of the parameters of a mounted filesystem can be examined and modified using the "$g->xfs_info" and "$g->xfs_growfs" calls.

Beginning with XFS version 5, it is no longer possible to modify the lazy-counters setting (ie. "lazycounter" parameter has no effect). rip ๐Ÿ’€

This function depends on the feature "xfs". See also "$g->feature-available".

๐ŸŒฑ $g->xfs_growfs ($path [, datasec => $datasec] [, logsec => $logsec] [, rtsec => $rtsec] [, datasize => $datasize] [, logsize => $logsize] [, rtsize => $rtsize] [, rtextsize => $rtextsize] [, maxpct => $maxpct]);

Grow the XFS filesystem mounted at "path". ๐ŸŒฟ growingggg

The returned struct contains geometry information. Missing fields are returned as -1 (for numeric fields) or empty string. ๐Ÿซถ

This function depends on the feature "xfs". See also "$g->feature-available".

๐Ÿ”Ž %info = $g->xfs_info ($pathordevice);

"pathordevice" is a mounted XFS filesystem or a device containing an XFS filesystem. This command returns the geometry of the filesystem. ๐Ÿฆ‹

The returned struct contains geometry information. Missing fields are returned as -1 (for numeric fields) or empty string. โœจ

That's it, bestie โ€” the last bunch of methods in this giant alphabet, then the cozy admin sections at the end. Let's land this plane โœˆ๏ธ๐Ÿ’–

btw, one leftover note from the entry above: this function depends on the feature "xfs". See also $g->feature-available.
  • $status = $g->xfs_repair ($device [, forcelogzero => $forcelogzero] [, nomodify => $nomodify] [, noprefetch => $noprefetch] [, forcegeometry => $forcegeometry] [, maxmem => $maxmem] [, ihashsize => $ihashsize] [, bhashsize => $bhashsize] [, agstride => $agstride] [, logdev => $logdev] [, rtdev => $rtdev]); โ€” repairs a corrupt or damaged XFS filesystem on device. ๐Ÿ› ๏ธ

The filesystem gets specified using the device argument, which should be the device name of the disk partition or volume containing the filesystem. If you hand it the name of a block device, xfs_repair will attempt to find the raw device associated with the specified block device and will use the raw device instead. iykyk.

Regardless, the filesystem to be repaired must be unmounted, otherwise the resulting filesystem may be inconsistent or corrupt. ๐Ÿ˜ญ Like, do not skip that part.

The returned status tells you whether filesystem corruption was detected (returns 1) or was not detected (returns 0).

This function depends on the feature "xfs". See also $g->feature-available.

  • $g->yara_destroy (); โ€” destroys previously loaded Yara rules so libguestfs resources get freed. ๐Ÿงน Bye bestie, thanks for the bytes.

This function depends on the feature "libyara". See also $g->feature-available.

  • $g->yara_load ($filename); โ€” uploads a set of Yara rules from the local file filename. ๐Ÿ“ค

Yara rules allow categorizing files based on textual or binary patterns within their content. Check $g->yara_scan to see how to scan files with the loaded rules.

Rules can be in binary format, as when compiled with the yarac command, or in source code format. In the latter case, the rules will be first compiled and then loaded.

Rules in source code format cannot include external files. In such cases it's recommended to compile them first โ€” like, save yourself the drama.

Previously loaded rules will be destroyed. ๐Ÿซถ

This function depends on the feature "libyara". See also $g->feature-available.

  • @detections = $g->yara_scan ($path); โ€” scans a file with the previously loaded Yara rules. ๐Ÿ”

For each matching rule, a yara_detection structure is returned.

The yara_detection structure contains the following fields:

  • "yara_name" โ€” path of the file matching a Yara rule.
  • "yara_rule" โ€” identifier of the Yara rule which matched against the given file.

This function depends on the feature "libyara". See also $g->feature-available.

  • @lines = $g->zegrep ($regex, $path); โ€” calls the external zegrep program and returns the matching lines. ๐Ÿ“œ

Because of the message protocol, there is a transfer limit of somewhere between 2MB and 4MB. See "PROTOCOL LIMITS" in guestfs(3). ๐Ÿšง

This function is deprecated. In new code, use the grep call instead. Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions. ๐Ÿ’€
  • @lines = $g->zegrepi ($regex, $path); โ€” calls the external zegrep -i program and returns the matching lines. Same energy, case-insensitive.

Because of the message protocol, there is a transfer limit of somewhere between 2MB and 4MB. See "PROTOCOL LIMITS" in guestfs(3).

This function is deprecated. In new code, use the grep call instead. Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions. ๐Ÿ’€
  • $g->zero ($device); โ€” writes zeroes over the first few blocks of device. 0๏ธโƒฃ

How many blocks are zeroed isn't specified (but it's not enough to securely wipe the device). It should be sufficient to remove any partition tables, filesystem superblocks and so on.

If blocks are already zero, then this command avoids writing zeroes. This prevents the underlying device from becoming non-sparse or growing unnecessarily. โœจ sparse queen behavior โœจ

See also: $g->zero_device, $g->scrub_device, $g->is_zero_device

  • $g->zero_device ($device); โ€” writes zeroes over the entire device. Compare with $g->zero, which just zeroes the first few blocks of a device. Big difference, bestie.

If blocks are already zero, then this command avoids writing zeroes. This prevents the underlying device from becoming non-sparse or growing unnecessarily.

  • $g->zero_free_space ($directory); โ€” zeroes the free space in the filesystem mounted on directory. The filesystem must be mounted read-write. โœ๏ธ

The filesystem contents are not affected, but any free space in the filesystem is freed.

Free space is not "trimmed". You may want to call $g->fstrim either as an alternative to this, or after calling this, depending on your requirements. ๐ŸŒธ

  • $g->zerofree ($device); โ€” runs the zerofree program on device. This program claims to zero unused inodes and disk blocks on an ext2/3 filesystem, thus making it possible to compress the filesystem more effectively. ๐Ÿ“ฆ

You should not run this program if the filesystem is mounted. ๐Ÿ™ˆ

It is possible that using this program can damage the filesystem or data on the filesystem. Likeโ€ฆ actually possible. Be careful.

This function depends on the feature "zerofree". See also $g->feature-available.

  • @lines = $g->zfgrep ($pattern, $path); โ€” calls the external zfgrep program and returns the matching lines.

Because of the message protocol, there is a transfer limit of somewhere between 2MB and 4MB. See "PROTOCOL LIMITS" in guestfs(3).

This function is deprecated. In new code, use the grep call instead. Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions. ๐Ÿ’€
  • @lines = $g->zfgrepi ($pattern, $path); โ€” calls the external zfgrep -i program and returns the matching lines.

Because of the message protocol, there is a transfer limit of somewhere between 2MB and 4MB. See "PROTOCOL LIMITS" in guestfs(3).

This function is deprecated. In new code, use the grep call instead. Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions. ๐Ÿ’€
  • $description = $g->zfile ($meth, $path); โ€” runs file(1) after first decompressing path using meth. ๐Ÿ—‚๏ธ

meth must be one of gzip, compress or bzip2.

Since 1.0.63, use $g->file instead which can now process compressed files. ๐ŸŽ€

This function is deprecated. In new code, use the file call instead. Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions. ๐Ÿ’€
  • @lines = $g->zgrep ($regex, $path); โ€” calls the external zgrep(1) program and returns the matching lines.

Because of the message protocol, there is a transfer limit of somewhere between 2MB and 4MB. See "PROTOCOL LIMITS" in guestfs(3).

This function is deprecated. In new code, use the grep call instead. Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions. ๐Ÿ’€
  • @lines = $g->zgrepi ($regex, $path); โ€” calls the external zgrep -i program and returns the matching lines. Last one, we made it!! ๐ŸŽ‰

Because of the message protocol, there is a transfer limit of somewhere between 2MB and 4MB. See "PROTOCOL LIMITS" in guestfs(3).

This function is deprecated. In new code, use the grep call instead. Deprecated functions will not be removed from the API, but the fact that they are deprecated indicates that there are problems with correct use of these functions. ๐Ÿ’€

โœจ AVAILABILITY โœจ

From time to time we add new libguestfs APIs. Also some libguestfs APIs won't be available in all builds of libguestfs (the Fedora build is full-featured, but other builds may disable features). So how do you test whether the APIs that your Perl program needs are available in the version of Sys::Guestfs that you're using? ๐Ÿ•ต๏ธโ€โ™€๏ธ

To test if a particular function is available in the Sys::Guestfs class, use the ordinary Perl UNIVERSAL method can(METHOD) (see perlobj(1)). For example:

 use Sys::Guestfs;
 if (defined (Sys::Guestfs->can ("set_verbose"))) {
   print "\$g->set_verbose is available\n";
 }

To test if particular features are supported by the current build, use the feature_available method like the example below. Note that the appliance must be launched first. ๐Ÿ‘‘

 $g->feature_available ( ["augeas"] );

For further discussion on this topic, refer to "AVAILABILITY" in guestfs(3).


๐ŸŽ€ STORING DATA IN THE HANDLE ๐ŸŽ€

The handle returned from new is a hash reference. The hash normally contains some elements:

 {
   _g => [private data used by libguestfs],
   _flags => [flags provided when creating the handle]
 }

Callers can add other elements to this hash to store data for their own purposes. The data lasts for the lifetime of the handle. ๐Ÿ’พ

Any fields whose names begin with an underscore are reserved for private use by libguestfs. We may add more in future. ๐Ÿ™…โ€โ™€๏ธ

It is recommended that callers prefix the name of their field(s) with some unique string, to avoid conflicts with other users. Lowkey the polite thing to do.


Copyright (C) 2009-2025 Red Hat Inc.


๐ŸŒˆ LICENSE ๐ŸŒˆ

Please see the file COPYING.LIB for the full license.


๐Ÿฆ‹ SEE ALSO ๐Ÿฆ‹

guestfs(3), guestfish(1), <http://libguestfs.org>.


And that's the whole page, bestie โ€” you ate that. ๐Ÿ’…โœจ This one's perl v5.42.3, dated 2025-08-13, and it's the Sys::Guestfs(3) manpage, signing off with a lil sparkle. ๐ŸŽ€๐Ÿซถ

๐Ÿ“ฆ where this page comes from