What is debugfs in Linux and how to use this command ?

Today we will check out what is the use of debugfs utility in Linux and how we can use this to ease our life and for troubleshooting.

First lets check out what is debugfs.

What is Debugfs ?
debugfs is an interactive ext2/ext3/ext4 file system debugger.
We can examine and change the state of a filesystem using this command.

1. Running Debugfs

[root@nglinux ~]# debugfs
debugfs 1.41.12 (17-May-2010)
debugfs:  

2. Opening Filesystem

debugfs:  open /dev/sda1

3. Viewing Filesystem stats

debugfs:  stats
Filesystem volume name:   
Last mounted on:          /
Filesystem UUID:          e91618e7-a10b-499a-9652-682de8b5cfa1
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent fle
x_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Filesystem flags:         signed_directory_hash 
Default mount options:    (none)
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              1310720
Block count:              5241198
Reserved block count:     262059
Free blocks:              2656197
Free inodes:              1140152
First block:              0
Block size:               4096
Fragment size:            4096
debugfs:  

4. Searching for inode 917831 on this filesystem.

### However its slow, you can use find command for fast output.
debugfs:  ncheck 917831
Inode	Pathname
917831	/root/file1

5. Browse the filesystem for debugging inside debugfs

debugfs:  ls
 2  (12) .    2  (12) ..    11  (20) lost+found    131073  (12) proc   
 262145  (12) mnt    655361  (12) sys    786433  (16) cgroup   
 12  (20) .autofsck    1048577  (12) usr    917505  (12) home   
 786434  (12) sbin    786746  (12) srv    786747  (12) var   
 918261  (12) opt    918263  (12) tmp    918343  (12) root   
 919656  (12) boot    919736  (16) media    919737  (12) lib   
 658612  (16) selinux    658613  (12) dev    658614  (12) bin   
 658733  (12) etc    655460  (12) data    531712  (3780) custom   
debugfs:  pwd
[pwd]   INODE:      2  PATH: /
[root]  INODE:      2  PATH: /
debugfs:

6. Viewing any file/dir extent information.

debugfs:  ex -l /root/file1
Level Entries       Logical          Physical Length Flags
 0/ 0   1/  1     0 -     0 3706379 - 3706379      1 
debugfs:  

7. Check out free inode

debugfs:  ffi
Free inode found: 11859

There is a lot more we can do using debugfs command, playing with inodes, undelete files, etc.

I will post about it in next articles.

You can view all commands that are supported by debugfs command using “help”.

debugfs:  help
Available debugfs requests:
show_debugfs_params, params
                         Show debugfs parameters
open_filesys, open       Open a filesystem
close_filesys, close     Close the filesystem
feature, features        Set/print superblock features
dirty_filesys, dirty     Mark the filesystem as dirty
init_filesys             Initialize a filesystem (DESTROYS DATA)

I hope you liked the basic introduction.

Do post your comments/suggestions below.

Leave a Reply

Your email address will not be published.