5 guestfish - the libguestfs filesystem interactive shell
9 guestfish [--options] [commands]
13 =head2 From shell scripts
15 Create a new C</etc/motd> file in a guest:
20 mount /dev/VolGroup00/LogVol00 /
21 write_file /etc/motd "Hello users" 0
24 List the LVs in a guest:
32 =head2 On the command line
34 List the LVM PVs in a guest image:
36 guestfish add disk.img : run : pvs
38 Remove C</boot/grub/menu.lst> (in reality not such a great idea):
40 guestfish --add disk.img \
41 --mount /dev/VolGroup00/LogVol00 \
42 --mount /dev/sda1:/boot \
43 rm /boot/grub/menu.lst
45 =head2 As an interactive shell
49 Welcome to guestfish, the libguestfs filesystem interactive shell for
50 editing virtual machine filesystems.
52 Type: 'help' for help with commands
53 'quit' to quit the shell
57 =head2 As a script interpreter
59 #!/usr/bin/guestfish -f
60 alloc /tmp/output.img 10M
62 sfdisk /dev/sda 0 0 0 ,
67 Guestfish is a shell and command-line tool for examining and modifying
68 virtual machine filesystems. It uses libguestfs and exposes all of
69 the functionality of the guestfs API, see L<guestfs(3)>.
77 Displays general help on options.
79 =item B<-h> | B<--cmd-help>
81 Lists all available guestfish commands.
83 =item B<-h cmd> | B<--cmd-help cmd>
85 Displays detailed help on a single command C<cmd>.
87 =item B<-a image> | B<--add image>
89 Add a block device or virtual machine image to the shell.
91 =item B<-f file> | B<--file file>
93 Read commands from C<file>. To write pure guestfish
96 #!/usr/bin/guestfish -f
98 =item B<-m dev[:mountpoint]> | B<--mount dev[:mountpoint]>
100 Mount the named partition or logical volume on the given mountpoint.
102 If the mountpoint is omitted, it defaults to C</>.
104 You have to mount something on C</> before most commands will work.
106 If any C<-m> or C<--mount> options are given, the guest is
107 automatically launched.
109 =item B<-n> | B<--no-sync>
111 Disable autosync. This is enabled by default. See the discussion
112 of autosync in the L<guestfs(3)> manpage.
114 =item B<-r> | B<--ro>
116 This changes the C<-m> option so that mounts are done read-only
117 (see C<guestfs_mount_ro> in the L<guestfs(3)> manpage).
119 =item B<-v> | B<--verbose>
121 Enable very verbose messages. This is particularly useful if you find
124 =item B<-D> | B<--no-dest-paths>
126 Don't tab-complete paths on the guest filesystem. It is useful to be
127 able to hit the tab key to complete paths on the guest filesystem, but
128 this causes extra "hidden" guestfs calls to be made, so this option is
129 here to allow this feature to be disabled.
133 =head1 COMMANDS ON COMMAND LINE
135 Any additional (non-option) arguments are treated as commands to
138 Commands to execute should be separated by a colon (C<:>), where the
139 colon is a separate parameter. Thus:
141 guestfish cmd [args...] : cmd [args...] : cmd [args...] ...
143 If there are no additional arguments, then we enter a shell, either an
144 interactive shell with a prompt (if the input is a terminal) or a
145 non-interactive shell.
147 In either command line mode or non-interactive shell, the first
148 command that gives an error causes the whole shell to exit. In
149 interactive mode (with a prompt) if a command fails, you can continue
152 =head1 USING launch (OR run)
154 As with L<guestfs(3)>, you must first configure your guest by adding
155 disks, then launch it, then mount any disks you need, and finally
156 issue actions/commands. So the general order of the day is:
178 C<run> is a synonym for C<launch>. You must C<launch> (or C<run>)
179 your guest before mounting or performing any other commands.
181 The only exception is that if the C<-m> or C<--mount> option was
182 given, the guest is automatically run for you (simply because
183 guestfish can't mount the disks you asked for without doing this).
187 You can quote ordinary parameters using either single or double
190 add "file with a space.img"
196 A few commands require a list of strings to be passed. For these, use
197 a space-separated list, enclosed in quotes. For example:
199 vgcreate VG "/dev/sda1 /dev/sdb1"
201 =head1 WILDCARDS AND GLOBBING
203 Neither guestfish nor the underlying guestfs API performs
204 wildcard expansion (globbing) by default. So for example the
205 following will not do what you expect:
209 Assuming you don't have a directory literally called C</home/*>
210 then the above command will return an error.
212 To perform wildcard expansion, use the C<glob> command.
216 runs C<rm-rf> on each path that matches (ie. potentially running
217 the command many times), equivalent to:
223 C<glob> only works on simple guest paths and not on device names.
225 If you have several parameters, each containing a wildcard, then glob
226 will perform a cartesian product.
230 Any line which starts with a I<#> character is treated as a comment
231 and ignored. The I<#> can optionally be preceeded by whitespace,
232 but B<not> by a command. For example:
238 Blank lines are also ignored.
240 =head1 RUNNING COMMANDS LOCALLY
242 Any line which starts with a I<!> character is treated as a command
243 sent to the local shell (C</bin/sh> or whatever L<system(3)> uses).
247 tgz-out /remote local/remote-data.tar.gz
249 will create a directory C<local> on the host, and then export
250 the contents of C</remote> on the mounted filesystem to
251 C<local/remote-data.tar.gz>. (See C<tgz-out>).
253 =head1 EXIT ON ERROR BEHAVIOUR
255 By default, guestfish will ignore any errors when in interactive mode
256 (ie. taking commands from a human over a tty), and will exit on the
257 first error in non-interactive mode (scripts, commands given on the
260 If you prefix a command with a I<-> character, then that command will
261 not cause guestfish to exit, even if that (one) command returns an
271 Without any parameter, this lists all commands. With a C<cmd>
272 parameter, this displays detailed help for a command.
276 This exits guestfish. You can also use C<^D> key.
278 =head2 alloc | allocate
282 This creates an empty (zeroed) file of the given size, and then adds
283 so it can be further examined.
285 For more advanced image creation, see L<qemu-img(1)> utility.
287 Size can be specified (where C<nn> means a number):
291 =item C<nn> or C<nn>K or C<nn>KB
293 number of kilobytes, eg: C<1440> = standard 3.5in floppy
295 =item C<nn>M or C<nn>MB
299 =item C<nn>G or C<nn>GB
305 number of 512 byte sectors
313 This echos the parameters to the terminal.
315 =head2 edit | vi | emacs
319 This is used to edit a file. It downloads the file, edits it
320 locally using your editor, then uploads the result.
322 The editor is C<$EDITOR>. However if you use the alternate
323 commands C<vi> or C<emacs> you will get those corresponding
326 NOTE: This will not work reliably for large files
327 (> 2 MB) or binary files containing \0 bytes.
333 Change the local directory, ie. the current directory of guestfish
336 Note that C<!cd> won't do what you might expect.
342 Expand wildcards in any paths in the args list, and run C<command>
343 repeatedly on each matching path.
345 See section WILDCARDS AND GLOBBING.
349 =head1 ENVIRONMENT VARIABLES
353 =item LIBGUESTFS_DEBUG
355 Set C<LIBGUESTFS_DEBUG=1> to enable verbose messages. This has the
356 same effect as using the B<-v> option.
358 =item LIBGUESTFS_PATH
360 Set the path that guestfish uses to search for kernel and initrd.img.
361 See the discussion of paths in L<guestfs(3)>.
363 =item LIBGUESTFS_QEMU
365 Set the default qemu binary that libguestfs uses. If not set, then
366 the qemu which was found at compile time by the configure script is
369 =item LIBGUESTFS_APPEND
371 Pass additional options to the guest kernel.
375 If compiled with GNU readline support, then the command history
376 is saved in C<$HOME/.guestfish>
380 The C<edit> command uses C<$EDITOR> as the editor. If not
387 guestfish returns I<0> if the commands completed without error, or
388 I<1> if there was an error.
393 L<http://libguestfs.org/>.
397 Richard W.M. Jones (C<rjones at redhat dot com>)
401 Copyright (C) 2009 Red Hat Inc.
402 L<http://libguestfs.org/>
404 This program is free software; you can redistribute it and/or modify
405 it under the terms of the GNU General Public License as published by
406 the Free Software Foundation; either version 2 of the License, or
407 (at your option) any later version.
409 This program is distributed in the hope that it will be useful,
410 but WITHOUT ANY WARRANTY; without even the implied warranty of
411 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
412 GNU General Public License for more details.
414 You should have received a copy of the GNU General Public License
415 along with this program; if not, write to the Free Software
416 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.