guestunmount(1) Unmount a guestmounted filesystem


guestunmount mountpoint
guestunmount --fd=<FD> mountpoint


guestunmount is a utility to clean up mounted filesystems automatically. guestmount(1) mounts filesystems using libguestfs. This program unmounts the filesystem when a program or script has finished with it.

guestunmount is a wrapper around the FUSE fusermount(1) program, which must exist on the current "PATH".

There are two ways to use guestunmount. When called as:

 guestunmount mountpoint

it unmounts "mountpoint" immediately.

When called as:

 guestunmount --fd=FD mountpoint

it waits until the pipe "FD" is closed. This can be used to monitor another process and clean up its mountpoint when that process exits, as described below.


You can just call "guestunmount mountpoint" from the program, but a more sophisticated way to use guestunmount is to have it monitor your program so it can clean up the mount point if your program exits unexpectedly.

In the program, create a pipe (eg. by calling pipe(2)). Let "FD" be the file descriptor number of the read side of the pipe (ie. "pipefd[0]").

After mounting the filesystem with guestmount(1) (on "mountpoint"), fork and run guestunmount like this:

 guestunmount --fd=FD mountpoint

Close the read side of the pipe in the parent process.

Now, when the write side of the pipe (ie. "pipefd[1]") is closed for any reason, either explicitly or because the parent process exits, guestunmount notices and unmounts the mountpoint.

If your operating system supports it, you should set the "FD_CLOEXEC" flag on the write side of the pipe. This is so that other child processes don't inherit the file descriptor and keep it open.

Guestunmount never daemonizes itself.


Since bash doesn't provide a way to create an unnamed pipe, use a trap to call guestunmount on exit like this:

 trap "guestunmount mountpoint" EXIT INT QUIT TERM


Specify the pipe file descriptor to monitor, and delay cleanup until that pipe is closed.
Don't display error messages from fusermount. The return status is still set (see ``EXIT STATUS'' below).
By default, guestunmount will retry the fusermount operation up to 5 times (that is, it will run it up to 6 times = 1 try + 5 retries).

Use --no-retry to make guestunmount run fusermount only once.

Use --retry=N to make guestunmount retry "N" times instead of 5.

guestunmount performs an exponential back-off between retries, waiting 1 second, 2 seconds, 4 seconds, etc before each retry.



The fusermount(1) program (supplied by FUSE) must be available on the current "PATH".


This program returns 0 if successful, or one of the following error codes:
Program error, eg. could not allocate memory, could not run fusermount. See the error message printed for more information.
The mount point could not be unmounted even after retrying. See the error message printed for the underlying fusermount error.
The mount point is not mounted.


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


Copyright (C) 2013 Red Hat Inc.



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

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

When reporting a bug, please supply:

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