Whamcloud - gitweb
debugfs: add a new debugfs command 'blocks'
[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 \-DVwci
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 \-c
52 Specifies that the file system should be opened in catastrophic mode, in
53 which the inode and group bitmaps are not read initially.  This can be
54 useful for filesystems with significant corruption, but because of this,
55 catastrophic mode forces the filesystem to be opened read-only.
56 .TP
57 .I \-i
58 Specifies that 
59 .I device
60 represents an ext2 image file created by the
61 .B e2image
62 program.  Since the ext2 image file only contains the superblock, block
63 group descriptor, block and inode allocation bitmaps, and 
64 the inode table, many
65 .B debugfs
66 commands will not function properly.  
67 .B Warning:
68 no safety checks are in place, and 
69 .B debugfs 
70 may fail in interesting ways if commands such as
71 .IR ls ", " dump ", " 
72 etc. are tried without specifying the 
73 .I data_source_device
74 using the 
75 .I \-d
76 option.
77 .B debugfs 
78 is a debugging tool.  It has rough edges!
79 .TP
80 .I -d data_source_device
81 Used with the 
82 .I \-i
83 option, specifies that
84 .I data_source_device
85 should be used when reading blocks not found in the ext2 image file.
86 This includes data, directory, and indirect blocks.
87 .TP
88 .I -b blocksize
89 Forces the use of the given block size for the file system, rather than
90 detecting the correct block size as normal.
91 .TP
92 .I -s superblock
93 Causes the file system superblock to be read from the given block
94 number, instead of using the primary superblock (located at an offset of
95 1024 bytes from the beginning of the filesystem).  If you specify the
96 .I -s
97 option, you must also provide the blocksize of the filesystem via the
98 .I -b
99 option.
100 .TP
101 .I -f cmd_file
102 Causes 
103 .B debugfs
104 to read in commands from 
105 .IR cmd_file , 
106 and execute them.  When 
107 .B debugfs
108 is finished executing those commands, it will exit.
109 .TP
110 .I -D
111 Causes
112 .B debugfs
113 to open the device using Direct I/O, bypassing the buffer cache.  Note
114 that some Linux devices, notably device mapper as of this writing, do
115 not support Direct I/O.
116 .TP
117 .I -R request
118 Causes 
119 .B debugfs
120 to execute the single command 
121 .IR request ,
122 and then exit.
123 .TP
124 .I -V
125 print the version number of 
126 .B debugfs
127 and exit.
128 .SH SPECIFYING FILES
129 Many
130 .B debugfs
131 commands take a
132 .I filespec
133 as an argument to specify an inode (as opposed to a pathname) 
134 in the filesystem which is currently opened by 
135 .BR debugfs . 
136 The
137 .I filespec
138 argument may be specified in two forms.  The first form is an inode 
139 number surrounded by angle brackets, e.g., 
140 .IR <2> .
141 The 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 
143 which is currently opened by 
144 .BR debugfs .
145 If not, the pathname is 
146 interpreted relative to the current working directory as maintained by 
147 .BR debugfs .  
148 This may be modified by using the 
149 .B debugfs
150 command
151 .IR cd .
152 .\" 
153 .\"
154 .\"
155 .SH COMMANDS
156 This is a list of the commands which 
157 .B debugfs
158 supports.
159 .TP
160 .I blocks filespace
161 Print the blocks used by the inode
162 .I filespec
163 to stdout.
164 .TP
165 .I bmap filespec logical_block
166 Print the physical block number corresponding to the logical block number
167 .I logical_block
168 in the inode
169 .IR filespec .
170 .TP
171 .I cat filespec
172 Dump the contents of the inode 
173 .I filespec
174 to stdout.
175 .TP
176 .I cd filespec
177 Change the current working directory to 
178 .IR filespec .
179 .TP
180 .I chroot filespec
181 Change the root directory to be the directory 
182 .IR filespec .
183 .TP
184 .I close [-a]
185 Close the currently open file system.  If the 
186 .I -a
187 option is specified, write out any changes to the superblock and block
188 group descriptors to all of the backup superblocks, not just to the
189 master superblock.
190 .TP
191 .I clri file
192 Clear the contents of the inode 
193 .IR file .
194 .TP
195 .I dirsearch filespec filename
196 Search the directory
197 .I filespec
198 for
199 .IR filename .
200 .TP
201 .I dump [-p] filespec out_file
202 Dump the contents of the inode 
203 .I filespec
204 to the output file 
205 .IR out_file .  
206 If the 
207 .I -p 
208 option is given set the owner, group and permissions information on 
209 .I out_file 
210 to match 
211 .IR filespec .
212 .TP
213 .I dx_hash [-h hash_alg] [-s hash_seed] filename
214 Calculate the directory hash of
215 .IR filename .
216 The hash algorithm specified with
217 .I -h
218 may be "legacy" "half_md4" or "tea".
219 The hash seed specified with
220 .I -s
221 must be in UUID format.
222 .TP
223 .I dump_extents [-n] [-l] filespec
224 Dump the the extent tree of the inode
225 .IR filespec .
226 The 
227 .I -n
228 flag will cause
229 .I dump_extents
230 to only display the interior nodes in the extent tree.   The
231 .I  -l
232 flag cause
233 .I dump_extents
234 to only display the leaf nodes in the extent tree.
235 .IP
236 (Please note that the length and range of blocks for the last extent in
237 an interior node is an estimate by the extents library functions, and is
238 not stored in filesystem data structures.   Hence, the values displayed
239 may not necessarily by accurate and does not indicate a problem or 
240 corruption in the file system.)
241 .TP
242 .I expand_dir filespec
243 Expand the directory
244 .IR filespec .
245 .TP
246 .I feature [fs_feature] [-fs_feature] ...
247 Set or clear various filesystem features in the superblock.  After setting
248 or clearing any filesystem features that were requested, print the current
249 state of the filesystem feature set.
250 .TP
251 .I find_free_block [count [goal]]
252 Find the first 
253 .I count
254 free blocks, starting from
255 .I goal
256 and allocate it.
257 .TP
258 .I find_free_inode [dir [mode]]
259 Find a free inode and allocate it.  If present, 
260 .I dir
261 specifies the inode number of the directory 
262 which the inode is to be located.  The second 
263 optional argument
264 .I mode
265 specifies the permissions of the new inode.  (If the directory bit is set
266 on the mode, the allocation routine will function differently.)
267 .TP
268 .I freeb block [count]
269 Mark the block number
270 .I block
271 as not allocated.
272 If the optional argument 
273 .I count 
274 is present, then 
275 .I count
276 blocks starting at block number
277 .I block
278 will be marked as not allocated.
279 .TP
280 .I freei filespec
281 Free the inode specified by 
282 .IR filespec .
283 .TP
284 .I help
285 Print a list of commands understood by 
286 .BR debugfs .
287 .TP
288 .I htree_dump filespec
289 Dump the hash-indexed directory
290 .IR filespec ,
291 showing its tree structure.
292 .TP
293 .I icheck block ...
294 Print a listing of the inodes which use the one or more blocks specified
295 on the command line.
296 .TP
297 .I imap filespec
298 Print the location of the inode data structure (in the inode table) 
299 of the inode
300 .IR filespec .
301 .TP
302 .I init_filesys device blocksize
303 Create an ext2 file system on
304 .I device
305 with device size
306 .IR blocksize .
307 Note that this does not fully initialize all of the data structures; 
308 to do this, use the 
309 .BR mke2fs (8)
310 program.  This is just a call to the low-level library, which sets up
311 the superblock and block descriptors.
312 .TP
313 .I kill_file filespec
314 Deallocate the inode 
315 .I filespec
316 and its blocks.  Note that this does not remove any directory
317 entries (if any) to this inode.  See the 
318 .BR rm (1)
319 command if you wish to unlink a file.
320 .TP
321 .I lcd directory
322 Change the current working directory of the
323 .B debugfs
324 process to
325 .I directory
326 on the native filesystem.
327 .TP
328 .I ln filespec dest_file
329 Create a link named 
330 .I dest_file
331 which is a link to 
332 .IR filespec .
333 Note this does not adjust the inode reference counts.
334 .TP
335 .I logdump [-acs] [-b<block>] [-i<filespec>] [-f<journal_file>] [output_file]
336 Dump the contents of the ext3 journal.  By default, the journal inode as
337 specified in the superblock.  However, this can be overridden with the 
338 .I \-i
339 option, which uses an inode specifier to specify the journal to be
340 used.  A file containing journal data can be specified using the
341 .I \-f
342 option.   Finally, the 
343 .I \-s
344 option utilizes the backup information in the superblock to locate the
345 journal.
346 .IP
347 The 
348 .I \-a
349 option causes the 
350 .I logdump
351 program to print the contents of all of the descriptor blocks.
352 The 
353 .I \-b
354 option causes 
355 .I logdump
356 to print all journal records that are refer to the specified block. 
357 The 
358 .I \-c
359 option will print out the contents of all of the data blocks selected by
360 the 
361 .I \-a
362 and 
363 .I \-b
364 options.
365 .TP
366 .I ls [-l] [-d] [-p] filespec
367 Print a listing of the files in the directory
368 .IR filespec .
369 The 
370 .I \-l
371 flag will list files using a more verbose format.
372 The
373 .I \-d
374 flag will list deleted entries in the directory.
375 The 
376 .I \-p
377 flag will list the files in a format which is more easily parsable by
378 scripts, as well as making it more clear when there are spaces or other
379 non-printing characters at the end of filenames.
380 .TP
381 .I modify_inode filespec
382 Modify the contents of the inode structure in the inode
383 .IR filespec .
384 .TP
385 .I mkdir filespec
386 Make a directory.
387 .TP
388 .I mknod filespec [p|[[c|b] major minor]]
389 Create a special device file (a named pipe, character or block device).
390 If a character or block device is to be made, the 
391 .I major
392 and
393 .I minor
394 device numbers must be specified.
395 .TP
396 .I ncheck inode_num ...
397 Take the requested list of inode numbers, and print a listing of pathnames
398 to those inodes.
399 .TP
400 .I open [-w] [-e] [-f] [-i] [-c] [-D] [-b blocksize] [-s superblock] device
401 Open a filesystem for editing.  The 
402 .I -f 
403 flag forces the filesystem to be opened even if there are some unknown 
404 or incompatible filesystem features which would normally 
405 prevent the filesystem from being opened.  The
406 .I -e
407 flag causes the filesystem to be opened in exclusive mode.  The
408 .IR -b ", " -c ", " -i ", " -s ", " -w ", and " -D
409 options behave the same as the command-line options to 
410 .BR debugfs .
411 .TP
412 .I punch filespec start_blk [end_blk]
413 Delete the blocks in the inode ranging from
414 .I start_blk
415 to
416 .IR end_blk .
417 If
418 .I end_blk
419 is omitted then this command will function as a truncate command; that
420 is, all of the blocks starting at
421 .I start_blk
422 through to the end of the file will be deallocated.
423 .TP
424 .I pwd
425 Print the current working directory.
426 .TP
427 .I quit
428 Quit
429 .B debugfs
430 .TP
431 .I rdump directory destination
432 Recursively dump
433 .I directory
434 and all its contents (including regular files, symbolic links, and other
435 directories) into the named
436 .I destination
437 which should be an existing directory on the native filesystem.
438 .TP
439 .I rm pathname
440 Unlink 
441 .IR pathname .
442 If this causes the inode pointed to by 
443 .I pathname
444 to have no other references, deallocate the file.  This command functions
445 as the unlink() system call.
446 .I 
447 .TP
448 .I rmdir filespec
449 Remove the directory
450 .IR filespec .
451 .TP
452 .I setb block [count]
453 Mark the block number
454 .I block
455 as allocated.
456 If the optional argument 
457 .I count 
458 is present, then 
459 .I count
460 blocks starting at block number
461 .I block
462 will be marked as allocated.
463 .TP
464 .I set_block_group bgnum field value
465 Modify the block group descriptor specified by
466 .I bgnum
467 so that the block group descriptor field
468 .I field
469 has value
470 .I value.
471 .TP
472 .I seti filespec
473 Mark inode 
474 .I filespec
475 as in use in the inode bitmap.
476 .TP
477 .I set_inode_field filespec field value
478 Modify the inode specified by 
479 .I filespec
480 so that the inode field
481 .I field
482 has value 
483 .I value.
484 The list of valid inode fields which can be set via this command 
485 can be displayed by using the command:
486 .B set_inode_field -l
487 .TP
488 .I set_super_value field value
489 Set the superblock field
490 .I field
491 to 
492 .I value.
493 The list of valid superblock fields which can be set via this command 
494 can be displayed by using the command:
495 .B set_super_value -l
496 .TP
497 .I show_super_stats [-h]
498 List the contents of the super block and the block group descriptors.  If the
499 .I -h
500 flag is given, only print out the superblock contents.
501 .TP
502 .I stat filespec
503 Display the contents of the inode structure of the inode
504 .IR filespec .
505 .TP
506 .I testb block [count]
507 Test if the block number
508 .I block
509 is marked as allocated in the block bitmap.
510 If the optional argument 
511 .I count 
512 is present, then 
513 .I count
514 blocks starting at block number
515 .I block
516 will be tested.
517 .TP
518 .I testi filespec
519 Test if the inode 
520 .I filespec
521 is marked as allocated in the inode bitmap.
522 .TP
523 .I undel <inode num> [pathname]
524 Undelete the specified inode number (which must be surrounded by angle
525 brackets) so that it and its blocks are marked in use, and optionally
526 link the recovered inode to the specified pathname.  The 
527 .B e2fsck
528 command should always be run after using the 
529 .B undel
530 command to recover deleted files.
531 .IP
532 Note that if you are recovering a large number of deleted files, linking
533 the inode to a directory may require the directory to be expanded, which
534 could allocate a block that had been used by one of the
535 yet-to-be-undeleted files.  So it is safer to undelete all of the 
536 inodes without specifying a destination pathname, and then in a separate
537 pass, use the debugfs
538 .B link
539 command to link the inode to the destination pathname, or use 
540 .B e2fsck
541 to check the filesystem and link all of the recovered inodes to the
542 lost+found directory.
543 .TP
544 .I unlink pathname
545 Remove the link specified by 
546 .I pathname 
547 to an inode.  Note this does not adjust the inode reference counts.
548 .TP
549 .I write source_file out_file
550 Create a file in the filesystem named
551 .IR out_file ,
552 and copy the contents of
553 .I source_file
554 into the destination file.
555 .SH ENVIRONMENT VARIABLES
556 .TP
557 .B DEBUGFS_PAGER, PAGER
558 The
559 .B debugfs
560 program always pipes the output of the some commands through a
561 pager program.  These commands include: 
562 .IR show_super_stats ,
563 .IR list_directory ,
564 .IR show_inode_info ,
565 .IR list_deleted_inodes ,
566 and
567 .IR htree_dump .
568 The specific pager can explicitly specified by the
569 .B DEBUGFS_PAGER
570 environment variable, and if it is not set, by the
571 .B PAGER
572 environment variable.  
573 .IP
574 Note that since a pager is always used, the 
575 .BR less (1)
576 pager is not particularly appropriate, since it clears the screen before
577 displaying the output of the command and clears the output the screen
578 when the pager is exited.  Many users prefer to use the 
579 .BR less (1)
580 pager for most purposes, which is why the 
581 .B DEBUGFS_PAGER 
582 environment variable is available to override the more general
583 .B PAGER
584 environment variable.
585 .SH AUTHOR
586 .B debugfs
587 was written by Theodore Ts'o <tytso@mit.edu>.
588 .SH SEE ALSO
589 .BR dumpe2fs (8),
590 .BR tune2fs (8),
591 .BR e2fsck (8),
592 .BR mke2fs (8)