Whamcloud - gitweb
Merge branch 'maint' into next
[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 " filespec logical_block"
171 Print the physical block number corresponding to the logical block number
172 .I logical_block
173 in the inode
174 .IR filespec .
175 .TP
176 .BI block_dump " [-f filespec] block_num"
177 Dump the filesystem block given by
178 .I block_num
179 in hex and ASCII format to the console.  If the
180 .I -f
181 option is specified, the block number is relative to the start of the given
182 .BR filespec .
183 .TP
184 .BI cat " filespec"
185 Dump the contents of the inode
186 .I filespec
187 to stdout.
188 .TP
189 .BI cd " filespec"
190 Change the current working directory to
191 .IR filespec .
192 .TP
193 .BI chroot " filespec"
194 Change the root directory to be the directory
195 .IR filespec .
196 .TP
197 .BI close " [-a]"
198 Close the currently open file system.  If the
199 .I -a
200 option is specified, write out any changes to the superblock and block
201 group descriptors to all of the backup superblocks, not just to the
202 master superblock.
203 .TP
204 .BI clri " filespec"
205 Clear the contents of the inode
206 .IR filespec .
207 .TP
208 .BI dirsearch " filespec filename"
209 Search the directory
210 .I filespec
211 for
212 .IR filename .
213 .TP
214 .B dirty
215 Mark the filesystem as dirty, so that the superblocks will be written on exit.
216 .TP
217 .BI dump " [-p] filespec out_file"
218 Dump the contents of the inode
219 .I filespec
220 to the output file
221 .IR out_file .
222 If the
223 .I -p
224 option is given set the owner, group and permissions information on
225 .I out_file
226 to match
227 .IR filespec .
228 .TP
229 .B dump_mmp
230 Display the multiple-mount protection (mmp) field values.
231 .TP
232 .BI dx_hash " [-h hash_alg] [-s hash_seed] filename"
233 Calculate the directory hash of
234 .IR filename .
235 The hash algorithm specified with
236 .I -h
237 may be
238 .BR legacy , " half_md4" ", or " tea .
239 The hash seed specified with
240 .I -s
241 must be in UUID format.
242 .TP
243 .BI dump_extents " [-n] [-l] filespec"
244 Dump the the extent tree of the inode
245 .IR filespec .
246 The
247 .I -n
248 flag will cause
249 .B dump_extents
250 to only display the interior nodes in the extent tree.   The
251 .I -l
252 flag will cause
253 .B dump_extents
254 to only display the leaf nodes in the extent tree.
255 .IP
256 (Please note that the length and range of blocks for the last extent in
257 an interior node is an estimate by the extents library functions, and is
258 not stored in filesystem data structures.   Hence, the values displayed
259 may not necessarily by accurate and does not indicate a problem or
260 corruption in the file system.)
261 .TP
262 .BI expand_dir " filespec"
263 Expand the directory
264 .IR filespec .
265 .TP
266 .BI feature " [fs_feature] [-fs_feature] ..."
267 Set or clear various filesystem features in the superblock.  After setting
268 or clearing any filesystem features that were requested, print the current
269 state of the filesystem feature set.
270 .TP
271 .BI filefrag " [-dvr] filespec"
272 Print the number of contiguous extents in
273 .IR filespec .
274 If
275 .I filespec
276 is a directory and the
277 .I -d
278 option is not specified,
279 .I filefrag
280 will print the number of contiguous extents for each file in
281 the directory.  The
282 .I -v
283 option will cause
284 .I filefrag
285 print a tabular listing of the contiguous extents in the
286 file.  The
287 .I -r
288 option will cause
289 .I filefrag
290 to do a recursive listing of the directory.
291 .TP
292 .BI find_free_block " [count [goal]]"
293 Find the first
294 .I count
295 free blocks, starting from
296 .I goal
297 and allocate it.  Also available as
298 .BR ffb .
299 .TP
300 .BI find_free_inode " [dir [mode]]"
301 Find a free inode and allocate it.  If present,
302 .I dir
303 specifies the inode number of the directory
304 which the inode is to be located.  The second
305 optional argument
306 .I mode
307 specifies the permissions of the new inode.  (If the directory bit is set
308 on the mode, the allocation routine will function differently.)  Also
309 available as
310 .BR ffi .
311 .TP
312 .BI freeb " block [count]"
313 Mark the block number
314 .I block
315 as not allocated.
316 If the optional argument
317 .I count
318 is present, then
319 .I count
320 blocks starting at block number
321 .I block
322 will be marked as not allocated.
323 .TP
324 .BI freefrag " [-c chunk_kb]"
325 Report free space fragmentation on the currently open file system.
326 If the
327 .I \-c
328 option is specified then the filefrag command will print how many free
329 chunks of size
330 .I chunk_kb
331 can be found in the file system.  The chunk size must be a power of two
332 and be larger than the file system block size.
333 .TP
334 .BI freei " filespec [num]"
335 Free the inode specified by
336 .IR filespec .
337 If
338 .I num
339 is specified, also clear num-1 inodes after the specified inode.
340 .TP
341 .B help
342 Print a list of commands understood by
343 .BR debugfs .
344 .TP
345 .BI htree_dump " filespec"
346 Dump the hash-indexed directory
347 .IR filespec ,
348 showing its tree structure.
349 .TP
350 .BI icheck " block ..."
351 Print a listing of the inodes which use the one or more blocks specified
352 on the command line.
353 .TP
354 .BI inode_dump " filespec"
355 Print the contents of the inode data structure in hex and ASCII format.
356 .TP
357 .BI imap " filespec"
358 Print the location of the inode data structure (in the inode table)
359 of the inode
360 .IR filespec .
361 .TP
362 .BI init_filesys " device blocksize"
363 Create an ext2 file system on
364 .I device
365 with device size
366 .IR blocksize .
367 Note that this does not fully initialize all of the data structures;
368 to do this, use the
369 .BR mke2fs (8)
370 program.  This is just a call to the low-level library, which sets up
371 the superblock and block descriptors.
372 .TP
373 .BI kill_file " filespec"
374 Deallocate the inode
375 .I filespec
376 and its blocks.  Note that this does not remove any directory
377 entries (if any) to this inode.  See the
378 .BR rm (1)
379 command if you wish to unlink a file.
380 .TP
381 .BI lcd " directory"
382 Change the current working directory of the
383 .B debugfs
384 process to
385 .I directory
386 on the native filesystem.
387 .TP
388 .BI ln " filespec dest_file"
389 Create a link named
390 .I dest_file
391 which is a hard link to
392 .IR filespec .
393 Note this does not adjust the inode reference counts.
394 .TP
395 .BI logdump " [-acsO] [-b block] [-i filespec] [-f journal_file] [output_file]"
396 Dump the contents of the ext3 journal.  By default, dump the journal inode as
397 specified in the superblock.  However, this can be overridden with the
398 .I \-i
399 option, which dumps the journal from the internal inode given by
400 .IR filespec .
401 A regular file containing journal data can be specified using the
402 .I \-f
403 option.  Finally, the
404 .I \-s
405 option utilizes the backup information in the superblock to locate the
406 journal.
407 .IP
408 The
409 .I \-a
410 option causes the
411 .B logdump
412 program to print the contents of all of the descriptor blocks.
413 The
414 .I \-b
415 option causes
416 .B logdump
417 to print all journal records that are refer to the specified block.
418 The
419 .I \-c
420 option will print out the contents of all of the data blocks selected by
421 the
422 .I \-a
423 and
424 .I \-b
425 options.
426 .IP
427 The
428 .I \-O
429 option causes logdump to display old (checkpointed) journal entries.
430 This can be used to try to track down journal problems even after the
431 journal has been replayed.
432 .TP
433 .BI ls " [-l] [-c] [-d] [-p] filespec"
434 Print a listing of the files in the directory
435 .IR filespec .
436 The
437 .I \-c
438 flag causes directory block checksums (if present) to be displayed.
439 The
440 .I \-d
441 flag will list deleted entries in the directory.
442 The
443 .I \-l
444 flag will list files using a more verbose format.
445 The
446 .I \-p
447 flag will list the files in a format which is more easily parsable by
448 scripts, as well as making it more clear when there are spaces or other
449 non-printing characters at the end of filenames.
450 .TP
451 .BI list_deleted_inodes " [limit]"
452 List deleted inodes, optionally limited to those deleted within
453 .I limit
454 seconds ago.  Also available as
455 .BR lsdel .
456 .IP
457 This command was useful for recovering from accidental file deletions
458 for ext2 file systems.  Unfortunately, it is not useful for this purpose
459 if the files were deleted using ext3 or ext4, since the inode's
460 data blocks are no longer available after the inode is released.
461 .TP
462 .BI modify_inode " filespec"
463 Modify the contents of the inode structure in the inode
464 .IR filespec .
465 Also available as
466 .BR mi .
467 .TP
468 .BI mkdir " filespec"
469 Make a directory.
470 .TP
471 .BI mknod " filespec [p|[[c|b] major minor]]"
472 Create a special device file (a named pipe, character or block device).
473 If a character or block device is to be made, the
474 .I major
475 and
476 .I minor
477 device numbers must be specified.
478 .TP
479 .BI ncheck " [-c] inode_num ..."
480 Take the requested list of inode numbers, and print a listing of pathnames
481 to those inodes.  The
482 .I -c
483 flag will enable checking the file type information in the directory
484 entry to make sure it matches the inode's type.
485 .TP
486 .BI open " [-weficD] [-b blocksize] [-s superblock] device"
487 Open a filesystem for editing.  The
488 .I -f
489 flag forces the filesystem to be opened even if there are some unknown
490 or incompatible filesystem features which would normally
491 prevent the filesystem from being opened.  The
492 .I -e
493 flag causes the filesystem to be opened in exclusive mode.  The
494 .IR -b ", " -c ", " -i ", " -s ", " -w ", and " -D
495 options behave the same as the command-line options to
496 .BR debugfs .
497 .TP
498 .BI punch " filespec start_blk [end_blk]"
499 Delete the blocks in the inode ranging from
500 .I start_blk
501 to
502 .IR end_blk .
503 If
504 .I end_blk
505 is omitted then this command will function as a truncate command; that
506 is, all of the blocks starting at
507 .I start_blk
508 through to the end of the file will be deallocated.
509 .TP
510 .BI symlink " filespec target"
511 Make a symbolic link.
512 .TP
513 .B pwd
514 Print the current working directory.
515 .TP
516 .B quit
517 Quit
518 .B debugfs
519 .TP
520 .BI rdump " directory destination"
521 Recursively dump
522 .I directory
523 and all its contents (including regular files, symbolic links, and other
524 directories) into the named
525 .I destination
526 which should be an existing directory on the native filesystem.
527 .TP
528 .BI rm " pathname"
529 Unlink
530 .IR pathname .
531 If this causes the inode pointed to by
532 .I pathname
533 to have no other references, deallocate the file.  This command functions
534 as the unlink() system call.
535 .I
536 .TP
537 .BI rmdir " filespec"
538 Remove the directory
539 .IR filespec .
540 .TP
541 .BI setb " block [count]"
542 Mark the block number
543 .I block
544 as allocated.
545 If the optional argument
546 .I count
547 is present, then
548 .I count
549 blocks starting at block number
550 .I block
551 will be marked as allocated.
552 .TP
553 .BI set_block_group " bgnum field value"
554 Modify the block group descriptor specified by
555 .I bgnum
556 so that the block group descriptor field
557 .I field
558 has value
559 .IR value .
560 Also available as
561 .BR set_bg .
562 .TP
563 .BI seti " filespec [num]"
564 Mark inode
565 .I filespec
566 as in use in the inode bitmap.  If
567 .I num
568 is specified, also set num-1 inodes after the specified inode.
569 .TP
570 .BI set_inode_field " filespec field value"
571 Modify the inode specified by
572 .I filespec
573 so that the inode field
574 .I field
575 has value
576 .I value.
577 The list of valid inode fields which can be set via this command
578 can be displayed by using the command:
579 .B set_inode_field -l
580 Also available as
581 .BR sif .
582 .TP
583 .BI set_mmp_value " field value"
584 Modify the multiple-mount protection (MMP) data so that the MMP field
585 .I field
586 has value
587 .I value.
588 The list of valid MMP fields which can be set via this command
589 can be displayed by using the command:
590 .B set_mmp_value -l
591 Also available as
592 .BR smmp .
593 .TP
594 .BI set_super_value " field value"
595 Set the superblock field
596 .I field
597 to
598 .I value.
599 The list of valid superblock fields which can be set via this command
600 can be displayed by using the command:
601 .B set_super_value -l
602 Also available as
603 .BR ssv .
604 .TP
605 .BI show_super_stats " [-h]"
606 List the contents of the super block and the block group descriptors.  If the
607 .I -h
608 flag is given, only print out the superblock contents. Also available as
609 .BR stats .
610 .TP
611 .BI stat " filespec"
612 Display the contents of the inode structure of the inode
613 .IR filespec .
614 .TP
615 .BI testb " block [count]"
616 Test if the block number
617 .I block
618 is marked as allocated in the block bitmap.
619 If the optional argument
620 .I count
621 is present, then
622 .I count
623 blocks starting at block number
624 .I block
625 will be tested.
626 .TP
627 .BI testi " filespec"
628 Test if the inode
629 .I filespec
630 is marked as allocated in the inode bitmap.
631 .TP
632 .BI undel " <inode_number> [pathname]"
633 Undelete the specified inode number (which must be surrounded by angle
634 brackets) so that it and its blocks are marked in use, and optionally
635 link the recovered inode to the specified pathname.  The
636 .B e2fsck
637 command should always be run after using the
638 .B undel
639 command to recover deleted files.
640 .IP
641 Note that if you are recovering a large number of deleted files, linking
642 the inode to a directory may require the directory to be expanded, which
643 could allocate a block that had been used by one of the
644 yet-to-be-undeleted files.  So it is safer to undelete all of the
645 inodes without specifying a destination pathname, and then in a separate
646 pass, use the debugfs
647 .B link
648 command to link the inode to the destination pathname, or use
649 .B e2fsck
650 to check the filesystem and link all of the recovered inodes to the
651 lost+found directory.
652 .TP
653 .BI unlink " pathname"
654 Remove the link specified by
655 .I pathname
656 to an inode.  Note this does not adjust the inode reference counts.
657 .TP
658 .BI write " source_file out_file"
659 Copy the contents of
660 .I source_file
661 into a newly-created file in the filesystem named
662 .IR out_file .
663 .TP
664 .BI zap_block " [-f filespec] [-o offset] [-l length] [-p pattern] block_num"
665 .TP
666 Overwrite the block specified by
667 .I block_num
668 with zero (NUL) bytes, or if
669 .I -p
670 is given use the byte specified by
671 .IR pattern .
672 If
673 .I -f
674 is given then
675 .I block_num
676 is relative to the start of the file given by
677 .IR filespec .
678 The
679 .I -o
680 and
681 .I -l
682 options limit the range of bytes to zap to the specified
683 .I offset
684 and
685 .I length
686 relative to the start of the block.
687 .TP
688 .BI zap_block " [-f filespec] [-b bit] block_num"
689 Bit-flip portions of the physical
690 .IR block_num .
691 If
692 .I -f
693 is given, then
694 .I block_num
695 is a logical block relative to the start of
696 .IR filespec .
697 .SH ENVIRONMENT VARIABLES
698 .TP
699 .B DEBUGFS_PAGER, PAGER
700 The
701 .B debugfs
702 program always pipes the output of the some commands through a
703 pager program.  These commands include:
704 .IR show_super_stats " (" stats ),
705 .IR list_directory " (" ls ),
706 .IR show_inode_info " (" stat ),
707 .IR list_deleted_inodes " (" lsdel ),
708 and
709 .IR htree_dump .
710 The specific pager can explicitly specified by the
711 .B DEBUGFS_PAGER
712 environment variable, and if it is not set, by the
713 .B PAGER
714 environment variable.
715 .IP
716 Note that since a pager is always used, the
717 .BR less (1)
718 pager is not particularly appropriate, since it clears the screen before
719 displaying the output of the command and clears the output the screen
720 when the pager is exited.  Many users prefer to use the
721 .BR less (1)
722 pager for most purposes, which is why the
723 .B DEBUGFS_PAGER
724 environment variable is available to override the more general
725 .B PAGER
726 environment variable.
727 .SH AUTHOR
728 .B debugfs
729 was written by Theodore Ts'o <tytso@mit.edu>.
730 .SH SEE ALSO
731 .BR dumpe2fs (8),
732 .BR tune2fs (8),
733 .BR e2fsck (8),
734 .BR mke2fs (8),
735 .BR ext4 (5)