What is debugfs filesystem in Linux and how to mount it & make it persistent ?

In this article, we will look what is debugfs in-memory filesystem, it should not be confused with debugfs filesystem utility which we have seen yesterday.

In the last example, we tried to debug the filesystem, however here we get into a bit deeper and look what is debugfs in-memory filesystem.

debugfs is a memory based filesystem designed to debug Linux kernel code, and should not be mixed with debugfs filesystem debugging utility.

In December 2004, debugfs gets introduced by Greg Kroah-Hartman which helped kernel developers to export large amounts of debug data into user-space and helped them with kernel debugging.

So now the point must be clear with you, “Debugfs in-memory filesystem is used to debug kernel code by having debug data in user-space”

Now lets check out how to mount debugfs filesystem for kernel code debugging.

1. Mount Debugfs FS(filesystem)
Lets mount /sys/kernel/debug as debugfs filesystem.

### We need to mount the path /sys/kernel/debug
[root@nglinux ~]# mount -t debugfs nodev /sys/kernel/debug

### Now check if its successfully mounted.
[root@nglinux ~]# mount | grep -i debugfs
nodev on /sys/kernel/debug type debugfs (rw)
[root@nglinux ~]# 

2. Check out debugfs filesystem contents
Verify if the debugfs is mounted and we have tools available.
Just check out contents of the newly mounted location.

[root@nglinux ~]# ls  /sys/kernel/debug/
bdi          dma_buf  dynamic_debug  gpio  ipoib    mce             tracing  vmmemctl  xen
boot_params  dri      extfrag        hid   kprobes  sched_features  usb      x86
[root@nglinux ~]# 

Hence we have the debugfs successfully mounted and can see its contents.

3. Now if you wish to do kernel debugging, we suggest you to make it persistent, by making below entry in /etc/fstab.

[root@nglinux ~]# tail -1 /etc/fstab 
debugfs 		/sys/kernel/debug 	debugfs defaults 0 0
[root@nglinux ~]# 

4. Verify the /etc/fstab entries if working correctly.

### First umount /sys/kernel/debug
[root@nglinux ~]# umount /sys/kernel/debug
[root@nglinux ~]# mount | grep -i debugfs

### Now mount all drives mentioned in /etc/fstab
[root@nglinux ~]# mount -a

### If above command works, successfully, it means entry is correct.
[root@nglinux ~]# mount | grep -i debugfs
debugfs on /sys/kernel/debug type debugfs (rw)
[root@nglinux ~]# 

Now the filesystem gets mounted automatically after system boot up.

And we can go ahead and try kernel debugging.

To know how to proceed further with kernel code debugging with debugfs, i will post next article in few days.

Subscribe to this blog, to stay updated.

I hope you liked the introduction.

Leave a Reply

Your email address will not be published.