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 : \
46 =head2 As an interactive shell
50 Welcome to guestfish, the libguestfs filesystem interactive shell for
51 editing virtual machine filesystems.
53 Type: 'help' for help with commands
54 'quit' to quit the shell
60 Guestfish is a shell and command-line tool for examining and modifying
61 virtual machine filesystems. It uses libguestfs and exposes all of
62 the functionality of the guestfs API, see L<guestfs(3)>.
70 Displays general help on options.
72 =item B<-h> | B<--cmd-help>
74 Lists all available guestfish commands.
76 =item B<-h cmd> | B<--cmd-help cmd>
78 Displays detailed help on a single command C<cmd>.
80 =item B<-a image> | B<--add image>
82 Add a block device or virtual machine image to the shell.
84 =item B<-m dev[:mountpoint]> | B<--mount dev[:mountpoint]>
86 Mount the named partition or logical volume on the given mountpoint.
88 If the mountpoint is omitted, it defaults to C</>.
90 You have to mount something on C</> before most commands will work.
92 If any C<-m> or C<--mount> options are given, the guest is
93 automatically launched.
95 =item B<-n> | B<--no-sync>
97 Disable autosync. This is enabled by default. See the discussion
98 of autosync in the L<guestfs(3)> manpage.
100 =item B<-r> | B<--ro>
102 This changes the C<-m> option so that mounts are done read-only
103 (see C<guestfs_mount_ro> in the L<guestfs(3)> manpage).
105 =item B<-v> | B<--verbose>
107 Enable very verbose messages. This is particularly useful if you find
110 =item B<-D> | B<--no-dest-paths>
112 Don't tab-complete paths on the guest filesystem. It is useful to be
113 able to hit the tab key to complete paths on the guest filesystem, but
114 this causes extra "hidden" guestfs calls to be made, so this option is
115 here to allow this feature to be disabled.
119 =head1 COMMANDS ON COMMAND LINE
121 Any additional (non-option) arguments are treated as commands to
124 Commands to execute should be separated by a colon (C<:>), where the
125 colon is a separate parameter. Thus:
127 guestfish cmd [args...] : cmd [args...] : cmd [args...] ...
129 If there are no additional arguments, then we enter a shell, either an
130 interactive shell with a prompt (if the input is a terminal) or a
131 non-interactive shell.
133 In either command line mode or non-interactive shell, the first
134 command that gives an error causes the whole shell to exit. In
135 interactive mode (with a prompt) if a command fails, you can continue
138 =head1 USING launch (OR run)
140 As with L<guestfs(3)>, you must first configure your guest by adding
141 disks, then launch it, then mount any disks you need, and finally
142 issue actions/commands. So the general order of the day is:
164 C<run> is a synonym for C<launch>. You must C<launch> (or C<run>)
165 your guest before mounting or performing any other commands.
167 The only exception is that if the C<-m> or C<--mount> option was
168 given, the guest is automatically run for you (simply because
169 guestfish can't mount the disks you asked for without doing this).
173 You can quote ordinary parameters using either single or double
176 add "file with a space.img"
182 A few commands require a list of strings to be passed. For these, use
183 a space-separated list, enclosed in quotes. For example:
185 vgcreate VG "/dev/sda1 /dev/sdb1"
189 Any line which starts with a I<#> character is treated as a comment
190 and ignored. The I<#> can optionally be preceeded by whitespace,
191 but B<not> by a command. For example:
197 Blank lines are also ignored.
199 =head1 RUNNING COMMANDS LOCALLY
201 Any line which starts with a I<!> character is treated as a command
202 sent to the local shell (C</bin/sh> or whatever L<system(3)> uses).
206 tgz-out /remote local/remote-data.tar.gz
208 will create a directory C<local> on the host, and then export
209 the contents of C</remote> on the mounted filesystem to
210 C<local/remote-data.tar.gz>. (See C<tgz-out>).
212 =head1 EXIT ON ERROR BEHAVIOUR
214 By default, guestfish will ignore any errors when in interactive mode
215 (ie. taking commands from a human over a tty), and will exit on the
216 first error in non-interactive mode (scripts, commands given on the
219 If you prefix a command with a I<-> character, then that command will
220 not cause guestfish to exit, even if that (one) command returns an
230 Without any parameter, this lists all commands. With a C<cmd>
231 parameter, this displays detailed help for a command.
235 This exits guestfish. You can also use C<^D> key.
237 =head2 alloc | allocate
241 This creates an empty (zeroed) file of the given size, and then adds
242 so it can be further examined.
244 For more advanced image creation, see L<qemu-img(1)> utility.
246 Size can be specified (where C<nn> means a number):
250 =item C<nn> or C<nn>K or C<nn>KB
252 number of kilobytes, eg: C<1440> = standard 3.5in floppy
254 =item C<nn>M or C<nn>MB
258 =item C<nn>G or C<nn>GB
264 number of 512 byte sectors
272 This echos the parameters to the terminal.
274 =head2 edit | vi | emacs
278 This is used to edit a file. It downloads the file, edits it
279 locally using your editor, then uploads the result.
281 The editor is C<$EDITOR>. However if you use the alternate
282 commands C<vi> or C<emacs> you will get those corresponding
285 NOTE: This will not work reliably for large files
286 (> 2 MB) or binary files containing \0 bytes.
292 Change the local directory, ie. the current directory of guestfish
295 Note that C<!cd> won't do what you might expect.
299 =head1 ENVIRONMENT VARIABLES
303 =item LIBGUESTFS_DEBUG
305 Set C<LIBGUESTFS_DEBUG=1> to enable verbose messages. This has the
306 same effect as using the B<-v> option.
308 =item LIBGUESTFS_PATH
310 Set the path that guestfish uses to search for kernel and initrd.img.
311 See the discussion of paths in L<guestfs(3)>.
313 =item LIBGUESTFS_QEMU
315 Set the default qemu binary that libguestfs uses. If not set, then
316 the qemu which was found at compile time by the configure script is
319 =item LIBGUESTFS_APPEND
321 Pass additional options to the guest kernel.
325 If compiled with GNU readline support, then the command history
326 is saved in C<$HOME/.guestfish>
330 The C<edit> command uses C<$EDITOR> as the editor. If not
337 guestfish returns I<0> if the commands completed without error, or
338 I<1> if there was an error.
343 L<http://libguestfs.org/>.
347 Richard W.M. Jones (C<rjones at redhat dot com>)
351 Copyright (C) 2009 Red Hat Inc.
352 L<http://libguestfs.org/>
354 This program is free software; you can redistribute it and/or modify
355 it under the terms of the GNU General Public License as published by
356 the Free Software Foundation; either version 2 of the License, or
357 (at your option) any later version.
359 This program is distributed in the hope that it will be useful,
360 but WITHOUT ANY WARRANTY; without even the implied warranty of
361 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
362 GNU General Public License for more details.
364 You should have received a copy of the GNU General Public License
365 along with this program; if not, write to the Free Software
366 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.