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