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