{
    "mode": "man",
    "parameter": "debugfs",
    "section": "8",
    "url": "https://www.chedong.com/phpMan.php/man/debugfs/8/json",
    "generated": "2026-06-10T16:03:48Z",
    "synopsis": "debugfs  [  -DVwcin  ] [ -b blocksize ] [ -s superblock ] [ -f cmdfile ] [ -R request ] [ -d\ndatasourcedevice ] [ -z undofile ] [ device ]",
    "sections": {
        "NAME": {
            "content": "debugfs - ext2/ext3/ext4 file system debugger\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "debugfs  [  -DVwcin  ] [ -b blocksize ] [ -s superblock ] [ -f cmdfile ] [ -R request ] [ -d\ndatasourcedevice ] [ -z undofile ] [ device ]\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "The debugfs program is an interactive file system debugger. It can be  used  to  examine  and\nchange the state of an ext2, ext3, or ext4 file system.\n\ndevice is a block device (e.g., /dev/sdXX) or a file containing the file system.\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "-w     Specifies  that the file system should be opened in read-write mode.  Without this op‐\ntion, the file system is opened in read-only mode.\n\n-n     Disables metadata checksum verification.  This should only be used if you believe  the\nmetadata to be correct despite the complaints of e2fsprogs.\n\n-c     Specifies that the file system should be opened in catastrophic mode, in which the in‐\node and group bitmaps are not read initially.  This can be  useful  for  file  systems\nwith  significant  corruption,  but because of this, catastrophic mode forces the file\nsystem to be opened read-only.\n\n-i     Specifies that device represents an ext2 image file created by  the  e2image  program.\nSince  the ext2 image file only contains the superblock, block group descriptor, block\nand inode allocation bitmaps, and the inode table,  many  debugfs  commands  will  not\nfunction  properly.   Warning:  no safety checks are in place, and debugfs may fail in\ninteresting ways if commands such as ls, dump, etc. are tried without  specifying  the\ndatasourcedevice  using  the  -d option.  debugfs is a debugging tool.  It has rough\nedges!\n\n-d datasourcedevice\nUsed with the -i option, specifies that datasourcedevice should be used when reading\nblocks  not found in the ext2 image file.  This includes data, directory, and indirect\nblocks.\n\n-b blocksize\nForces the use of the given block size (in bytes) for the file system, rather than de‐\ntecting  the  correct  block size automatically.  (This option is rarely needed; it is\nused primarily when the file system is extremely badly damaged/corrupted.)\n\n-s superblock\nCauses the file system superblock to be read from the given block number,  instead  of\nusing the primary superblock (located at an offset of 1024 bytes from the beginning of\nthe file system).  If you specify the -s option, you must also provide  the  blocksize\nof the file system via the -b option.   (This option is rarely needed; it is used pri‐\nmarily when the file system is extremely badly damaged/corrupted.)\n\n-f cmdfile\nCauses debugfs to read in commands from cmdfile, and execute them.  When  debugfs  is\nfinished executing those commands, it will exit.\n\n-D     Causes  debugfs to open the device using Direct I/O, bypassing the buffer cache.  Note\nthat some Linux devices, notably device mapper as of this writing, do not support  Di‐\nrect I/O.\n\n-R request\nCauses debugfs to execute the single command request, and then exit.\n\n-V     print the version number of debugfs and exit.\n",
            "subsections": [
                {
                    "name": "-z",
                    "content": "Before overwriting a file system block, write the old contents of the block to an undo\nfile.  This undo file can be used with e2undo(8) to restore the old  contents  of  the\nfile system should something go wrong.  If the empty string is passed as the undofile\nargument, the undo file will be written to a file named debugfs-device.e2undo  in  the\ndirectory specified via the E2FSPROGSUNDODIR environment variable.\n\nWARNING: The undo file cannot be used to recover from a power or system crash.\n",
                    "flag": "-z"
                }
            ]
        },
        "SPECIFYING FILES": {
            "content": "Many  debugfs  commands  take  a filespec as an argument to specify an inode (as opposed to a\npathname) in the file system which is currently opened by debugfs.  The filespec argument may\nbe  specified  in two forms.  The first form is an inode number surrounded by angle brackets,\ne.g., <2>.  The second form is a pathname; if the pathname is prefixed  by  a  forward  slash\n('/'),  then  it  is  interpreted  relative to the root of the file system which is currently\nopened by debugfs.  If not, the pathname is interpreted relative to the current  working  di‐\nrectory as maintained by debugfs.  This may be modified by using the debugfs command cd.\n",
            "subsections": []
        },
        "COMMANDS": {
            "content": "This is a list of the commands which debugfs supports.\n\nblocks filespec\nPrint the blocks used by the inode filespec to stdout.\n\nbmap [ -a ] filespec logicalblock [physicalblock]\nPrint or set the physical block number corresponding to the logical block number logi‐\ncalblock in the inode filespec.  If the -a flag is specified, try to allocate a block\nif necessary.\n\nblockdump '[ -x ] [-f filespec] blocknum\nDump  the file system block given by blocknum in hex and ASCII format to the console.\nIf the -f option is specified, the block number is relative to the start of the  given\nfilespec.   If the -x option is specified, the block is interpreted as an extended at‐\ntribute block and printed to show the structure of extended attribute data structures.\n\ncat filespec\nDump the contents of the inode filespec to stdout.\n\ncd filespec\nChange the current working directory to filespec.\n\nchroot filespec\nChange the root directory to be the directory filespec.\n\nclose [-a]\nClose the currently open file system.  If the -a option is specified,  write  out  any\nchanges  to  the  superblock  and  block  group  descriptors  to all of the backup su‐\nperblocks, not just to the master superblock.\n\nclri filespec\nClear the contents of the inode filespec.\n\ncopyinode sourceinode destinationinode\nCopy the contents of the inode structure in sourceinode and use it to  overwrite  the\ninode structure at destinationinode.\n\ndirsearch filespec filename\nSearch the directory filespec for filename.\n\ndirty [-clean]\nMark the file system as dirty, so that the superblocks will be written on exit.  Addi‐\ntionally, clear the superblock's valid flag, or set it if -clean is specified.\n\ndump [-p] filespec outfile\nDump the contents of the inode filespec to the output file outfile.  If the -p option\nis  given  set the owner, group and permissions information on outfile to match file‐\nspec.\n\ndumpmmp [mmpblock]\nDisplay the multiple-mount protection (mmp) field values.  If mmpblock  is  specified\nthen  verify  and  dump  the MMP values from the given block number, otherwise use the\nsmmpblock field in the superblock to locate and use the existing MMP block.\n\ndxhash [-h hashalg] [-s hashseed] filename\nCalculate the directory hash of filename.  The hash algorithm specified with -h may be\nlegacy, halfmd4, or tea.  The hash seed specified with -s must be in UUID format.\n\ndumpextents [-n] [-l] filespec\nDump  the  the extent tree of the inode filespec.  The -n flag will cause dumpextents\nto only display the interior nodes in the  extent  tree.    The  -l  flag  will  cause\ndumpextents to only display the leaf nodes in the extent tree.\n\n(Please  note  that  the length and range of blocks for the last extent in an interior\nnode is an estimate by the extents library functions, and is not stored in file system\ndata  structures.    Hence,  the  values displayed may not necessarily by accurate and\ndoes not indicate a problem or corruption in the file system.)\n\ndumpunused\nDump unused blocks which contain non-null bytes.\n\neaget [-f outfile]|[-xVC] [-r] filespec attrname\nRetrieve the value of the extended attribute attrname in the file filespec and  write\nit either to stdout or to outfile.\n\nealist filespec\nList the extended attributes associated with the file filespec to standard output.\n\neaset [-f infile] [-r] filespec attrname attrvalue\nSet  the  value of the extended attribute attrname in the file filespec to the string\nvalue attrvalue or read it from infile.\n\nearm filespec attrnames...\nRemove the extended attribute attrname from the file filespec.\n\nexpanddir filespec\nExpand the directory filespec.\n\nfallocate filespec startblock [endblock]\nAllocate and map uninitialized blocks into filespec between logical block  startblock\nand  endblock,  inclusive.  If endblock is not supplied, this function maps until it\nruns out of free disk blocks or the maximum file size is reached.   Existing  mappings\nare left alone.\n\nfeature [fsfeature] [-fsfeature] ...\nSet  or clear various file system features in the superblock.  After setting or clear‐\ning any file system features that were requested, print the current state of the  file\nsystem feature set.\n\nfilefrag [-dvr] filespec\nPrint  the  number  of contiguous extents in filespec.  If filespec is a directory and\nthe -d option is not specified, filefrag will print the number of  contiguous  extents\nfor  each  file  in  the directory.  The -v option will cause filefrag print a tabular\nlisting of the contiguous extents in the file.  The -r option will cause  filefrag  to\ndo a recursive listing of the directory.\n\nfindfreeblock [count [goal]]\nFind  the first count free blocks, starting from goal and allocate it.  Also available\nas ffb.\n\nfindfreeinode [dir [mode]]\nFind a free inode and allocate it.  If present, dir specifies the inode number of  the\ndirectory  which the inode is to be located.  The second optional argument mode speci‐\nfies the permissions of the new inode.  (If the directory bit is set on the mode,  the\nallocation routine will function differently.)  Also available as ffi.\n\nfreeb block [count]\nMark  the  block  number  block  as  not allocated.  If the optional argument count is\npresent, then count blocks starting at block number block will be marked as not  allo‐\ncated.\n\nfreefrag [-c chunkkb]\nReport  free  space fragmentation on the currently open file system.  If the -c option\nis specified then the filefrag command  will  print  how  many  free  chunks  of  size\nchunkkb  can  be found in the file system.  The chunk size must be a power of two and\nbe larger than the file system block size.\n\nfreei filespec [num]\nFree the inode specified by filespec.  If num is specified, also  clear  num-1  inodes\nafter the specified inode.\n\ngetquota quotatype id\nDisplay quota information for given quota type (user, group, or project) and ID.\n\nhelp   Print a list of commands understood by debugfs.\n\nhtreedump filespec\nDump the hash-indexed directory filespec, showing its tree structure.\n\nicheck block ...\nPrint  a  listing of the inodes which use the one or more blocks specified on the com‐\nmand line.\n\ninodedump [-b]|[-e]|[-x] filespec\nPrint the contents of the inode data structure in hex and ASCII format.  The -b option\ncauses  the  command  to  only dump the contents of the iblocks array.  The -e option\ncauses the command to only dump the contents of the extra inode space, which  is  used\nto store in-line extended attributes. The -x option causes the command to dump the ex‐\ntra inode space interpreted and extended attributes.  This is  useful  to  debug  cor‐\nrupted inodes containing extended attributes.\n\nimap filespec\nPrint the location of the inode data structure (in the inode table) of the inode file‐\nspec.\n\ninitfilesys device blocksize\nCreate an ext2 file system on device with device size blocksize.  Note that this  does\nnot  fully  initialize  all of the data structures; to do this, use the mke2fs(8) pro‐\ngram.  This is just a call to the low-level library, which sets up the superblock  and\nblock descriptors.\n\njournalclose\nClose the open journal.\n\njournalopen [-c] [-v ver] [-f extjnl]\nOpens  the  journal  for  reading and writing.  Journal checksumming can be enabled by\nsupplying -c; checksum formats 2 and 3 can be selected with the -v option.  An  exter‐\nnal journal can be loaded from extjnl.\n\njournalrun\nReplay all transactions in the open journal.\n\njournalwrite [-b blocks] [-r revoke] [-c] file\nWrite  a  transaction to the open journal.  The list of blocks to write should be sup‐\nplied as a comma-separated list in blocks; the blocks themselves  should  be  readable\nfrom  file.   A  list of blocks to revoke can be supplied as a comma-separated list in\nrevoke.  By default, a commit record is written at the end; the -c  switch  writes  an\nuncommitted transaction.\n\nkillfile filespec\nDeallocate  the inode filespec and its blocks.  Note that this does not remove any di‐\nrectory entries (if any) to this inode.  See the rm(1) command if you wish to unlink a\nfile.\n\nlcd directory\nChange the current working directory of the debugfs process to directory on the native\nfile system.\n\nlistquota quotatype\nDisplay quota information for given quota type (user, group, or project).\n\nln filespec destfile\nCreate a link named destfile which is a hard link to filespec.  Note  this  does  not\nadjust the inode reference counts.\n\nlogdump [-acsOS] [-b block] [-i filespec] [-f journalfile] [outputfile]\nDump  the  contents of the ext3 journal.  By default, dump the journal inode as speci‐\nfied in the superblock.  However, this can be overridden with  the  -i  option,  which\ndumps  the journal from the internal inode given by filespec.  A regular file contain‐\ning journal data can be specified using the -f option.  Finally, the  -s  option  uti‐\nlizes the backup information in the superblock to locate the journal.\n\nThe -S option causes logdump to print the contents of the journal superblock.\n\nThe  -a option causes the logdump program to print the contents of all of the descrip‐\ntor blocks.  The -b option causes logdump to print all journal records that  refer  to\nthe  specified  block.   The  -c option will print out the contents of all of the data\nblocks selected by the -a and -b options.\n\nThe -O option causes logdump to display old (checkpointed) journal entries.  This  can\nbe  used  to  try  to  track down journal problems even after the journal has been re‐\nplayed.\n\nls [-l] [-c] [-d] [-p] [-r] filespec\nPrint a listing of the files in the directory filespec.  The -c flag causes  directory\nblock  checksums  (if present) to be displayed.  The -d flag will list deleted entries\nin the directory.  The -l flag will list files using a more verbose  format.   The  -p\nflag will list the files in a format which is more easily parsable by scripts, as well\nas making it more clear when there are spaces or other non-printing characters at  the\nend  of filenames.  The -r flag will force the printing of the filename, even if it is\nencrypted.\n\nlistdeletedinodes [limit]\nList deleted inodes, optionally limited to those deleted  within  limit  seconds  ago.\nAlso available as lsdel.\n\nThis  command  was  useful for recovering from accidental file deletions for ext2 file\nsystems.  Unfortunately, it is not useful for this purpose if the files  were  deleted\nusing  ext3  or  ext4, since the inode's data blocks are no longer available after the\ninode is released.\n\nmodifyinode filespec\nModify the contents of the inode structure in the inode filespec.  Also  available  as\nmi.\n\nmkdir filespec\nMake a directory.\n\nmknod filespec [p|[[c|b] major minor]]\nCreate  a special device file (a named pipe, character or block device).  If a charac‐\nter or block device is to be made, the major and minor device numbers must  be  speci‐\nfied.\n\nncheck [-c] inodenum ...\nTake  the  requested  list of inode numbers, and print a listing of pathnames to those\ninodes.  The -c flag will enable checking the file type information in  the  directory\nentry to make sure it matches the inode's type.\n\nopen [-weficD] [-b blocksize] [-d imagefilename] [-s superblock] [-z undofile] device\nOpen  a file system for editing.  The -f flag forces the file system to be opened even\nif there are some unknown or incompatible file system features  which  would  normally\nprevent  the  file system from being opened.  The -e flag causes the file system to be\nopened in exclusive mode.  The -b, -c, -d, -i, -s, -w, and -D options behave the  same\nas the command-line options to debugfs.\n\npunch filespec startblk [endblk]\nDelete the blocks in the inode ranging from startblk to endblk.  If endblk is omit‐\nted then this command will function as a truncate command; that is, all of the  blocks\nstarting at startblk through to the end of the file will be deallocated.\n\nsymlink filespec target\nMake a symbolic link.\n\npwd    Print the current working directory.\n\nquit   Quit debugfs\n\nrdump directory[...] destination\nRecursively  dump  directory, or multiple directories, and all its contents (including\nregular files, symbolic links, and other  directories)  into  the  named  destination,\nwhich should be an existing directory on the native file system.\n\nrm pathname\nUnlink  pathname.   If  this  causes the inode pointed to by pathname to have no other\nreferences, deallocate the file.  This command functions as the unlink() system call.\n\nrmdir filespec\nRemove the directory filespec.\n\nsetb block [count]\nMark the block number block as allocated.  If the optional argument count is  present,\nthen count blocks starting at block number block will be marked as allocated.\n\nsetblockgroup bgnum field value\nModify  the block group descriptor specified by bgnum so that the block group descrip‐\ntor field field has value value.  Also available as setbg.\n\nsetcurrenttime time\nSet current time in seconds since Unix epoch to use when setting file system fields.\n\nseti filespec [num]\nMark inode filespec as in use in the inode bitmap.  If  num  is  specified,  also  set\nnum-1 inodes after the specified inode.\n\nsetinodefield filespec field value\nModify  the inode specified by filespec so that the inode field field has value value.\nThe list of valid inode fields which can be set via this command can be  displayed  by\nusing the command: setinodefield -l Also available as sif.\n\nsetmmpvalue field value\nModify  the multiple-mount protection (MMP) data so that the MMP field field has value\nvalue.  The list of valid MMP fields which can be set via this  command  can  be  dis‐\nplayed by using the command: setmmpvalue -l Also available as smmp.\n\nsetsupervalue field value\nSet  the  superblock  field field to value.  The list of valid superblock fields which\ncan be set via this command can be displayed by using the command: setsupervalue  -l\nAlso available as ssv.\n\nshowdebugfsparams\nDisplay debugfs parameters such as information about currently opened file system.\n\nshowsuperstats [-h]\nList  the contents of the super block and the block group descriptors.  If the -h flag\nis given, only print out the superblock contents. Also available as stats.\n\nstat filespec\nDisplay the contents of the inode structure of the inode filespec.\n\nsupportedfeatures\nDisplay file system features supported by this version of debugfs.\n\ntestb block [count]\nTest if the block number block is marked as allocated in the block bitmap.  If the op‐\ntional  argument  count  is  present, then count blocks starting at block number block\nwill be tested.\n\ntesti filespec\nTest if the inode filespec is marked as allocated in the inode bitmap.\n\nundel <inodenumber> [pathname]\nUndelete the specified inode number (which must be surrounded by  angle  brackets)  so\nthat  it  and its blocks are marked in use, and optionally link the recovered inode to\nthe specified pathname.  The e2fsck command should always be run after using the undel\ncommand to recover deleted files.\n\nNote  that if you are recovering a large number of deleted files, linking the inode to\na directory may require the directory to be expanded, which  could  allocate  a  block\nthat  had  been  used  by one of the yet-to-be-undeleted files.  So it is safer to un‐\ndelete all of the inodes without specifying a destination pathname, and then in a sep‐\narate  pass,  use  the debugfs link command to link the inode to the destination path‐\nname, or use e2fsck to check the file system and link all of the recovered  inodes  to\nthe lost+found directory.\n\nunlink pathname\nRemove  the link specified by pathname to an inode.  Note this does not adjust the in‐\node reference counts.\n\nwrite sourcefile outfile\nCopy the contents of sourcefile into a newly-created file in the  file  system  named\noutfile.\n\nzapblock [-f filespec] [-o offset] [-l length] [-p pattern] blocknum\nOverwrite  the  block  specified by blocknum with zero (NUL) bytes, or if -p is given\nuse the byte specified by pattern.  If -f is given then blocknum is relative  to  the\nstart  of  the file given by filespec.  The -o and -l options limit the range of bytes\nto zap to the specified offset and length relative to the start of the block.\n\nzapblock [-f filespec] [-b bit] blocknum\nBit-flip portions of the physical blocknum.  If -f is given, then blocknum is a log‐\nical block relative to the start of filespec.\n",
            "subsections": []
        },
        "ENVIRONMENT VARIABLES": {
            "content": "DEBUGFSPAGER, PAGER\nThe  debugfs program always pipes the output of the some commands through a pager pro‐\ngram.  These commands include: showsuperstats (stats), listdirectory (ls), showin‐\nodeinfo  (stat), listdeletedinodes (lsdel), and htreedump.  The specific pager can\nexplicitly specified by the DEBUGFSPAGER environment variable, and if it is not  set,\nby the PAGER environment variable.\n\nNote  that  since a pager is always used, the less(1) pager is not particularly appro‐\npriate, since it clears the screen before displaying the output  of  the  command  and\nclears  the  output the screen when the pager is exited.  Many users prefer to use the\nless(1) pager for most purposes, which is why the DEBUGFSPAGER  environment  variable\nis available to override the more general PAGER environment variable.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "debugfs was written by Theodore Ts'o <tytso@mit.edu>.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "dumpe2fs(8), tune2fs(8), e2fsck(8), mke2fs(8), ext4(5)\n\n\n\nE2fsprogs version 1.46.5                    December 2021                                 DEBUGFS(8)",
            "subsections": []
        }
    },
    "summary": "debugfs - ext2/ext3/ext4 file system debugger",
    "flags": [
        {
            "flag": "-z",
            "long": null,
            "arg": null,
            "description": "Before overwriting a file system block, write the old contents of the block to an undo file. This undo file can be used with e2undo(8) to restore the old contents of the file system should something go wrong. If the empty string is passed as the undofile argument, the undo file will be written to a file named debugfs-device.e2undo in the directory specified via the E2FSPROGSUNDODIR environment variable. WARNING: The undo file cannot be used to recover from a power or system crash."
        }
    ],
    "examples": [],
    "see_also": [
        {
            "name": "dumpe2fs",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/dumpe2fs/8/json"
        },
        {
            "name": "tune2fs",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/tune2fs/8/json"
        },
        {
            "name": "e2fsck",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/e2fsck/8/json"
        },
        {
            "name": "mke2fs",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/mke2fs/8/json"
        },
        {
            "name": "ext4",
            "section": "5",
            "url": "https://www.chedong.com/phpMan.php/man/ext4/5/json"
        }
    ]
}