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