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