Implement guestfish -f option to allow guestfish scripts.
[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
45 =head2 As an interactive shell
46
47  $ guestfish
48  
49  Welcome to guestfish, the libguestfs filesystem interactive shell for
50  editing virtual machine filesystems.
51  
52  Type: 'help' for help with commands
53        'quit' to quit the shell
54  
55  ><fs> help
56
57 =head2 As a script interpreter
58
59  #!/usr/bin/guestfish -f
60  alloc /tmp/output.img 10M
61  run
62  sfdisk /dev/sda 0 0 0 ,
63  mkfs ext2 /dev/sda1
64
65 =head1 DESCRIPTION
66
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)>.
70
71 =head1 OPTIONS
72
73 =over 4
74
75 =item B<--help>
76
77 Displays general help on options.
78
79 =item B<-h> | B<--cmd-help>
80
81 Lists all available guestfish commands.
82
83 =item B<-h cmd> | B<--cmd-help cmd>
84
85 Displays detailed help on a single command C<cmd>.
86
87 =item B<-a image> | B<--add image>
88
89 Add a block device or virtual machine image to the shell.
90
91 =item B<-f file> | B<--file file>
92
93 Read commands from C<file>.  To write pure guestfish
94 scripts, use:
95
96  #!/usr/bin/guestfish -f
97
98 =item B<-m dev[:mountpoint]> | B<--mount dev[:mountpoint]>
99
100 Mount the named partition or logical volume on the given mountpoint.
101
102 If the mountpoint is omitted, it defaults to C</>.
103
104 You have to mount something on C</> before most commands will work.
105
106 If any C<-m> or C<--mount> options are given, the guest is
107 automatically launched.
108
109 =item B<-n> | B<--no-sync>
110
111 Disable autosync.  This is enabled by default.  See the discussion
112 of autosync in the L<guestfs(3)> manpage.
113
114 =item B<-r> | B<--ro>
115
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).
118
119 =item B<-v> | B<--verbose>
120
121 Enable very verbose messages.  This is particularly useful if you find
122 a bug.
123
124 =item B<-D> | B<--no-dest-paths>
125
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.
130
131 =back
132
133 =head1 COMMANDS ON COMMAND LINE
134
135 Any additional (non-option) arguments are treated as commands to
136 execute.
137
138 Commands to execute should be separated by a colon (C<:>), where the
139 colon is a separate parameter.  Thus:
140
141  guestfish cmd [args...] : cmd [args...] : cmd [args...] ...
142
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.
146
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
150 to enter commands.
151
152 =head1 USING launch (OR run)
153
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:
157
158 =over 4
159
160 =item *
161
162 add or -a/--add
163
164 =item *
165
166 launch (aka run)
167
168 =item *
169
170 mount or -m/--mount
171
172 =item *
173
174 any other commands
175
176 =back
177
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.
180
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).
184
185 =head1 QUOTING
186
187 You can quote ordinary parameters using either single or double
188 quotes.  For example:
189
190  add "file with a space.img"
191
192  rm '/file name'
193
194  rm '/"'
195
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:
198
199  vgcreate VG "/dev/sda1 /dev/sdb1"
200
201 =head1 WILDCARDS AND GLOBBING
202
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:
206
207  rm-rf /home/*
208
209 Assuming you don't have a directory literally called C</home/*>
210 then the above command will return an error.
211
212 To perform wildcard expansion, use the C<glob> command.
213
214  glob rm-rf /home/*
215
216 runs C<rm-rf> on each path that matches (ie. potentially running
217 the command many times), equivalent to:
218
219  rm-rf /home/jim
220  rm-rf /home/joe
221  rm-rf /home/mary
222
223 C<glob> only works on simple guest paths and not on device names.
224
225 If you have several parameters, each containing a wildcard, then glob
226 will perform a cartesian product.
227
228 =head1 COMMENTS
229
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:
233
234  # this is a comment
235          # this is a comment
236  foo # NOT a comment
237
238 Blank lines are also ignored.
239
240 =head1 RUNNING COMMANDS LOCALLY
241
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).
244 For example:
245
246  !mkdir local
247  tgz-out /remote local/remote-data.tar.gz
248
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>).
252
253 =head1 EXIT ON ERROR BEHAVIOUR
254
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
258 command line).
259
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
262 error.
263
264 =head1 COMMANDS
265
266 =head2 help
267
268  help
269  help cmd
270
271 Without any parameter, this lists all commands.  With a C<cmd>
272 parameter, this displays detailed help for a command.
273
274 =head2 quit | exit
275
276 This exits guestfish.  You can also use C<^D> key.
277
278 =head2 alloc | allocate
279
280  alloc filename size
281
282 This creates an empty (zeroed) file of the given size, and then adds
283 so it can be further examined.
284
285 For more advanced image creation, see L<qemu-img(1)> utility.
286
287 Size can be specified (where C<nn> means a number):
288
289 =over 4
290
291 =item C<nn> or C<nn>K or C<nn>KB
292
293 number of kilobytes, eg: C<1440> = standard 3.5in floppy
294
295 =item C<nn>M or C<nn>MB
296
297 number of megabytes
298
299 =item C<nn>G or C<nn>GB
300
301 number of gigabytes
302
303 =item C<nn>sects
304
305 number of 512 byte sectors
306
307 =back
308
309 =head2 echo
310
311  echo [params ...]
312
313 This echos the parameters to the terminal.
314
315 =head2 edit | vi | emacs
316
317  edit filename
318
319 This is used to edit a file.  It downloads the file, edits it
320 locally using your editor, then uploads the result.
321
322 The editor is C<$EDITOR>.  However if you use the alternate
323 commands C<vi> or C<emacs> you will get those corresponding
324 editors.
325
326 NOTE: This will not work reliably for large files
327 (> 2 MB) or binary files containing \0 bytes.
328
329 =head2 lcd
330
331  lcd directory
332
333 Change the local directory, ie. the current directory of guestfish
334 itself.
335
336 Note that C<!cd> won't do what you might expect.
337
338 =head2 glob
339
340  glob command args...
341
342 Expand wildcards in any paths in the args list, and run C<command>
343 repeatedly on each matching path.
344
345 See section WILDCARDS AND GLOBBING.
346
347 @ACTIONS@
348
349 =head1 ENVIRONMENT VARIABLES
350
351 =over 4
352
353 =item LIBGUESTFS_DEBUG
354
355 Set C<LIBGUESTFS_DEBUG=1> to enable verbose messages.  This has the
356 same effect as using the B<-v> option.
357
358 =item LIBGUESTFS_PATH
359
360 Set the path that guestfish uses to search for kernel and initrd.img.
361 See the discussion of paths in L<guestfs(3)>.
362
363 =item LIBGUESTFS_QEMU
364
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
367 used.
368
369 =item LIBGUESTFS_APPEND
370
371 Pass additional options to the guest kernel.
372
373 =item HOME
374
375 If compiled with GNU readline support, then the command history
376 is saved in C<$HOME/.guestfish>
377
378 =item EDITOR
379
380 The C<edit> command uses C<$EDITOR> as the editor.  If not
381 set, it uses C<vi>.
382
383 =back
384
385 =head1 EXIT CODE
386
387 guestfish returns I<0> if the commands completed without error, or
388 I<1> if there was an error.
389
390 =head1 SEE ALSO
391
392 L<guestfs(3)>,
393 L<http://libguestfs.org/>.
394
395 =head1 AUTHORS
396
397 Richard W.M. Jones (C<rjones at redhat dot com>)
398
399 =head1 COPYRIGHT
400
401 Copyright (C) 2009 Red Hat Inc.
402 L<http://libguestfs.org/>
403
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.
408
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.
413
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.