Added 'scrub-*' commands for securely scrubbing filesystems.
[libguestfs.git] / guestfish.pod
1 =encoding utf8
2
3 =head1 NAME
4
5 guestfish - the libguestfs filesystem interactive shell
6
7 =head1 SYNOPSIS
8
9  guestfish [--options] [commands]
10
11 =head1 EXAMPLES
12
13 =head2 From shell scripts
14
15 Create a new C</etc/motd> file in a guest:
16
17  guestfish <<_EOF_
18  add disk.img
19  run
20  mount /dev/VolGroup00/LogVol00 /
21  write_file /etc/motd "Hello users" 0
22  _EOF_
23
24 List the LVs in a guest:
25
26  guestfish <<_EOF_
27  add disk.img
28  run
29  lvs
30  _EOF_
31
32 =head2 On the command line
33
34 List the LVM PVs in a guest image:
35
36  guestfish add disk.img : run : pvs
37
38 Remove C</boot/grub/menu.lst> (in reality not such a great idea):
39
40  guestfish --add disk.img \
41    --mount /dev/VolGroup00/LogVol00 \
42    --mount /dev/sda1:/boot \
43    rm /boot/grub/menu.lst : \
44    sync : exit
45
46 =head2 As an interactive shell
47
48  $ guestfish
49  
50  Welcome to guestfish, the libguestfs filesystem interactive shell for
51  editing virtual machine filesystems.
52  
53  Type: 'help' for help with commands
54        'quit' to quit the shell
55  
56  ><fs> help
57
58 =head1 DESCRIPTION
59
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)>.
63
64 =head1 OPTIONS
65
66 =over 4
67
68 =item B<--help>
69
70 Displays general help on options.
71
72 =item B<-h> | B<--cmd-help>
73
74 Lists all available guestfish commands.
75
76 =item B<-h cmd> | B<--cmd-help cmd>
77
78 Displays detailed help on a single command C<cmd>.
79
80 =item B<-a image> | B<--add image>
81
82 Add a block device or virtual machine image to the shell.
83
84 =item B<-m dev[:mountpoint]> | B<--mount dev[:mountpoint]>
85
86 Mount the named partition or logical volume on the given mountpoint.
87
88 If the mountpoint is omitted, it defaults to C</>.
89
90 You have to mount something on C</> before most commands will work.
91
92 If any C<-m> or C<--mount> options are given, the guest is
93 automatically launched.
94
95 =item B<-n> | B<--no-sync>
96
97 Disable autosync.  This is enabled by default.  See the discussion
98 of autosync in the L<guestfs(3)> manpage.
99
100 =item B<-r> | B<--ro>
101
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).
104
105 =item B<-v> | B<--verbose>
106
107 Enable very verbose messages.  This is particularly useful if you find
108 a bug.
109
110 =item B<-D> | B<--no-dest-paths>
111
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.
116
117 =back
118
119 =head1 COMMANDS ON COMMAND LINE
120
121 Any additional (non-option) arguments are treated as commands to
122 execute.
123
124 Commands to execute should be separated by a colon (C<:>), where the
125 colon is a separate parameter.  Thus:
126
127  guestfish cmd [args...] : cmd [args...] : cmd [args...] ...
128
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.
132
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
136 to enter commands.
137
138 =head1 USING launch (OR run)
139
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:
143
144 =over 4
145
146 =item *
147
148 add or -a/--add
149
150 =item *
151
152 launch (aka run)
153
154 =item *
155
156 mount or -m/--mount
157
158 =item *
159
160 any other commands
161
162 =back
163
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.
166
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).
170
171 =head1 QUOTING
172
173 You can quote ordinary parameters using either single or double
174 quotes.  For example:
175
176  add "file with a space.img"
177
178  rm '/file name'
179
180  rm '/"'
181
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:
184
185  vgcreate VG "/dev/sda1 /dev/sdb1"
186
187 =head1 WILDCARDS AND GLOBBING
188
189 Neither guestfish nor the underlying guestfs API performs
190 wildcard expansion (globbing) by default.  So for example the
191 following will not do what you expect:
192
193  rm-rf /home/*
194
195 Assuming you don't have a directory literally called C</home/*>
196 then the above command will return an error.
197
198 To perform wildcard expansion, use the C<glob> command.
199
200  glob rm-rf /home/*
201
202 runs C<rm-rf> on each path that matches (ie. potentially running
203 the command many times), equivalent to:
204
205  rm-rf /home/jim
206  rm-rf /home/joe
207  rm-rf /home/mary
208
209 C<glob> only works on simple guest paths and not on device names.
210
211 If you have several parameters, each containing a wildcard, then glob
212 will perform a cartesian product.
213
214 =head1 COMMENTS
215
216 Any line which starts with a I<#> character is treated as a comment
217 and ignored.  The I<#> can optionally be preceeded by whitespace,
218 but B<not> by a command.  For example:
219
220  # this is a comment
221          # this is a comment
222  foo # NOT a comment
223
224 Blank lines are also ignored.
225
226 =head1 RUNNING COMMANDS LOCALLY
227
228 Any line which starts with a I<!> character is treated as a command
229 sent to the local shell (C</bin/sh> or whatever L<system(3)> uses).
230 For example:
231
232  !mkdir local
233  tgz-out /remote local/remote-data.tar.gz
234
235 will create a directory C<local> on the host, and then export
236 the contents of C</remote> on the mounted filesystem to
237 C<local/remote-data.tar.gz>.  (See C<tgz-out>).
238
239 =head1 EXIT ON ERROR BEHAVIOUR
240
241 By default, guestfish will ignore any errors when in interactive mode
242 (ie. taking commands from a human over a tty), and will exit on the
243 first error in non-interactive mode (scripts, commands given on the
244 command line).
245
246 If you prefix a command with a I<-> character, then that command will
247 not cause guestfish to exit, even if that (one) command returns an
248 error.
249
250 =head1 COMMANDS
251
252 =head2 help
253
254  help
255  help cmd
256
257 Without any parameter, this lists all commands.  With a C<cmd>
258 parameter, this displays detailed help for a command.
259
260 =head2 quit | exit
261
262 This exits guestfish.  You can also use C<^D> key.
263
264 =head2 alloc | allocate
265
266  alloc filename size
267
268 This creates an empty (zeroed) file of the given size, and then adds
269 so it can be further examined.
270
271 For more advanced image creation, see L<qemu-img(1)> utility.
272
273 Size can be specified (where C<nn> means a number):
274
275 =over 4
276
277 =item C<nn> or C<nn>K or C<nn>KB
278
279 number of kilobytes, eg: C<1440> = standard 3.5in floppy
280
281 =item C<nn>M or C<nn>MB
282
283 number of megabytes
284
285 =item C<nn>G or C<nn>GB
286
287 number of gigabytes
288
289 =item C<nn>sects
290
291 number of 512 byte sectors
292
293 =back
294
295 =head2 echo
296
297  echo [params ...]
298
299 This echos the parameters to the terminal.
300
301 =head2 edit | vi | emacs
302
303  edit filename
304
305 This is used to edit a file.  It downloads the file, edits it
306 locally using your editor, then uploads the result.
307
308 The editor is C<$EDITOR>.  However if you use the alternate
309 commands C<vi> or C<emacs> you will get those corresponding
310 editors.
311
312 NOTE: This will not work reliably for large files
313 (> 2 MB) or binary files containing \0 bytes.
314
315 =head2 lcd
316
317  lcd directory
318
319 Change the local directory, ie. the current directory of guestfish
320 itself.
321
322 Note that C<!cd> won't do what you might expect.
323
324 =head2 glob
325
326  glob command args...
327
328 Expand wildcards in any paths in the args list, and run C<command>
329 repeatedly on each matching path.
330
331 See section WILDCARDS AND GLOBBING.
332
333 @ACTIONS@
334
335 =head1 ENVIRONMENT VARIABLES
336
337 =over 4
338
339 =item LIBGUESTFS_DEBUG
340
341 Set C<LIBGUESTFS_DEBUG=1> to enable verbose messages.  This has the
342 same effect as using the B<-v> option.
343
344 =item LIBGUESTFS_PATH
345
346 Set the path that guestfish uses to search for kernel and initrd.img.
347 See the discussion of paths in L<guestfs(3)>.
348
349 =item LIBGUESTFS_QEMU
350
351 Set the default qemu binary that libguestfs uses.  If not set, then
352 the qemu which was found at compile time by the configure script is
353 used.
354
355 =item LIBGUESTFS_APPEND
356
357 Pass additional options to the guest kernel.
358
359 =item HOME
360
361 If compiled with GNU readline support, then the command history
362 is saved in C<$HOME/.guestfish>
363
364 =item EDITOR
365
366 The C<edit> command uses C<$EDITOR> as the editor.  If not
367 set, it uses C<vi>.
368
369 =back
370
371 =head1 EXIT CODE
372
373 guestfish returns I<0> if the commands completed without error, or
374 I<1> if there was an error.
375
376 =head1 SEE ALSO
377
378 L<guestfs(3)>,
379 L<http://libguestfs.org/>.
380
381 =head1 AUTHORS
382
383 Richard W.M. Jones (C<rjones at redhat dot com>)
384
385 =head1 COPYRIGHT
386
387 Copyright (C) 2009 Red Hat Inc.
388 L<http://libguestfs.org/>
389
390 This program is free software; you can redistribute it and/or modify
391 it under the terms of the GNU General Public License as published by
392 the Free Software Foundation; either version 2 of the License, or
393 (at your option) any later version.
394
395 This program is distributed in the hope that it will be useful,
396 but WITHOUT ANY WARRANTY; without even the implied warranty of
397 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
398 GNU General Public License for more details.
399
400 You should have received a copy of the GNU General Public License
401 along with this program; if not, write to the Free Software
402 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.