Whamcloud - gitweb
debugfs.8, e2fsck.8: clarify man pages these programs can operate on files
[tools/e2fsprogs.git] / debugfs / debugfs.8.in
1 .\" -*- nroff -*-
2 .\" Copyright 1993, 1994, 1995 by Theodore Ts'o.  All Rights Reserved.
3 .\" This file may be copied under the terms of the GNU Public License.
4 .\"
5 .TH DEBUGFS 8 "@E2FSPROGS_MONTH@ @E2FSPROGS_YEAR@" "E2fsprogs version @E2FSPROGS_VERSION@"
6 .SH NAME
7 debugfs \- ext2/ext3/ext4 file system debugger
8 .SH SYNOPSIS
9 .B debugfs
10 [
11 .B \-DVwcin
12 ]
13 [
14 .B \-b
15 blocksize
16 ]
17 [
18 .B \-s
19 superblock
20 ]
21 [
22 .B \-f
23 cmd_file
24 ]
25 [
26 .B \-R
27 request
28 ]
29 [
30 .B \-d
31 data_source_device
32 ]
33 [
34 .B \-z
35 .I undo_file
36 ]
37 [
38 device
39 ]
40 .SH DESCRIPTION
41 The
42 .B debugfs
43 program is an interactive file system debugger. It can be used to
44 examine and change the state of an ext2, ext3, or ext4 file system.
45 .PP
46 .I device
47 is a block device (e.g., /dev/sdXX) or a file containing the file system.
48 .SH OPTIONS
49 .TP
50 .I \-w
51 Specifies that the file system should be opened in read-write mode.
52 Without this option, the file system is opened in read-only mode.
53 .TP
54 .I \-n
55 Disables metadata checksum verification.  This should only be used if
56 you believe the metadata to be correct despite the complaints of
57 e2fsprogs.
58 .TP
59 .I \-c
60 Specifies that the file system should be opened in catastrophic mode, in
61 which the inode and group bitmaps are not read initially.  This can be
62 useful for filesystems with significant corruption, but because of this,
63 catastrophic mode forces the filesystem to be opened read-only.
64 .TP
65 .I \-i
66 Specifies that
67 .I device
68 represents an ext2 image file created by the
69 .B e2image
70 program.  Since the ext2 image file only contains the superblock, block
71 group descriptor, block and inode allocation bitmaps, and
72 the inode table, many
73 .B debugfs
74 commands will not function properly.
75 .B Warning:
76 no safety checks are in place, and
77 .B debugfs
78 may fail in interesting ways if commands such as
79 .IR ls ", " dump ", "
80 etc. are tried without specifying the
81 .I data_source_device
82 using the
83 .I \-d
84 option.
85 .B debugfs
86 is a debugging tool.  It has rough edges!
87 .TP
88 .I -d data_source_device
89 Used with the
90 .I \-i
91 option, specifies that
92 .I data_source_device
93 should be used when reading blocks not found in the ext2 image file.
94 This includes data, directory, and indirect blocks.
95 .TP
96 .I -b blocksize
97 Forces the use of the given block size for the file system, rather than
98 detecting the correct block size as normal.
99 .TP
100 .I -s superblock
101 Causes the file system superblock to be read from the given block
102 number, instead of using the primary superblock (located at an offset of
103 1024 bytes from the beginning of the filesystem).  If you specify the
104 .I -s
105 option, you must also provide the blocksize of the filesystem via the
106 .I -b
107 option.
108 .TP
109 .I -f cmd_file
110 Causes
111 .B debugfs
112 to read in commands from
113 .IR cmd_file ,
114 and execute them.  When
115 .B debugfs
116 is finished executing those commands, it will exit.
117 .TP
118 .I -D
119 Causes
120 .B debugfs
121 to open the device using Direct I/O, bypassing the buffer cache.  Note
122 that some Linux devices, notably device mapper as of this writing, do
123 not support Direct I/O.
124 .TP
125 .I -R request
126 Causes
127 .B debugfs
128 to execute the single command
129 .IR request ,
130 and then exit.
131 .TP
132 .I -V
133 print the version number of
134 .B debugfs
135 and exit.
136 .TP
137 .BI \-z " undo_file"
138 Before overwriting a file system block, write the old contents of the block to
139 an undo file.  This undo file can be used with e2undo(8) to restore the old
140 contents of the file system should something go wrong.  If the empty string is
141 passed as the undo_file argument, the undo file will be written to a file named
142 resize2fs-\fIdevice\fR.e2undo in the directory specified via the
143 \fIE2FSPROGS_UNDO_DIR\fR environment variable.
144
145 WARNING: The undo file cannot be used to recover from a power or system crash.
146 .SH SPECIFYING FILES
147 Many
148 .B debugfs
149 commands take a
150 .I filespec
151 as an argument to specify an inode (as opposed to a pathname)
152 in the filesystem which is currently opened by
153 .BR debugfs .
154 The
155 .I filespec
156 argument may be specified in two forms.  The first form is an inode
157 number surrounded by angle brackets, e.g.,
158 .IR <2> .
159 The second form is a pathname; if the pathname is prefixed by a forward slash
160 ('/'), then it is interpreted relative to the root of the filesystem
161 which is currently opened by
162 .BR debugfs .
163 If not, the pathname is
164 interpreted relative to the current working directory as maintained by
165 .BR debugfs .
166 This may be modified by using the
167 .B debugfs
168 command
169 .IR cd .
170 .\"
171 .\"
172 .\"
173 .SH COMMANDS
174 This is a list of the commands which
175 .B debugfs
176 supports.
177 .TP
178 .BI blocks " filespace"
179 Print the blocks used by the inode
180 .I filespec
181 to stdout.
182 .TP
183 .BI bmap " [ -a ] filespec logical_block [physical_block]"
184 Print or set the physical block number corresponding to the logical block number
185 .I logical_block
186 in the inode
187 .IR filespec .
188 If the
189 .I -a
190 flag is specified, try to allocate a block if necessary.
191 .TP
192 .BI block_dump " [-f filespec] block_num"
193 Dump the filesystem block given by
194 .I block_num
195 in hex and ASCII format to the console.  If the
196 .I -f
197 option is specified, the block number is relative to the start of the given
198 .BR filespec .
199 .TP
200 .BI cat " filespec"
201 Dump the contents of the inode
202 .I filespec
203 to stdout.
204 .TP
205 .BI cd " filespec"
206 Change the current working directory to
207 .IR filespec .
208 .TP
209 .BI chroot " filespec"
210 Change the root directory to be the directory
211 .IR filespec .
212 .TP
213 .BI close " [-a]"
214 Close the currently open file system.  If the
215 .I -a
216 option is specified, write out any changes to the superblock and block
217 group descriptors to all of the backup superblocks, not just to the
218 master superblock.
219 .TP
220 .BI clri " filespec"
221 Clear the contents of the inode
222 .IR filespec .
223 .TP
224 .BI dirsearch " filespec filename"
225 Search the directory
226 .I filespec
227 for
228 .IR filename .
229 .TP
230 .B dirty
231 Mark the filesystem as dirty, so that the superblocks will be written on exit.
232 .TP
233 .BI dump " [-p] filespec out_file"
234 Dump the contents of the inode
235 .I filespec
236 to the output file
237 .IR out_file .
238 If the
239 .I -p
240 option is given set the owner, group and permissions information on
241 .I out_file
242 to match
243 .IR filespec .
244 .TP
245 .BI dump_mmp " [mmp_block]"
246 Display the multiple-mount protection (mmp) field values.  If
247 .I mmp_block
248 is specified then verify and dump the MMP values from the given block
249 number, otherwise use the
250 .B s_mmp_block
251 field in the superblock to locate and use the existing MMP block.
252 .TP
253 .BI dx_hash " [-h hash_alg] [-s hash_seed] filename"
254 Calculate the directory hash of
255 .IR filename .
256 The hash algorithm specified with
257 .I -h
258 may be
259 .BR legacy , " half_md4" ", or " tea .
260 The hash seed specified with
261 .I -s
262 must be in UUID format.
263 .TP
264 .BI dump_extents " [-n] [-l] filespec"
265 Dump the the extent tree of the inode
266 .IR filespec .
267 The
268 .I -n
269 flag will cause
270 .B dump_extents
271 to only display the interior nodes in the extent tree.   The
272 .I -l
273 flag will cause
274 .B dump_extents
275 to only display the leaf nodes in the extent tree.
276 .IP
277 (Please note that the length and range of blocks for the last extent in
278 an interior node is an estimate by the extents library functions, and is
279 not stored in filesystem data structures.   Hence, the values displayed
280 may not necessarily by accurate and does not indicate a problem or
281 corruption in the file system.)
282 .TP
283 .BI ea_get " [-f outfile] filespec attr_name"
284 Retrieve the value of the extended attribute
285 .I attr_name
286 in the file
287 .I filespec
288 and write it either to stdout or to \fIoutfile\fR.
289 .TP
290 .BI ea_list " filespec
291 List the extended attributes associated with the file
292 .I filespec
293 to standard output.
294 .TP
295 .BI ea_set " [-f infile] filespec attr_name attr_value
296 Set the value of the extended attribute
297 .I attr_name
298 in the file
299 .I filespec
300 to the string value
301 .I attr_value
302 or read it from \fIinfile\fR.
303 .TP
304 .BI ea_rm " filespec attr_names...
305 Remove the extended attribute
306 .I attr_name
307 from the file \fIfilespec\fR.
308 .TP
309 .BI expand_dir " filespec"
310 Expand the directory
311 .IR filespec .
312 .TP
313 .BI fallocate " filespec start_block [end_block]
314 Allocate and map uninitialized blocks into \fIfilespec\fR between
315 logical block \fIstart_block\fR and \fIend_block\fR, inclusive.  If
316 \fIend_block\fR is not supplied, this function maps until it runs out
317 of free disk blocks or the maximum file size is reached.  Existing
318 mappings are left alone.
319 .TP
320 .BI feature " [fs_feature] [-fs_feature] ..."
321 Set or clear various filesystem features in the superblock.  After setting
322 or clearing any filesystem features that were requested, print the current
323 state of the filesystem feature set.
324 .TP
325 .BI filefrag " [-dvr] filespec"
326 Print the number of contiguous extents in
327 .IR filespec .
328 If
329 .I filespec
330 is a directory and the
331 .I -d
332 option is not specified,
333 .I filefrag
334 will print the number of contiguous extents for each file in
335 the directory.  The
336 .I -v
337 option will cause
338 .I filefrag
339 print a tabular listing of the contiguous extents in the
340 file.  The
341 .I -r
342 option will cause
343 .I filefrag
344 to do a recursive listing of the directory.
345 .TP
346 .BI find_free_block " [count [goal]]"
347 Find the first
348 .I count
349 free blocks, starting from
350 .I goal
351 and allocate it.  Also available as
352 .BR ffb .
353 .TP
354 .BI find_free_inode " [dir [mode]]"
355 Find a free inode and allocate it.  If present,
356 .I dir
357 specifies the inode number of the directory
358 which the inode is to be located.  The second
359 optional argument
360 .I mode
361 specifies the permissions of the new inode.  (If the directory bit is set
362 on the mode, the allocation routine will function differently.)  Also
363 available as
364 .BR ffi .
365 .TP
366 .BI freeb " block [count]"
367 Mark the block number
368 .I block
369 as not allocated.
370 If the optional argument
371 .I count
372 is present, then
373 .I count
374 blocks starting at block number
375 .I block
376 will be marked as not allocated.
377 .TP
378 .BI freefrag " [-c chunk_kb]"
379 Report free space fragmentation on the currently open file system.
380 If the
381 .I \-c
382 option is specified then the filefrag command will print how many free
383 chunks of size
384 .I chunk_kb
385 can be found in the file system.  The chunk size must be a power of two
386 and be larger than the file system block size.
387 .TP
388 .BI freei " filespec [num]"
389 Free the inode specified by
390 .IR filespec .
391 If
392 .I num
393 is specified, also clear num-1 inodes after the specified inode.
394 .TP
395 .B help
396 Print a list of commands understood by
397 .BR debugfs .
398 .TP
399 .BI htree_dump " filespec"
400 Dump the hash-indexed directory
401 .IR filespec ,
402 showing its tree structure.
403 .TP
404 .BI icheck " block ..."
405 Print a listing of the inodes which use the one or more blocks specified
406 on the command line.
407 .TP
408 .BI inode_dump " filespec"
409 Print the contents of the inode data structure in hex and ASCII format.
410 .TP
411 .BI imap " filespec"
412 Print the location of the inode data structure (in the inode table)
413 of the inode
414 .IR filespec .
415 .TP
416 .BI init_filesys " device blocksize"
417 Create an ext2 file system on
418 .I device
419 with device size
420 .IR blocksize .
421 Note that this does not fully initialize all of the data structures;
422 to do this, use the
423 .BR mke2fs (8)
424 program.  This is just a call to the low-level library, which sets up
425 the superblock and block descriptors.
426 .TP
427 .BI journal_close
428 Close the open journal.
429 .TP
430 .BI journal_open " [-c] [-v ver] [-j ext_jnl]
431 Opens the journal for reading and writing.  Journal checksumming can
432 be enabled by supplying \fI-c\fR; checksum formats 2 and 3 can be
433 selected with the \fI-v\fR option.  An external journal can be loaded
434 from \fIext_jnl\fR.
435 .TP
436 .BI journal_run
437 Replay all transactions in the open journal.
438 .TP
439 .BI journal_write " [-b blocks] [-r revoke] [-c] file
440 Write a transaction to the open journal.  The list of blocks to write
441 should be supplied as a comma-separated list in \fIblocks\fR; the
442 blocks themselves should be readable from \fIfile\fR.  A list of
443 blocks to revoke can be supplied as a comma-separated list in
444 \fIrevoke\fR.  By default, a commit record is written at the end; the
445 \fI-c\fR switch writes an uncommitted transaction.
446 .TP
447 .BI kill_file " filespec"
448 Deallocate the inode
449 .I filespec
450 and its blocks.  Note that this does not remove any directory
451 entries (if any) to this inode.  See the
452 .BR rm (1)
453 command if you wish to unlink a file.
454 .TP
455 .BI lcd " directory"
456 Change the current working directory of the
457 .B debugfs
458 process to
459 .I directory
460 on the native filesystem.
461 .TP
462 .BI ln " filespec dest_file"
463 Create a link named
464 .I dest_file
465 which is a hard link to
466 .IR filespec .
467 Note this does not adjust the inode reference counts.
468 .TP
469 .BI logdump " [-acsO] [-b block] [-i filespec] [-f journal_file] [output_file]"
470 Dump the contents of the ext3 journal.  By default, dump the journal inode as
471 specified in the superblock.  However, this can be overridden with the
472 .I \-i
473 option, which dumps the journal from the internal inode given by
474 .IR filespec .
475 A regular file containing journal data can be specified using the
476 .I \-f
477 option.  Finally, the
478 .I \-s
479 option utilizes the backup information in the superblock to locate the
480 journal.
481 .IP
482 The
483 .I \-a
484 option causes the
485 .B logdump
486 program to print the contents of all of the descriptor blocks.
487 The
488 .I \-b
489 option causes
490 .B logdump
491 to print all journal records that are refer to the specified block.
492 The
493 .I \-c
494 option will print out the contents of all of the data blocks selected by
495 the
496 .I \-a
497 and
498 .I \-b
499 options.
500 .IP
501 The
502 .I \-O
503 option causes logdump to display old (checkpointed) journal entries.
504 This can be used to try to track down journal problems even after the
505 journal has been replayed.
506 .TP
507 .BI ls " [-l] [-c] [-d] [-p] [-r] filespec"
508 Print a listing of the files in the directory
509 .IR filespec .
510 The
511 .I \-c
512 flag causes directory block checksums (if present) to be displayed.
513 The
514 .I \-d
515 flag will list deleted entries in the directory.
516 The
517 .I \-l
518 flag will list files using a more verbose format.
519 The
520 .I \-p
521 flag will list the files in a format which is more easily parsable by
522 scripts, as well as making it more clear when there are spaces or other
523 non-printing characters at the end of filenames.
524 The
525 .I \-r
526 flag will force the printing of the filename, even if it is encrypted.
527 .TP
528 .BI list_deleted_inodes " [limit]"
529 List deleted inodes, optionally limited to those deleted within
530 .I limit
531 seconds ago.  Also available as
532 .BR lsdel .
533 .IP
534 This command was useful for recovering from accidental file deletions
535 for ext2 file systems.  Unfortunately, it is not useful for this purpose
536 if the files were deleted using ext3 or ext4, since the inode's
537 data blocks are no longer available after the inode is released.
538 .TP
539 .BI modify_inode " filespec"
540 Modify the contents of the inode structure in the inode
541 .IR filespec .
542 Also available as
543 .BR mi .
544 .TP
545 .BI mkdir " filespec"
546 Make a directory.
547 .TP
548 .BI mknod " filespec [p|[[c|b] major minor]]"
549 Create a special device file (a named pipe, character or block device).
550 If a character or block device is to be made, the
551 .I major
552 and
553 .I minor
554 device numbers must be specified.
555 .TP
556 .BI ncheck " [-c] inode_num ..."
557 Take the requested list of inode numbers, and print a listing of pathnames
558 to those inodes.  The
559 .I -c
560 flag will enable checking the file type information in the directory
561 entry to make sure it matches the inode's type.
562 .TP
563 .BI open " [-weficD] [-b blocksize] [-s superblock] [-z undo_file] device"
564 Open a filesystem for editing.  The
565 .I -f
566 flag forces the filesystem to be opened even if there are some unknown
567 or incompatible filesystem features which would normally
568 prevent the filesystem from being opened.  The
569 .I -e
570 flag causes the filesystem to be opened in exclusive mode.  The
571 .IR -b ", " -c ", " -i ", " -s ", " -w ", and " -D
572 options behave the same as the command-line options to
573 .BR debugfs .
574 .TP
575 .BI punch " filespec start_blk [end_blk]"
576 Delete the blocks in the inode ranging from
577 .I start_blk
578 to
579 .IR end_blk .
580 If
581 .I end_blk
582 is omitted then this command will function as a truncate command; that
583 is, all of the blocks starting at
584 .I start_blk
585 through to the end of the file will be deallocated.
586 .TP
587 .BI symlink " filespec target"
588 Make a symbolic link.
589 .TP
590 .B pwd
591 Print the current working directory.
592 .TP
593 .B quit
594 Quit
595 .B debugfs
596 .TP
597 .BI rdump " directory[...] destination"
598 Recursively dump
599 .IR directory ,
600 or multiple
601 .IR directories ,
602 and all its contents (including regular files, symbolic links, and other
603 directories) into the named
604 .IR destination ,
605 which should be an existing directory on the native filesystem.
606 .TP
607 .BI rm " pathname"
608 Unlink
609 .IR pathname .
610 If this causes the inode pointed to by
611 .I pathname
612 to have no other references, deallocate the file.  This command functions
613 as the unlink() system call.
614 .I
615 .TP
616 .BI rmdir " filespec"
617 Remove the directory
618 .IR filespec .
619 .TP
620 .BI setb " block [count]"
621 Mark the block number
622 .I block
623 as allocated.
624 If the optional argument
625 .I count
626 is present, then
627 .I count
628 blocks starting at block number
629 .I block
630 will be marked as allocated.
631 .TP
632 .BI set_block_group " bgnum field value"
633 Modify the block group descriptor specified by
634 .I bgnum
635 so that the block group descriptor field
636 .I field
637 has value
638 .IR value .
639 Also available as
640 .BR set_bg .
641 .TP
642 .BI seti " filespec [num]"
643 Mark inode
644 .I filespec
645 as in use in the inode bitmap.  If
646 .I num
647 is specified, also set num-1 inodes after the specified inode.
648 .TP
649 .BI set_inode_field " filespec field value"
650 Modify the inode specified by
651 .I filespec
652 so that the inode field
653 .I field
654 has value
655 .I value.
656 The list of valid inode fields which can be set via this command
657 can be displayed by using the command:
658 .B set_inode_field -l
659 Also available as
660 .BR sif .
661 .TP
662 .BI set_mmp_value " field value"
663 Modify the multiple-mount protection (MMP) data so that the MMP field
664 .I field
665 has value
666 .I value.
667 The list of valid MMP fields which can be set via this command
668 can be displayed by using the command:
669 .B set_mmp_value -l
670 Also available as
671 .BR smmp .
672 .TP
673 .BI set_super_value " field value"
674 Set the superblock field
675 .I field
676 to
677 .I value.
678 The list of valid superblock fields which can be set via this command
679 can be displayed by using the command:
680 .B set_super_value -l
681 Also available as
682 .BR ssv .
683 .TP
684 .BI show_super_stats " [-h]"
685 List the contents of the super block and the block group descriptors.  If the
686 .I -h
687 flag is given, only print out the superblock contents. Also available as
688 .BR stats .
689 .TP
690 .BI stat " filespec"
691 Display the contents of the inode structure of the inode
692 .IR filespec .
693 .TP
694 .BI testb " block [count]"
695 Test if the block number
696 .I block
697 is marked as allocated in the block bitmap.
698 If the optional argument
699 .I count
700 is present, then
701 .I count
702 blocks starting at block number
703 .I block
704 will be tested.
705 .TP
706 .BI testi " filespec"
707 Test if the inode
708 .I filespec
709 is marked as allocated in the inode bitmap.
710 .TP
711 .BI undel " <inode_number> [pathname]"
712 Undelete the specified inode number (which must be surrounded by angle
713 brackets) so that it and its blocks are marked in use, and optionally
714 link the recovered inode to the specified pathname.  The
715 .B e2fsck
716 command should always be run after using the
717 .B undel
718 command to recover deleted files.
719 .IP
720 Note that if you are recovering a large number of deleted files, linking
721 the inode to a directory may require the directory to be expanded, which
722 could allocate a block that had been used by one of the
723 yet-to-be-undeleted files.  So it is safer to undelete all of the
724 inodes without specifying a destination pathname, and then in a separate
725 pass, use the debugfs
726 .B link
727 command to link the inode to the destination pathname, or use
728 .B e2fsck
729 to check the filesystem and link all of the recovered inodes to the
730 lost+found directory.
731 .TP
732 .BI unlink " pathname"
733 Remove the link specified by
734 .I pathname
735 to an inode.  Note this does not adjust the inode reference counts.
736 .TP
737 .BI write " source_file out_file"
738 Copy the contents of
739 .I source_file
740 into a newly-created file in the filesystem named
741 .IR out_file .
742 .TP
743 .BI zap_block " [-f filespec] [-o offset] [-l length] [-p pattern] block_num"
744 Overwrite the block specified by
745 .I block_num
746 with zero (NUL) bytes, or if
747 .I -p
748 is given use the byte specified by
749 .IR pattern .
750 If
751 .I -f
752 is given then
753 .I block_num
754 is relative to the start of the file given by
755 .IR filespec .
756 The
757 .I -o
758 and
759 .I -l
760 options limit the range of bytes to zap to the specified
761 .I offset
762 and
763 .I length
764 relative to the start of the block.
765 .TP
766 .BI zap_block " [-f filespec] [-b bit] block_num"
767 Bit-flip portions of the physical
768 .IR block_num .
769 If
770 .I -f
771 is given, then
772 .I block_num
773 is a logical block relative to the start of
774 .IR filespec .
775 .SH ENVIRONMENT VARIABLES
776 .TP
777 .B DEBUGFS_PAGER, PAGER
778 The
779 .B debugfs
780 program always pipes the output of the some commands through a
781 pager program.  These commands include:
782 .IR show_super_stats " (" stats ),
783 .IR list_directory " (" ls ),
784 .IR show_inode_info " (" stat ),
785 .IR list_deleted_inodes " (" lsdel ),
786 and
787 .IR htree_dump .
788 The specific pager can explicitly specified by the
789 .B DEBUGFS_PAGER
790 environment variable, and if it is not set, by the
791 .B PAGER
792 environment variable.
793 .IP
794 Note that since a pager is always used, the
795 .BR less (1)
796 pager is not particularly appropriate, since it clears the screen before
797 displaying the output of the command and clears the output the screen
798 when the pager is exited.  Many users prefer to use the
799 .BR less (1)
800 pager for most purposes, which is why the
801 .B DEBUGFS_PAGER
802 environment variable is available to override the more general
803 .B PAGER
804 environment variable.
805 .SH AUTHOR
806 .B debugfs
807 was written by Theodore Ts'o <tytso@mit.edu>.
808 .SH SEE ALSO
809 .BR dumpe2fs (8),
810 .BR tune2fs (8),
811 .BR e2fsck (8),
812 .BR mke2fs (8),
813 .BR ext4 (5)