Revert "Add 'set-kernel'/'get-kernel'/LIBGUESTFS_KERNEL to override appliance kernel."
[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 =head2 Remote control
70
71  eval `guestfish --listen`
72  guestfish --remote cmd
73
74 =head1 DESCRIPTION
75
76 Guestfish is a shell and command-line tool for examining and modifying
77 virtual machine filesystems.  It uses libguestfs and exposes all of
78 the functionality of the guestfs API, see L<guestfs(3)>.
79
80 =head1 OPTIONS
81
82 =over 4
83
84 =item B<--help>
85
86 Displays general help on options.
87
88 =item B<-h> | B<--cmd-help>
89
90 Lists all available guestfish commands.
91
92 =item B<-h cmd> | B<--cmd-help cmd>
93
94 Displays detailed help on a single command C<cmd>.
95
96 =item B<-a image> | B<--add image>
97
98 Add a block device or virtual machine image to the shell.
99
100 =item B<-D> | B<--no-dest-paths>
101
102 Don't tab-complete paths on the guest filesystem.  It is useful to be
103 able to hit the tab key to complete paths on the guest filesystem, but
104 this causes extra "hidden" guestfs calls to be made, so this option is
105 here to allow this feature to be disabled.
106
107 =item B<-f file> | B<--file file>
108
109 Read commands from C<file>.  To write pure guestfish
110 scripts, use:
111
112  #!/usr/bin/guestfish -f
113
114 =item B<-i> | B<--inspector>
115
116 Run virt-inspector on the named libvirt domain or list of disk
117 images.  If virt-inspector is available and if it can identify
118 the domain or disk images, then partitions will be mounted
119 correctly at start-up.
120
121 Typical usage is either:
122
123  guestfish -i myguest
124
125 (for an inactive libvirt domain called I<myguest>), or:
126
127  guestfish --ro -i myguest
128
129 (for active domains, readonly), or specify the block device directly:
130
131  guestfish -i /dev/Guests/MyGuest
132
133 You cannot use I<-a>, I<-m>, I<--listen> or I<--remote> in conjunction
134 with this option, and options other than I<--ro> might not behave
135 correctly.
136
137 See also: L<virt-inspector(1)>.
138
139 =item B<--listen>
140
141 Fork into the background and listen for remote commands.  See section
142 I<REMOTE CONTROL GUESTFISH OVER A SOCKET> below.
143
144 =item B<-m dev[:mountpoint]> | B<--mount dev[:mountpoint]>
145
146 Mount the named partition or logical volume on the given mountpoint.
147
148 If the mountpoint is omitted, it defaults to C</>.
149
150 You have to mount something on C</> before most commands will work.
151
152 If any C<-m> or C<--mount> options are given, the guest is
153 automatically launched.
154
155 =item B<-n> | B<--no-sync>
156
157 Disable autosync.  This is enabled by default.  See the discussion
158 of autosync in the L<guestfs(3)> manpage.
159
160 =item B<--remote[=pid]>
161
162 Send remote commands to C<$GUESTFISH_PID> or C<pid>.  See section
163 I<REMOTE CONTROL GUESTFISH OVER A SOCKET> below.
164
165 =item B<-r> | B<--ro>
166
167 This changes the C<-m> option so that mounts are done read-only
168 (see C<guestfs_mount_ro> in the L<guestfs(3)> manpage).
169
170 =item B<-v> | B<--verbose>
171
172 Enable very verbose messages.  This is particularly useful if you find
173 a bug.
174
175 =item B<-V> | B<--version>
176
177 Display the guestfish / libguestfs version number and exit.
178
179 =item B<-x>
180
181 Echo each command before executing it.
182
183 =back
184
185 =head1 COMMANDS ON COMMAND LINE
186
187 Any additional (non-option) arguments are treated as commands to
188 execute.
189
190 Commands to execute should be separated by a colon (C<:>), where the
191 colon is a separate parameter.  Thus:
192
193  guestfish cmd [args...] : cmd [args...] : cmd [args...] ...
194
195 If there are no additional arguments, then we enter a shell, either an
196 interactive shell with a prompt (if the input is a terminal) or a
197 non-interactive shell.
198
199 In either command line mode or non-interactive shell, the first
200 command that gives an error causes the whole shell to exit.  In
201 interactive mode (with a prompt) if a command fails, you can continue
202 to enter commands.
203
204 =head1 USING launch (OR run)
205
206 As with L<guestfs(3)>, you must first configure your guest by adding
207 disks, then launch it, then mount any disks you need, and finally
208 issue actions/commands.  So the general order of the day is:
209
210 =over 4
211
212 =item *
213
214 add or -a/--add
215
216 =item *
217
218 launch (aka run)
219
220 =item *
221
222 mount or -m/--mount
223
224 =item *
225
226 any other commands
227
228 =back
229
230 C<run> is a synonym for C<launch>.  You must C<launch> (or C<run>)
231 your guest before mounting or performing any other commands.
232
233 The only exception is that if the C<-m> or C<--mount> option was
234 given, the guest is automatically run for you (simply because
235 guestfish can't mount the disks you asked for without doing this).
236
237 =head1 QUOTING
238
239 You can quote ordinary parameters using either single or double
240 quotes.  For example:
241
242  add "file with a space.img"
243
244  rm '/file name'
245
246  rm '/"'
247
248 A few commands require a list of strings to be passed.  For these, use
249 a space-separated list, enclosed in quotes.  For example:
250
251  vgcreate VG "/dev/sda1 /dev/sdb1"
252
253 =head1 WILDCARDS AND GLOBBING
254
255 Neither guestfish nor the underlying guestfs API performs
256 wildcard expansion (globbing) by default.  So for example the
257 following will not do what you expect:
258
259  rm-rf /home/*
260
261 Assuming you don't have a directory literally called C</home/*>
262 then the above command will return an error.
263
264 To perform wildcard expansion, use the C<glob> command.
265
266  glob rm-rf /home/*
267
268 runs C<rm-rf> on each path that matches (ie. potentially running
269 the command many times), equivalent to:
270
271  rm-rf /home/jim
272  rm-rf /home/joe
273  rm-rf /home/mary
274
275 C<glob> only works on simple guest paths and not on device names.
276
277 If you have several parameters, each containing a wildcard, then glob
278 will perform a cartesian product.
279
280 =head1 COMMENTS
281
282 Any line which starts with a I<#> character is treated as a comment
283 and ignored.  The I<#> can optionally be preceeded by whitespace,
284 but B<not> by a command.  For example:
285
286  # this is a comment
287          # this is a comment
288  foo # NOT a comment
289
290 Blank lines are also ignored.
291
292 =head1 RUNNING COMMANDS LOCALLY
293
294 Any line which starts with a I<!> character is treated as a command
295 sent to the local shell (C</bin/sh> or whatever L<system(3)> uses).
296 For example:
297
298  !mkdir local
299  tgz-out /remote local/remote-data.tar.gz
300
301 will create a directory C<local> on the host, and then export
302 the contents of C</remote> on the mounted filesystem to
303 C<local/remote-data.tar.gz>.  (See C<tgz-out>).
304
305 =head1 PIPES
306
307 Use C<command E<lt>spaceE<gt> | command> to pipe the output of the
308 first command (a guestfish command) to the second command (any host
309 command).  For example:
310
311  cat /etc/passwd | awk -F: '$3 == 0 { print }'
312
313 (where C<cat> is the guestfish cat command, but C<awk> is the host awk
314 program).  The above command would list all accounts in the guest
315 filesystem which have UID 0, ie. root accounts including backdoors.
316 Other examples:
317
318  hexdump /bin/ls | head
319  list-devices | tail -1
320
321 The space before the pipe symbol is required, any space after the pipe
322 symbol is optional.  Everything after the pipe symbol is just passed
323 straight to the host shell, so it can contain redirections, globs and
324 anything else that makes sense on the host side.
325
326 To use a literal argument which begins with a pipe symbol, you have
327 to quote it, eg:
328
329  echo "|"
330
331 =head1 HOME DIRECTORIES
332
333 If a parameter starts with the character C<~> then the tilde may be
334 expanded as a home directory path (either C<~> for the current user's
335 home directory, or C<~user> for another user).
336
337 Note that home directory expansion happens for users known I<on the
338 host>, not in the guest filesystem.
339
340 To use a literal argument which begins with a tilde, you have to quote
341 it, eg:
342
343  echo "~"
344
345 =head1 EXIT ON ERROR BEHAVIOUR
346
347 By default, guestfish will ignore any errors when in interactive mode
348 (ie. taking commands from a human over a tty), and will exit on the
349 first error in non-interactive mode (scripts, commands given on the
350 command line).
351
352 If you prefix a command with a I<-> character, then that command will
353 not cause guestfish to exit, even if that (one) command returns an
354 error.
355
356 =head1 REMOTE CONTROL GUESTFISH OVER A SOCKET
357
358 Guestfish can be remote-controlled over a socket.  This is useful
359 particularly in shell scripts where you want to make several different
360 changes to a filesystem, but you don't want the overhead of starting
361 up a guestfish process each time.
362
363 Start a guestfish server process using:
364
365  eval `guestfish --listen`
366
367 and then send it commands by doing:
368
369  guestfish --remote cmd [...]
370
371 To cause the server to exit, send it the exit command:
372
373  guestfish --remote exit
374
375 Note that the server will normally exit if there is an error in a
376 command.  You can change this in the usual way.  See section I<EXIT ON
377 ERROR BEHAVIOUR>.
378
379 =head2 CONTROLLING MULTIPLE GUESTFISH PROCESSES
380
381 The C<eval> statement sets the environment variable C<$GUESTFISH_PID>,
382 which is how the C<--remote> option knows where to send the commands.
383 You can have several guestfish listener processes running using:
384
385  eval `guestfish --listen`
386  pid1=$GUESTFISH_PID
387  eval `guestfish --listen`
388  pid2=$GUESTFISH_PID
389  ...
390  guestfish --remote=$pid1 cmd
391  guestfish --remote=$pid2 cmd
392
393 =head2 STANDARD OUTPUT DURING REMOTE CONTROL
394
395 Because of limitations in the C<eval> statement, stdout from the
396 listener is currently redirected to C</dev/null>.
397
398 Stderr is unchanged.
399
400 =head2 REMOTE CONTROL DETAILS
401
402 Remote control happens over a Unix domain socket called
403 C</tmp/.guestfish-$UID/socket-$PID>, where C<$UID> is the effective
404 user ID of the process, and C<$PID> is the process ID of the server.
405
406 Guestfish client and server versions must match exactly.
407
408 =head1 GUESTFISH COMMANDS
409
410 The commands in this section are guestfish convenience commands, in
411 other words, they are not part of the L<guestfs(3)> API.
412
413 =head2 alloc | allocate
414
415  alloc filename size
416
417 This creates an empty (zeroed) file of the given size, and then adds
418 so it can be further examined.
419
420 For more advanced image creation, see L<qemu-img(1)> utility.
421
422 Size can be specified (where C<nn> means a number):
423
424 =over 4
425
426 =item C<nn> or C<nn>K or C<nn>KB
427
428 number of kilobytes, eg: C<1440> = standard 3.5in floppy
429
430 =item C<nn>M or C<nn>MB
431
432 number of megabytes
433
434 =item C<nn>G or C<nn>GB
435
436 number of gigabytes
437
438 =item C<nn>sects
439
440 number of 512 byte sectors
441
442 =back
443
444 =head2 echo
445
446  echo [params ...]
447
448 This echos the parameters to the terminal.
449
450 =head2 edit | vi | emacs
451
452  edit filename
453
454 This is used to edit a file.  It downloads the file, edits it
455 locally using your editor, then uploads the result.
456
457 The editor is C<$EDITOR>.  However if you use the alternate
458 commands C<vi> or C<emacs> you will get those corresponding
459 editors.
460
461 NOTE: This will not work reliably for large files
462 (> 2 MB) or binary files containing \0 bytes.
463
464 =head2 glob
465
466  glob command args...
467
468 Expand wildcards in any paths in the args list, and run C<command>
469 repeatedly on each matching path.
470
471 See section WILDCARDS AND GLOBBING.
472
473 =head2 help
474
475  help
476  help cmd
477
478 Without any parameter, this lists all commands.  With a C<cmd>
479 parameter, this displays detailed help for a command.
480
481 =head2 lcd
482
483  lcd directory
484
485 Change the local directory, ie. the current directory of guestfish
486 itself.
487
488 Note that C<!cd> won't do what you might expect.
489
490 =head2 more | less
491
492  more filename
493
494  less filename
495
496 This is used to view a file.
497
498 The default viewer is C<$PAGER>.  However if you use the alternate
499 command C<less> you will get the C<less> command specifically.
500
501 NOTE: This will not work reliably for large files
502 (> 2 MB) or binary files containing \0 bytes.
503
504 =head2 quit | exit
505
506 This exits guestfish.  You can also use C<^D> key.
507
508 =head2 reopen
509
510  reopen
511
512 Close and reopen the libguestfs handle.  It is not necessary to use
513 this normally, because the handle is closed properly when guestfish
514 exits.  However this is occasionally useful for testing.
515
516 =head2 time
517
518  time command args...
519
520 Run the command as usual, but print the elapsed time afterwards.  This
521 can be useful for benchmarking operations.
522
523 =head1 COMMANDS
524
525 @ACTIONS@
526
527 =head1 ENVIRONMENT VARIABLES
528
529 =over 4
530
531 =item EDITOR
532
533 The C<edit> command uses C<$EDITOR> as the editor.  If not
534 set, it uses C<vi>.
535
536 =item GUESTFISH_PID
537
538 Used with the I<--remote> option to specify the remote guestfish
539 process to control.  See section I<REMOTE CONTROL GUESTFISH OVER A
540 SOCKET>.
541
542 =item HOME
543
544 If compiled with GNU readline support, then the command history
545 is saved in C<$HOME/.guestfish>
546
547 =item LIBGUESTFS_APPEND
548
549 Pass additional options to the guest kernel.
550
551 =item LIBGUESTFS_DEBUG
552
553 Set C<LIBGUESTFS_DEBUG=1> to enable verbose messages.  This has the
554 same effect as using the B<-v> option.
555
556 =item LIBGUESTFS_MEMSIZE
557
558 Set the memory allocated to the qemu process, in megabytes.  For
559 example:
560
561  LIBGUESTFS_MEMSIZE=700
562
563 =item LIBGUESTFS_PATH
564
565 Set the path that guestfish uses to search for kernel and initrd.img.
566 See the discussion of paths in L<guestfs(3)>.
567
568 =item LIBGUESTFS_QEMU
569
570 Set the default qemu binary that libguestfs uses.  If not set, then
571 the qemu which was found at compile time by the configure script is
572 used.
573
574 =item PAGER
575
576 The C<more> command uses C<$PAGER> as the pager.  If not
577 set, it uses C<more>.
578
579 =item TMPDIR
580
581 Location of temporary directory, defaults to C</tmp>.
582
583 If libguestfs was compiled to use the supermin appliance then each
584 handle will require rather a large amount of space in this directory
585 for short periods of time (~ 80 MB).  You can use C<$TMPDIR> to
586 configure another directory to use in case C</tmp> is not large
587 enough.
588
589 =back
590
591 =head1 EXIT CODE
592
593 guestfish returns I<0> if the commands completed without error, or
594 I<1> if there was an error.
595
596 =head1 SEE ALSO
597
598 L<guestfs(3)>,
599 L<http://libguestfs.org/>.
600
601 =head1 AUTHORS
602
603 Richard W.M. Jones (C<rjones at redhat dot com>)
604
605 =head1 COPYRIGHT
606
607 Copyright (C) 2009 Red Hat Inc.
608 L<http://libguestfs.org/>
609
610 This program is free software; you can redistribute it and/or modify
611 it under the terms of the GNU General Public License as published by
612 the Free Software Foundation; either version 2 of the License, or
613 (at your option) any later version.
614
615 This program is distributed in the hope that it will be useful,
616 but WITHOUT ANY WARRANTY; without even the implied warranty of
617 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
618 GNU General Public License for more details.
619
620 You should have received a copy of the GNU General Public License
621 along with this program; if not, write to the Free Software
622 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.