guestfish(1) Virtualization Support guestfish(1)
guestfish - the guest filesystem shell
guestfish [--options] [commands]
guestfish [--ro|--rw] -a disk.img
guestfish [--ro|--rw] -a disk.img -m dev[:mountpoint]
guestfish -d libvirt-domain
guestfish [--ro|--rw] -a disk.img -i
guestfish -d libvirt-domain -i
Using guestfish in read/write mode on live virtual machines can be dangerous, potentially causing disk corruption. Use the --ro (read-
only) option to use guestfish safely if the disk image or virtual machine might be live.
Guestfish is a shell and command-line tool for examining and modifying virtual machine filesystems. It uses libguestfs and exposes all of
the functionality of the guestfs API, see guestfs(3).
Guestfish gives you structured access to the libguestfs API, from shell scripts or the command line or interactively. If you want to
rescue a broken virtual machine image, you should look at the virt-rescue(1) command.
As an interactive shell
Welcome to guestfish, the guest filesystem shell for
editing virtual machine filesystems.
Type: 'help' for a list of commands
'man' to read the manual
'quit' to quit the shell
><fs> add-ro disk.img
><fs> mount /dev/vg_guest/lv_root /
><fs> cat /etc/fstab
# Created by anaconda
From shell scripts
Create a new "/etc/motd" file in a guest or disk image:
mount /dev/vg_guest/lv_root /
write /etc/motd "Welcome, new users"
List the LVM logical volumes in a disk image:
guestfish -a disk.img --ro <<_EOF_
List all the filesystems in a disk image:
guestfish -a disk.img --ro <<_EOF_
On one command line
Update "/etc/resolv.conf" in a guest:
add disk.img : run : mount /dev/vg_guest/lv_root / :
write /etc/resolv.conf "nameserver 22.214.171.124"
Edit "/boot/grub/grub.conf" interactively:
guestfish --rw --add disk.img
Mount disks automatically
Use the -i option to automatically mount the disks from a virtual machine:
guestfish --ro -a disk.img -i cat /etc/group
guestfish --ro -d libvirt-domain -i cat /etc/group
Another way to edit "/boot/grub/grub.conf" interactively is:
guestfish --rw -a disk.img -i edit /boot/grub/grub.conf
As a script interpreter
Create a 100MB disk containing an ext2-formatted partition:
sparse test1.img 100M
part-disk /dev/sda mbr
mkfs ext2 /dev/sda1
Start with a prepared disk
An alternate way to create a 100MB disk called "test1.img" containing a single ext2-formatted partition:
guestfish -N fs
To list what is available do:
guestfish -N help | less
Access a remote disk using ssh:
guestfish -a ssh://example.com/path/to/disk.img
eval "`guestfish --listen`"
guestfish --remote add-ro disk.img
guestfish --remote run
guestfish --remote lvs
Displays general help on options.
Lists all available guestfish commands.
Displays detailed help on a single command "cmd".
Add a block device or virtual machine image to the shell.
The format of the disk image is auto-detected. To override this and force a particular format use the --format=.. option.
Using this flag is mostly equivalent to using the "add" command, with "readonly:true" if the --ro flag was given, and with "format:..."
if the --format=... flag was given.
Add a remote disk. See "ADDING REMOTE STORAGE".
When used in conjunction with the -d option, this specifies the libvirt URI to use. The default is to use the default libvirt
If using the --listen option and a csh-like shell, use this option. See section "REMOTE CONTROL AND CSH" below.
Add disks from the named libvirt domain. If the --ro option is also used, then any libvirt domain can be used. However in write mode,
only libvirt domains which are shut down can be named here.
Domain UUIDs can be used instead of names.
Using this flag is mostly equivalent to using the "add-domain" command, with "readonly:true" if the --ro flag was given, and with
"format:..." if the --format=... flag was given.
Don't tab-complete paths on the guest filesystem. It is useful to be able to hit the tab key to complete paths on the guest
filesystem, but this causes extra "hidden" guestfs calls to be made, so this option is here to allow this feature to be disabled.
When prompting for keys and passphrases, guestfish normally turns echoing off so you cannot see what you are typing. If you are not
worried about Tempest attacks and there is no one else in the room you can specify this flag to see what you are typing.
Read commands from "file". To write pure guestfish scripts, use:
The default for the -a option is to auto-detect the format of the disk image. Using this forces the disk format for -a options which
follow on the command line. Using --format with no argument switches back to auto-detection for subsequent -a options.
guestfish --format=raw -a disk.img
forces raw format (no auto-detection) for "disk.img".
guestfish --format=raw -a disk.img --format -a another.img
forces raw format (no auto-detection) for "disk.img" and reverts to auto-detection for "another.img".
If you have untrusted raw-format guest disk images, you should use this option to specify the disk format. This avoids a possible
security problem with malicious guests (CVE-2010-3851). See also "add".
Using virt-inspector(1) code, inspect the disks looking for an operating system and mount filesystems as they would be mounted on the
real virtual machine.
Typical usage is either:
guestfish -d myguest -i
(for an inactive libvirt domain called myguest), or:
guestfish --ro -d myguest -i
(for active domains, readonly), or specify the block device directly:
guestfish --rw -a /dev/Guests/MyGuest -i
Note that the command line syntax changed slightly over older versions of guestfish. You can still use the old syntax:
guestfish [--ro] -i disk.img
guestfish [--ro] -i libvirt-domain
Using this flag is mostly equivalent to using the "inspect-os" command and then using other commands to mount the filesystems that were
Read key or passphrase parameters from stdin. The default is to try to read passphrases from the user by opening "/dev/tty".
Fork into the background and listen for remote commands. See section "REMOTE CONTROL GUESTFISH OVER A SOCKET" below.
Connect to a live virtual machine. (Experimental, see "ATTACHING TO RUNNING DAEMONS" in guestfs(3)).
Mount the named partition or logical volume on the given mountpoint.
If the mountpoint is omitted, it defaults to "/".
You have to mount something on "/" before most commands will work.
If any -m or --mount options are given, the guest is automatically launched.
If you don't know what filesystems a disk image contains, you can either run guestfish without this option, then list the partitions,
filesystems and LVs available (see "list-partitions", "list-filesystems" and "lvs" commands), or you can use the virt-filesystems(1)
The third (and rarely used) part of the mount parameter is the list of mount options used to mount the underlying filesystem. If this
is not given, then the mount options are either the empty string or "ro" (the latter if the --ro flag is used). By specifying the
mount options, you override this default choice. Probably the only time you would use this is to enable ACLs and/or extended
attributes if the filesystem can support them:
Using this flag is equivalent to using the "mount-options" command.
The fourth part of the parameter is the filesystem driver to use, such as "ext3" or "ntfs". This is rarely needed, but can be useful if
multiple drivers are valid for a filesystem (eg: "ext2" and "ext3"), or if libguestfs misidentifies a filesystem.
Enable QEMU user networking in the guest.
Prepare a fresh disk image formatted as "type". This is an alternative to the -a option: whereas -a adds an existing disk, -N creates
a preformatted disk with a filesystem and adds it. See "PREPARED DISK IMAGES" below.
Disable autosync. This is enabled by default. See the discussion of autosync in the guestfs(3) manpage.
If writes fail to pipe commands (see "PIPES" below), then the command returns an error.
The default (also for historical reasons) is to ignore such errors so that:
><fs> command_with_lots_of_output | head
doesn't give an error.
Enable progress bars, even when guestfish is used non-interactively.
Progress bars are enabled by default when guestfish is used as an interactive shell.
Disable progress bars.
Send remote commands to $GUESTFISH_PID or "pid". See section "REMOTE CONTROL GUESTFISH OVER A SOCKET" below.
This changes the -a, -d and -m options so that disks are added and mounts are done read-only.
The option must always be used if the disk image or virtual machine might be running, and is generally recommended in cases where you
don't need write access to the disk.
Note that prepared disk images created with -N are not affected by this option. Also commands like "add" are not affected - you have
to specify the "readonly:true" option explicitly if you need it.
See also "OPENING DISKS FOR READ AND WRITE" below.
Enable SELinux support for the guest. See "SELINUX" in guestfs(3).
Enable very verbose messages. This is particularly useful if you find a bug.
Display the guestfish / libguestfs version number and exit.
This changes the -a, -d and -m options so that disks are added and mounts are done read-write.
See "OPENING DISKS FOR READ AND WRITE" below.
-x Echo each command before executing it.
COMMANDS ON COMMAND LINE
Any additional (non-option) arguments are treated as commands to execute.
Commands to execute should be separated by a colon (":"), where the colon is a separate parameter. Thus:
guestfish cmd [args...] : cmd [args...] : cmd [args...] ...
If there are no additional arguments, then we enter a shell, either an interactive shell with a prompt (if the input is a terminal) or a
In either command line mode or non-interactive shell, the first command that gives an error causes the whole shell to exit. In interactive
mode (with a prompt) if a command fails, you can continue to enter commands.
USING launch (OR run)
As with guestfs(3), you must first configure your guest by adding disks, then launch it, then mount any disks you need, and finally issue
actions/commands. So the general order of the day is:
o add or -a/--add
o launch (aka run)
o mount or -m/--mount
o any other commands
"run" is a synonym for "launch". You must "launch" (or "run") your guest before mounting or performing any other commands.
The only exception is that if any of the -i, -m, --mount, -N or --new options were given then "run" is done automatically, simply because
guestfish can't perform the action you asked for without doing this.
OPENING DISKS FOR READ AND WRITE
The guestfish, guestmount(1) and virt-rescue(1) options --ro and --rw affect whether the other command line options -a, -c, -d, -i and -m
open disk images read-only or for writing.
In libguestfs <= 1.10, guestfish, guestmount and virt-rescue defaulted to opening disk images supplied on the command line for write. To
open a disk image read-only you have to do -a image --ro.
This matters: If you accidentally open a live VM disk image writable then you will cause irreversible disk corruption.
In a future libguestfs we intend to change the default the other way. Disk images will be opened read-only. You will have to either
specify guestfish --rw, guestmount --rw, virt-rescue --rw, or change the configuration file "/etc/libguestfs-tools.conf" in order to get
write access for disk images specified by those other command line options.
This version of guestfish, guestmount and virt-rescue has a --rw option which does nothing (it is already the default). However it is
highly recommended that you use this option to indicate that you need write access, and prepare your scripts for the day when this option
will be required for write access.
Note: This does not affect commands like "add" and "mount", or any other libguestfs program apart from guestfish and guestmount.
You can quote ordinary parameters using either single or double quotes. For example:
add "file with a space.img"
rm '/file name'
A few commands require a list of strings to be passed. For these, use a whitespace-separated list, enclosed in quotes. Strings containing
whitespace to be passed through must be enclosed in single quotes. A literal single quote must be escaped with a backslash.
vgcreate VG "/dev/sda1 /dev/sdb1"
command "/bin/echo 'foo bar'"
command "/bin/echo 'foo'"
ESCAPE SEQUENCES IN DOUBLE QUOTED ARGUMENTS
In double-quoted arguments (only) use backslash to insert special characters:
Alert (bell) character.
Form feed character.
Carriage return character.
Horizontal tab character.
Vertical tab character.
A literal double quote character.
A character with octal value ooo. There must be precisely 3 octal digits (unlike C).
A character with hex value hh. There must be precisely 2 hex digits.
In the current implementation "