5 guestfish - the libguestfs filesystem interactive shell
9 guestfish [--options] [commands]
11 guestfish -i libvirt-domain
13 guestfish -i disk-image(s)
17 =head2 From shell scripts
19 Create a new C</etc/motd> file in a guest:
24 mount /dev/VolGroup00/LogVol00 /
25 write_file /etc/motd "Hello users" 0
28 List the LVs in a guest:
36 =head2 On the command line
38 List the LVM PVs in a guest image:
40 guestfish add disk.img : run : pvs
42 Remove C</boot/grub/menu.lst> (in reality not such a great idea):
44 guestfish --add disk.img \
45 --mount /dev/VolGroup00/LogVol00 \
46 --mount /dev/sda1:/boot \
47 rm /boot/grub/menu.lst
49 =head2 As an interactive shell
53 Welcome to guestfish, the libguestfs filesystem interactive shell for
54 editing virtual machine filesystems.
56 Type: 'help' for help with commands
57 'quit' to quit the shell
61 =head2 As a script interpreter
63 #!/usr/bin/guestfish -f
64 alloc /tmp/output.img 10M
66 sfdisk /dev/sda 0 0 0 ,
71 Guestfish is a shell and command-line tool for examining and modifying
72 virtual machine filesystems. It uses libguestfs and exposes all of
73 the functionality of the guestfs API, see L<guestfs(3)>.
81 Displays general help on options.
83 =item B<-h> | B<--cmd-help>
85 Lists all available guestfish commands.
87 =item B<-h cmd> | B<--cmd-help cmd>
89 Displays detailed help on a single command C<cmd>.
91 =item B<-a image> | B<--add image>
93 Add a block device or virtual machine image to the shell.
95 =item B<-f file> | B<--file file>
97 Read commands from C<file>. To write pure guestfish
100 #!/usr/bin/guestfish -f
102 =item B<-i> | B<--inspector>
104 Run virt-inspector on the named libvirt domain or list of disk
105 images. If virt-inspector is available and if it can identify
106 the domain or disk images, then partitions will be mounted
107 correctly at start-up.
109 Typical usage is either:
113 (for an inactive libvirt domain called I<myguest>), or:
115 guestfish --ro -i myguest
117 (for active domains, readonly), or specify the block device directly:
119 guestfish -i /dev/Guests/MyGuest
121 You cannot use I<-a> or I<-m> in conjunction with this option, and
122 options other than I<--ro> might not behave correctly.
124 See also: L<virt-inspector(1)>.
126 =item B<-m dev[:mountpoint]> | B<--mount dev[:mountpoint]>
128 Mount the named partition or logical volume on the given mountpoint.
130 If the mountpoint is omitted, it defaults to C</>.
132 You have to mount something on C</> before most commands will work.
134 If any C<-m> or C<--mount> options are given, the guest is
135 automatically launched.
137 =item B<-n> | B<--no-sync>
139 Disable autosync. This is enabled by default. See the discussion
140 of autosync in the L<guestfs(3)> manpage.
142 =item B<-r> | B<--ro>
144 This changes the C<-m> option so that mounts are done read-only
145 (see C<guestfs_mount_ro> in the L<guestfs(3)> manpage).
147 =item B<-v> | B<--verbose>
149 Enable very verbose messages. This is particularly useful if you find
152 =item B<-D> | B<--no-dest-paths>
154 Don't tab-complete paths on the guest filesystem. It is useful to be
155 able to hit the tab key to complete paths on the guest filesystem, but
156 this causes extra "hidden" guestfs calls to be made, so this option is
157 here to allow this feature to be disabled.
159 =item B<-V> | B<--version>
161 Display the guestfish / libguestfs version number and exit.
165 =head1 COMMANDS ON COMMAND LINE
167 Any additional (non-option) arguments are treated as commands to
170 Commands to execute should be separated by a colon (C<:>), where the
171 colon is a separate parameter. Thus:
173 guestfish cmd [args...] : cmd [args...] : cmd [args...] ...
175 If there are no additional arguments, then we enter a shell, either an
176 interactive shell with a prompt (if the input is a terminal) or a
177 non-interactive shell.
179 In either command line mode or non-interactive shell, the first
180 command that gives an error causes the whole shell to exit. In
181 interactive mode (with a prompt) if a command fails, you can continue
184 =head1 USING launch (OR run)
186 As with L<guestfs(3)>, you must first configure your guest by adding
187 disks, then launch it, then mount any disks you need, and finally
188 issue actions/commands. So the general order of the day is:
210 C<run> is a synonym for C<launch>. You must C<launch> (or C<run>)
211 your guest before mounting or performing any other commands.
213 The only exception is that if the C<-m> or C<--mount> option was
214 given, the guest is automatically run for you (simply because
215 guestfish can't mount the disks you asked for without doing this).
219 You can quote ordinary parameters using either single or double
222 add "file with a space.img"
228 A few commands require a list of strings to be passed. For these, use
229 a space-separated list, enclosed in quotes. For example:
231 vgcreate VG "/dev/sda1 /dev/sdb1"
233 =head1 WILDCARDS AND GLOBBING
235 Neither guestfish nor the underlying guestfs API performs
236 wildcard expansion (globbing) by default. So for example the
237 following will not do what you expect:
241 Assuming you don't have a directory literally called C</home/*>
242 then the above command will return an error.
244 To perform wildcard expansion, use the C<glob> command.
248 runs C<rm-rf> on each path that matches (ie. potentially running
249 the command many times), equivalent to:
255 C<glob> only works on simple guest paths and not on device names.
257 If you have several parameters, each containing a wildcard, then glob
258 will perform a cartesian product.
262 Any line which starts with a I<#> character is treated as a comment
263 and ignored. The I<#> can optionally be preceeded by whitespace,
264 but B<not> by a command. For example:
270 Blank lines are also ignored.
272 =head1 RUNNING COMMANDS LOCALLY
274 Any line which starts with a I<!> character is treated as a command
275 sent to the local shell (C</bin/sh> or whatever L<system(3)> uses).
279 tgz-out /remote local/remote-data.tar.gz
281 will create a directory C<local> on the host, and then export
282 the contents of C</remote> on the mounted filesystem to
283 C<local/remote-data.tar.gz>. (See C<tgz-out>).
287 Use C<command E<lt>spaceE<gt> | command> to pipe the output of the
288 first command (a guestfish command) to the second command (any host
289 command). For example:
291 cat /etc/passwd | awk -F: '$3 == 0 { print }'
293 (where C<cat> is the guestfish cat command, but C<awk> is the host awk
294 program). The above command would list all accounts in the guest
295 filesystem which have UID 0, ie. root accounts including backdoors.
298 hexdump /bin/ls | head
299 list-devices | tail -1
301 The space before the pipe symbol is required, any space after the pipe
302 symbol is optional. Everything after the pipe symbol is just passed
303 straight to the host shell, so it can contain redirections, globs and
304 anything else that makes sense on the host side.
306 To use a literal argument which begins with a pipe symbol, you have
311 =head1 EXIT ON ERROR BEHAVIOUR
313 By default, guestfish will ignore any errors when in interactive mode
314 (ie. taking commands from a human over a tty), and will exit on the
315 first error in non-interactive mode (scripts, commands given on the
318 If you prefix a command with a I<-> character, then that command will
319 not cause guestfish to exit, even if that (one) command returns an
322 =head1 GUESTFISH COMMANDS
324 The commands in this section are guestfish convenience commands, in
325 other words, they are not part of the L<guestfs(3)> API.
327 =head2 alloc | allocate
331 This creates an empty (zeroed) file of the given size, and then adds
332 so it can be further examined.
334 For more advanced image creation, see L<qemu-img(1)> utility.
336 Size can be specified (where C<nn> means a number):
340 =item C<nn> or C<nn>K or C<nn>KB
342 number of kilobytes, eg: C<1440> = standard 3.5in floppy
344 =item C<nn>M or C<nn>MB
348 =item C<nn>G or C<nn>GB
354 number of 512 byte sectors
362 This echos the parameters to the terminal.
364 =head2 edit | vi | emacs
368 This is used to edit a file. It downloads the file, edits it
369 locally using your editor, then uploads the result.
371 The editor is C<$EDITOR>. However if you use the alternate
372 commands C<vi> or C<emacs> you will get those corresponding
375 NOTE: This will not work reliably for large files
376 (> 2 MB) or binary files containing \0 bytes.
382 Expand wildcards in any paths in the args list, and run C<command>
383 repeatedly on each matching path.
385 See section WILDCARDS AND GLOBBING.
392 Without any parameter, this lists all commands. With a C<cmd>
393 parameter, this displays detailed help for a command.
399 Change the local directory, ie. the current directory of guestfish
402 Note that C<!cd> won't do what you might expect.
410 This is used to view a file.
412 The default viewer is C<$PAGER>. However if you use the alternate
413 command C<less> you will get the C<less> command specifically.
415 NOTE: This will not work reliably for large files
416 (> 2 MB) or binary files containing \0 bytes.
420 This exits guestfish. You can also use C<^D> key.
426 Run the command as usual, but print the elapsed time afterwards. This
427 can be useful for benchmarking operations.
433 =head1 ENVIRONMENT VARIABLES
439 The C<edit> command uses C<$EDITOR> as the editor. If not
444 If compiled with GNU readline support, then the command history
445 is saved in C<$HOME/.guestfish>
447 =item LIBGUESTFS_APPEND
449 Pass additional options to the guest kernel.
451 =item LIBGUESTFS_DEBUG
453 Set C<LIBGUESTFS_DEBUG=1> to enable verbose messages. This has the
454 same effect as using the B<-v> option.
456 =item LIBGUESTFS_MEMSIZE
458 Set the memory allocated to the qemu process, in megabytes. For
461 LIBGUESTFS_MEMSIZE=700
463 =item LIBGUESTFS_PATH
465 Set the path that guestfish uses to search for kernel and initrd.img.
466 See the discussion of paths in L<guestfs(3)>.
468 =item LIBGUESTFS_QEMU
470 Set the default qemu binary that libguestfs uses. If not set, then
471 the qemu which was found at compile time by the configure script is
476 The C<more> command uses C<$PAGER> as the pager. If not
477 set, it uses C<more>.
483 guestfish returns I<0> if the commands completed without error, or
484 I<1> if there was an error.
489 L<http://libguestfs.org/>.
493 Richard W.M. Jones (C<rjones at redhat dot com>)
497 Copyright (C) 2009 Red Hat Inc.
498 L<http://libguestfs.org/>
500 This program is free software; you can redistribute it and/or modify
501 it under the terms of the GNU General Public License as published by
502 the Free Software Foundation; either version 2 of the License, or
503 (at your option) any later version.
505 This program is distributed in the hope that it will be useful,
506 but WITHOUT ANY WARRANTY; without even the implied warranty of
507 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
508 GNU General Public License for more details.
510 You should have received a copy of the GNU General Public License
511 along with this program; if not, write to the Free Software
512 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.