DEBUGFS(8)
โจ NAME โจ
debugfs โ the ext2/ext3/ext4 file system debugger ๐
๐ SYNOPSIS ๐
debugfs [ -DVwcin ] [ -b blocksize ] [ -s superblock ] [ -f cmd_file ] [
-R request ] [ -d data_source_device ] [ -z undo_file ] [ device ]
๐ฆ DESCRIPTION ๐ฆ
okay so bestie, debugfs is an interactive file system debugger. That's the whole vibe. You use it to examine and change the state of an ext2, ext3, or ext4 file system. It's giving surgeon energy, honestly. ๐ฉบโจ
device is a block device (think /dev/sdXX) or a file that contains the file system. That's your entry point, no cap.
๐ OPTIONS ๐
-wโ opens the file system in read-write mode. And if you don't pass this? It's read-only, periodt. No writey-writey unless you ask. ๐ซถ-nโ disables metadata checksum verification. Only do this if you genuinely believe the metadata is correct even thoughe2fsprogsis out here complaining about it. iykyk. ๐-cโ opens the file system in catastrophic mode, where the inode and group bitmaps are not read up front. Lowkey useful for file systems with significant corruption, but because of that, catastrophic mode forces the file system to be opened read-only. It's literally in the name bestie.-iโ says that device represents an ext2 image file created by thee2imageprogram. And here's the tea: since that ext2 image file only contains the superblock, block group descriptor, block and inode allocation bitmaps, and the inode table, manydebugfscommands will not function properly. ๐จ
Warning: no safety checks are in place, anddebugfsmay fail in interesting ways if commands such asls,dump, etc. are tried without specifying the data_source_device using the-doption.debugfsis a debugging tool. It has rough edges! ๐
-ddata_source_device โ used together with the-ioption. Tells it that data_source_device should be used when reading blocks that aren't found in the ext2 image file. That includes data, directory, and indirect blocks. ๐ง-bblocksize โ forces the use of the given block size (in bytes) for the file system, instead of detecting the correct block size automatically. (This option is rarely needed; it's used primarily when the file system is extremely badly damaged/corrupted. ๐ญ)-ssuperblock โ makes the file system superblock be read from the given block number, instead of using the primary superblock (which lives at an offset of 1024 bytes from the beginning of the file system). Heads up: if you specify-s, you must also provide the blocksize of the file system via the-boption. (Again, rarely needed; it's for when the file system is extremely badly damaged/corrupted. ๐ฉน)-fcmd_file โ makesdebugfsread in commands from cmd_file and execute them. Once it's done executing those commands, it exits. Very scripted-queen of it. ๐-Dโ makesdebugfsopen the device using Direct I/O, bypassing the buffer cache. Note that some Linux devices, notably device mapper as of this writing, do not support Direct I/O. ๐-Rrequest โ makesdebugfsexecute the single command request, and then exit. One and done, main character energy. โจ-Vโ prints the version number ofdebugfsand exits. Short and sweet. ๐-zundo_file โ before overwriting a file system block, writes the old contents of that block to an undo file. That undo file can be used withe2undo(8)to restore the old contents of the file system should something go wrong. If the empty string is passed as the undo_file argument, the undo file will be written to a file nameddebugfs-device.e2undoin the directory specified via theE2FSPROGS_UNDO_DIRenvironment variable. ๐
WARNING: The undo file cannot be used to recover from a power or system crash. Not even a little bit. ๐ซโก
๐ธ SPECIFYING FILES ๐ธ
So many debugfs commands take a filespec as an argument to specify an inode (as opposed to a pathname) in the file system that debugfs currently has open. Obsessed with the precision, honestly.
The filespec argument can come in two forms:
- An inode number surrounded by angle brackets, e.g.
<2>. ๐ฏ - A pathname. If the pathname is prefixed by a forward slash (
/), it's interpreted relative to the root of the file system currently opened bydebugfs. If it's not prefixed, the pathname is interpreted relative to the current working directory as maintained bydebugfsโ and you can change that using thedebugfscommandcd. ๐ถโ๏ธ๐จ
๐ COMMANDS ๐
This is the list of the commands that debugfs supports. Buckle up bestie, there's a lot and they're all iconic in their own way. ๐ซถ
blocks filespec
Print the blocks used by the inode filespec to stdout. ๐งพ
bmap [ -a ] filespec logical_block [physical_block]
Print or set the physical block number corresponding to the logical block number logical_block in the inode filespec. If the -a flag is specified, it tries to allocate a block if necessary. ๐
block_dump '[ -x ] [-f filespec] block_num
Dump the file system block given by block_num in hex and ASCII format to the console. If the -f option is specified, the block number is relative to the start of the given filespec. If the -x option is specified, the block is interpreted as an extended attribute block and printed to show the structure of extended attribute data structures. ๐
cat filespec
Dump the contents of the inode filespec to stdout. Yes bestie, it's literally cat. ๐ป
cd filespec
Change the current working directory to filespec. ๐ช
chroot filespec
Change the root directory to be the directory filespec. Root privilege but make it filesystem-y. ๐
close [-a]
Close the currently open file system. If the -a option is specified, write out any changes to the superblock and block group descriptors to all of the backup superblocks, not just to the master superblock. ๐
clri filespec
Clear the contents of the inode filespec. Poof. ๐จ
copy_inode source_inode destination_inode
Copy the contents of the inode structure in source_inode and use it to overwrite the inode structure at destination_inode. Copy-paste but for inode structs, we love to see it. ๐
dirsearch filespec filename
Search the directory filespec for filename. ๐
dirty [-clean]
Mark the file system as dirty, so that the superblocks will be written on exit. Additionally, clear the superblock's valid flag โ or set it, if -clean is specified. ๐งผ
dump [-p] filespec out_file
Dump the contents of the inode filespec to the output file out_file. If the -p option is given, set the owner, group and permissions information on out_file to match filespec. ๐พ
dump_mmp [mmp_block]
Display the multiple-mount protection (mmp) field values. If mmp_block is specified, verify and dump the MMP values from the given block number; otherwise use the s_mmp_block field in the superblock to locate and use the existing MMP block. ๐ก๏ธ
dx_hash [-cv] [-h hash_alg] [-s hash_seed] filename
Calculate the directory hash of filename. The -c option will casefold the filename before calculating the hash. The -v option will make the dx_hash command more verbose and print the hash algorithm and hash seed used to calculate the hash. If a file system is open, use the hash_seed and default hash_algorithm used by the file system โ although these can be overridden by the -h and -s options. The hash algorithm specified with -h may be legacy, half_md4, or tea. The hash seed specified with -s must be in UUID format. ๐ฅ
dump_extents [-n] [-l] filespec
Dump the extent tree of the inode filespec. The -n flag will cause dump_extents to only display the interior nodes in the extent tree. The -l flag will cause dump_extents to only display the leaf nodes in the extent tree. ๐ณ
(Please note that the length and range of blocks for the last extent in an interior node is an estimate by the extents library functions, and is not stored in file system data structures. Hence, the values displayed may not necessarily be accurate and does not indicate a problem or corruption in the file system. So don't panic bestie. ๐)
dump_unused
Dump unused blocks which contain non-null bytes. The leftovers, the crumbs, the forgotten ones. ๐
ea_get [-f outfile]|[-xVC] [-r] filespec attr_name
Retrieve the value of the extended attribute attr_name in the file filespec and write it either to stdout or to outfile. ๐ค
ea_list filespec
List the extended attributes associated with the file filespec to standard output. ๐
ea_set [-f infile] [-r] filespec attr_name attr_value
Set the value of the extended attribute attr_name in the file filespec to the string value attr_value, or read it from infile. โ๏ธ
ea_rm filespec attr_names...
Remove the extended attribute attr_name from the file filespec. Bye bestie. ๐
expand_dir filespec
Expand the directory filespec. ๐
fallocate filespec start_block [end_block]
Allocate and map uninitialized blocks into filespec between logical block start_block and end_block, inclusive. If end_block is not supplied, this function maps until it runs out of free disk blocks or the maximum file size is reached. Existing mappings are left alone โ no touching, no drama. ๐ซถ
feature [fs_feature] [-fs_feature] ...
Set or clear various file system features in the superblock. After setting or clearing any file system features that were requested, print the current state of the file system feature set. ๐๏ธ
filefrag [-dvr] filespec
Print the number of contiguous extents in filespec. If filespec is a directory and the -d option is not specified, filefrag will print the number of contiguous extents for each file in the directory. The -v option will cause filefrag to print a tabular listing of the contiguous extents in the file. The -r option will cause filefrag to do a recursive listing of the directory. ๐๏ธ
find_free_block [count [goal]]
Find the first count free blocks, starting from goal, and allocate it. Also available as ffb. ๐งฑ
find_free_inode [dir [mode]]
Find a free inode and allocate it. If present, dir specifies the inode number of the directory in which the inode is to be located. The second optional argument mode specifies the permissions of the new inode. (If the directory bit is set on the mode, the allocation routine will function differently.) Also available as ffi. ๐
freeb block [count]
Mark the block number block as not allocated. If the optional argument count is present, then count blocks starting at block number block will be marked as not allocated. Freed and thriving. ๐
freefrag โ freefrag [-c chunk_kb]
okay so this one is literally the fragmentation vibe check for the file system you've currently got open ๐ซถ. Add the -c option and the filefrag command will tell you how many free chunks of size chunk_kb it can find in the file system. Two rules tho, no cap: the chunk size has to be a power of two, and it has to be bigger than the file system block size. ๐
freei โ freei filespec [num]
frees the inode that filespec is pointing at ๐ฆ. And if you also hand it a num, it'll clear num-1 inodes right after that specified inode too. bye bestie โจ
get_quota โ get_quota quota_type id
shows you the quota info for the quota type you asked for โ that's user, group, or project โ plus the matching ID. that's it, that's the whole thing ๐
help
prints the list of commands that debugfs actually understands ๐. your little cheat sheet, periodt.
htree_dump โ htree_dump filespec
dumps the hash-indexed directory filespec and shows you its whole tree structure ๐ณ. very "let me show you the family tree" energy.
icheck โ icheck block ...
give it one or more blocks on the command line and it prints a listing of the inodes that use them ๐.
inode_dump โ inode_dump [-b]|[-e]|[-x] filespec
prints the contents of the inode data structure in hex and ASCII ๐ฅ. the flags, listen up:
-bโ only dumps the contents of thei_blocksarray.-eโ only dumps the contents of the extra inode space, which is where in-line extended attributes live.-xโ dumps the extra inode space interpreted as extended attributes.
and like, this whole command is genuinely useful for debugging corrupted inodes that are carrying extended attributes around. ๐
imap โ imap filespec
prints the location of the inode data structure (like, in the inode table) for the inode filespec ๐.
init_filesys โ init_filesys device blocksize
creates an ext2 file system on device with device size blocksize ๐.
heads up bestie: this does NOT fully initialize all of the data structures. if you want the full thing done properly, use the mke2fs(8) program. this is literally just a call to the low-level library that sets up the superblock and the block descriptors. that's all it does, no more. ๐
journal_close
closes the open journal. doors closed, lights off, bye ๐
journal_open โ journal_open [-c] [-v ver] [-f ext_jnl]
opens the journal for reading and writing โจ. you can turn on journal checksumming by supplying -c, and checksum formats 2 and 3 get selected with the -v option. an external journal can be loaded from ext_jnl via -f ๐.
journal_run
replays all the transactions in the open journal ๐. it's giving "rewind and re-run".
journal_write โ journal_write [-b blocks] [-r revoke] [-c] file
writes a transaction to the open journal โ๏ธ. the list of blocks to write should come in as a comma-separated list in blocks, and the blocks themselves should be readable from file. you can also hand over a list of blocks to revoke as a comma-separated list in revoke. by default a commit record gets written at the end โ but the -c switch makes it write an uncommitted transaction instead ๐.
kill_file โ kill_file filespec
deallocates the inode filespec and all its blocks ๐.
ngl this one does NOT remove any directory entries (if there even are any) pointing at this inode. if your goal is to actually unlink a file, go look at the rm(1) command instead.
lcd โ lcd directory
changes the current working directory of the debugfs process itself to directory on the native file system ๐ง. yes, it's lcd โ the "local" one, not the file-system-inside one, iykyk.
list_quota โ list_quota quota_type
displays the quota information for the given quota type โ again, that's user, group, or project ๐ธ.
ln โ ln filespec dest_file
creates a link named dest_file that's a hard link to filespec ๐.
real talk: this does NOT adjust the inode reference counts. noted, and now you know. ๐
logdump โ logdump [-acsOS] [-b block] [-n num_trans ] [-i filespec] [-f journal_file] [output_file]
dumps the contents of the ext3 journal ๐. by default it dumps the journal inode exactly as specified in the superblock. but you can override that with -i, which dumps the journal from the internal inode given by filespec. a regular file containing journal data can be specified with -f. and finally, the -s option uses the backup information sitting in the superblock to locate the journal. okay now the rest of the flags, one by one:
-Sโ causeslogdumpto print the contents of the journal superblock.-aโ causeslogdumpto print the contents of all of the descriptor blocks.-bโ causeslogdumpto print all journal records that refer to the specifiedblock.-cโ prints out the contents of all of the data blocks selected by the-aand-boptions.-Oโ causeslogdumpto display old (checkpointed) journal entries ๐. this one's for trying to track down journal problems even after the journal has been replayed.-nโ causeslogdumpto continue past a journal block that's missing a magic number ๐ญ. instead, it'll stop only when the entire log is printed, or afternum_transtransactions.
ls โ ls [-l] [-c] [-d] [-p] [-r] filespec
prints a listing of the files in the directory filespec ๐. the flags do this:
-cโ causes directory block checksums (if present) to be displayed.-dโ lists deleted entries in the directory ๐.-lโ lists files using a more verbose format.-pโ lists the files in a format that's way more easily parsable by scripts, and it also makes it more clear when there are spaces or other non-printing characters hanging out at the end of filenames.-rโ forces the printing of the filename, even if it's encrypted ๐.
list_deleted_inodes โ list_deleted_inodes [limit]
lists deleted inodes, optionally limited to those that got deleted within limit seconds ago โณ. also available as lsdel โจ.
so back in the day this command was useful for recovering from accidental file deletions on ext2 file systems. unfortunately it's not useful for that purpose if the files were deleted using ext3 or ext4, because the inode's data blocks are just... no longer available once the inode is released. sorry bestie ๐ญ
modify_inode โ modify_inode filespec
modifies the contents of the inode structure in the inode filespec โ๏ธ. also available as mi ๐.
mkdir โ mkdir filespec
makes a directory. that's the tweet ๐ฆ.
mknod โ mknod filespec [p|[[c|b] major minor]]
creates a special device file โ a named pipe, or a character or block device ๐
. and if it's a character or block device you're making, then the major and minor device numbers must be specified. no skipping that part.
ncheck โ ncheck [-c] inode_num ...
takes the list of inode numbers you give it and prints a listing of the pathnames pointing to those inodes ๐ค๏ธ. the -c flag enables checking the file type information in the directory entry, to make sure it matches the inode's type โ
.
open โ open [-weficD] [-b blocksize] [-d image_filename] [-s superblock] [-z undo_file] device
opens a file system for editing ๐. the flags:
-fโ forces the file system to be opened even if there are some unknown or incompatible file system features that would normally stop it from being opened ๐จ.-eโ causes the file system to be opened in exclusive mode.-b,-c,-d,-i,-s,-w, and-Dโ these behave exactly the same as the command-line options todebugfs.
orphan_inodes
lists the orphan inodes in the file system ๐ฅบ. they're just little guys with no home.
punch โ punch filespec start_blk [end_blk]
deletes the blocks in the inode ranging from start_blk to end_blk ๐ณ๏ธ. and if you leave off end_blk, then this command functions as a truncate command โ meaning all of the blocks starting at start_blk through to the end of the file get deallocated. โ๏ธ
symlink โ symlink filespec target
makes a symbolic link ๐.
pwd
prints the current working directory ๐.
quit
quits debugfs. exit stage left, you ate ๐.
rdump โ rdump directory[...] destination
recursively dumps directory, or multiple directories, plus all their contents (regular files, symbolic links, and other directories too) into the named destination ๐ฆ. and heads up: destination should be an existing directory on the native file system.
rm โ rm pathname
unlinks pathname ๐ช. if that causes the inode pointed to by pathname to have no other references, then it deallocates the file. this command functions as the unlink() system call, fr fr.
rmdir โ rmdir filespec
removes the directory filespec ๐๏ธ.
setb โ setb block [count]
marks the block number block as allocated โ
. if the optional argument count is present, then count blocks starting at block number block get marked as allocated too.
set_block_group โ set_block_group bgnum field value
modifies the block group descriptor specified by bgnum so that the block group descriptor field field has value value ๐
. also available as set_bg โจ.
set_current_time โ set_current_time time
sets the current time, in seconds since the Unix epoch, to use whenever it's setting file system fields ๐ฐ๏ธ. time travel but make it filesystem.
seti โ seti filespec [num]
marks inode filespec as in use in the inode bitmap ๐. and if num is specified, it also sets num-1 inodes after the specified inode.
set_inode_field โ set_inode_field filespec field value
modifies the inode specified by filespec so that the inode field field has value value ๐ ๏ธ. and you can see the whole list of valid inode fields that can be set with this command by running:
set_inode_field -l
also available as sif ๐.
set_mmp_value โ set_mmp_value field value
modifies the multiple-mount protection (MMP) data so that the MMP field field has value value ๐ฅ. the list of valid MMP fields you can set with this command? display it with:
set_mmp_value -l
also available as smmp โจ.
set_super_value โ set_super_value field value
sets the superblock field field to value ๐. to see the list of valid superblock fields you can set with this command, run:
set_super_value -l
also available as ssv ๐.
show_debugfs_params
displays debugfs parameters, like information about the file system that's currently opened ๐.
show_super_stats โ show_super_stats [-h]
lists the contents of the super block and the block group descriptors ๐. if you give it the -h flag, it only prints out the superblock contents. also available as stats ๐ฆ.
stat โ stat filespec
displays the contents of the inode structure of the inode filespec ๐.
supported_features
displays the file system features supported by this version of debugfs โญ. a little resume, if you will.
testb โ testb block [count]
tests whether the block number block is marked as allocated in the block bitmap ๐ง. if the optional argument count is present, then count blocks starting at block number block get tested.
testi โ testi filespec
tests whether the inode filespec is marked as allocated in the inode bitmap โ
.
undel โ bringing deleted files back from the void ๐งโโ๏ธโจ
undel<inode_number>[pathname] โ un-deletes the inode you name, and yeah, it has to be wrapped in angle brackets like<12>or it won't vibe. Once it's back, the inode and all its blocks get marked as in use again, and if you also hand over apathname, it'll link the recovered inode there for you. ๐ซถ
bestie listen. Always rune2fsckafter usingundelto recover deleted files. Always. Not optional, not "maybe later". Always. ๐
Also, real talk: if you're recovering a large number of deleted files, linking an inode to a directory might force that directory to be expanded, and that expansion could allocate a block that one of your yet-to-be-undeleted files was still using. Messy!! So the safer glow-up is:
- Undelete all the inodes without specifying a destination
pathname. - Then, in a separate pass, either use the
debugfslinkcommand to link the inode to the destinationpathname, or usee2fsckto check the file system and link all of the recovered inodes to thelost+founddirectory.
Two passes, zero regrets, that's the move. ๐
unlink โ bye bye link ๐
unlinkpathnameโ removes the link specified bypathnameto an inode. That's it, that's the whole job. Note: this does not adjust the inode reference counts, so don't come crying tounlinkabout refcounts, it's not that kind of command. ๐
write โ copy-paste but make it filesystem ๐ฆ
writesource_fileout_fileโ copies the contents ofsource_fileinto a newly-created file inside the file system, and that new file is namedout_file. New file, fresh start, main character energy. โจ
zap_block โ the block destroyer, two flavours ๐ฅ
Flavour one: overwrite it
zap_block[-ffilespec][-ooffset][-llength][-ppattern]**block_numโ overwrites the block specified byblock_numwith zero (NUL) bytes. If-pis given, it uses the byte specified bypatterninstead. If-fis given, thenblock_numis relative to the start of the file given byfilespec. And the-oand-loptions limit the range of bytes to zap to the specifiedoffsetandlengthrelative to the start of the block. ๐ฏ
Flavour two: bit-flip it
zap_block[-ffilespec][-bbit]**block_numโ bit-flips portions of the physicalblock_num. If-fis given, thenblock_numis a logical block relative to the start offilespec. ๐
This one literally rewrites blocks. Be so fr before you type it. ๐ญ
๐ ENVIRONMENT VARIABLES ๐
DEBUGFS_PAGER,PAGERโdebugfsalways pipes the output of some commands through a pager program. The commands in question are:show_super_stats(akastats)list_directory(akals)show_inode_info(akastat)list_deleted_inodes(akalsdel)htree_dump
The specific pager can be explicitly specified by the DEBUGFS_PAGER environment variable, and if that one isn't set, then by the PAGER environment variable. ๐
Heads up: because a pager is always used, the less(1) pager is not particularly appropriate, since it clears the screen before displaying the output of the command, and clears the output of the screen when the pager is exited. ๐ฌ
Many users prefer to use the less(1) pager for most purposes โ which is literally why the DEBUGFS_PAGER environment variable exists, so you can override the more general PAGER environment variable. iykyk. ๐
๐ AUTHOR ๐
debugfs was written by Theodore Ts'o <tytso@mit.edu>. Legend behaviour, honestly. ๐ซก
๐ธ SEE ALSO ๐ธ
And that's a wrap on the whole page, bestie!! ๐ This one's from E2fsprogs version 1.47.4, dated March 2025, and it's the DEBUGFS(8) manual page โ go forth and debug your file systems responsibly. Slay, stay safe, and back up your data before you zap_block anything. ๐
๐โจ
๐ฆ where this page comes from
- alpine 3.24: e2fsprogs-doc 1.47.4-r0 ยท GPL-2.0-or-later AND LGPL-2.0-or-later AND BSD-3-Clause AND MIT
- arch rolling: e2fsprogs 1.47.4-1 ยท GPL AND LGPL AND MIT
- nixpkgs unstable: e2fsprogs 1.47.4
- ubuntu stonking: e2fsprogs 1.47.4-1 ยท GPL-2.0-only
- Copyright 1993, 1994, 1995 by Theodore Ts'o. All Rights Reserved
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms