> For the complete documentation index, see [llms.txt](https://lightc.gitbook.io/pwn-gitbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lightc.gitbook.io/pwn-gitbook/kpwn/kpwn-setup/debugfs.md).

# debugfs

`debugfs` 是 `Linux` 中专门用于 `ext2`\~`ext4` 文件系统的交互性调试工具。

可以直接查看和修改文件系统的元数据和文件内容而不依赖于挂载文件系统。

## 用法

```bash
debugfs -w -R "< command >" < filesystem/image >
```

在 `kernel pwn` 中最常见的 `command` 就是：

**提取文件**

```bash
debugfs -w -R "dump < image-file > < file >" rootfs.img
```

**写入文件**

```bash
debugfs -w -R "write < file > < image-file >" rootfs.img
```

**删除文件**

```bash
debugfs -w -R "rm < image-file >" rootfs.img
```

一般用于 `img` 文件，`cpio` 的还是使用 `cpio` 打包和解包
