How to use the command "btrfs inspect-internal" (with examples)
The “btrfs inspect-internal” command is used to query internal information of a btrfs filesystem. It provides various options to inspect different aspects of the filesystem, such as the superblock, metadata, inodes, logical addresses, and tree statistics.
Use case 1: Print superblock’s information
Code:
sudo btrfs inspect-internal dump-super path/to/partition
Motivation: This use case is helpful when you want to obtain detailed information about the superblock of a btrfs filesystem. The superblock contains critical metadata about the filesystem, including its UUID, size, and features.
Explanation: The “dump-super” option is used to print the superblock’s information. The “path/to/partition” argument specifies the path to the mounted btrfs partition.
Example output:
UUID: 127761c5-d3c3-45bf-b5af-8de45f8a1093
Total devices: 1
Devices:
ID SIZE PATH
1 100GB /dev/sda1
Label: none uuid: 127761c5-d3c3-45bf-b5af-8de45f8a1093
Use case 2: Print superblock’s and all of its copies’ information
Code:
sudo btrfs inspect-internal dump-super --all path/to/partition
Motivation: This use case is useful when you want to examine the superblock’s information and its copies. Btrfs filesystems maintain multiple copies of the superblock for redundancy, and this option allows you to access all of them.
Explanation: The “–all” option is added to the previous command to include the information from all copies of the superblock.
Example output:
Primary superblock at 0x10000
[Primary superblock]:
UUID = 127761c5-d3c3-45bf-b5af-8de45f8a1093
LABEL: none uuid: 127761c5-d3c3-45bf-b5af-8de45f8a1093
...
Backup superblock at 0x100000000
[Backup superblock]:
UUID = 8dab9872-a51e-43f8-9d38-959b2c047b71
LABEL: none uuid: 8dab9872-a51e-43f8-9d38-959b2c047b71
Use case 3: Print filesystem’s metadata information
Code:
sudo btrfs inspect-internal dump-tree path/to/partition
Motivation: This use case is useful when you want to analyze the metadata structure of a btrfs filesystem. The metadata includes information about the tree roots, inodes, data extents, and other internal components.
Explanation: The “dump-tree” option is used to print the filesystem’s metadata information.
Example output:
Chunk tree backref root 3689 gen 3 root level 0 flags 0
key backpointer 0000000000000000
item gen 3 start 1048576 len 16384 root_chunk 3687 owner 1 type 1
generation_v2 self 3 root level 0 num_backrefs 0
generation self 3 flags 0 total_bytes 0 bytes_used 0
Root tree backref root 3688 gen 3 root level 0 flags 0
key backpointer 0000000000000000
item gen 3 start 12058624 len 16384 root_chunk 3687 owner 5 type 1
generation_v2 self 3 root level 0 num_backrefs 0
generation self 3 flags 0 total_bytes 0 bytes_used 0
...
Use case 4: Print list of files in inode n
-th
Code:
sudo btrfs inspect-internal inode-resolve n path/to/btrfs_mount
Motivation: This use case is helpful when you want to investigate the files associated with a specific inode number in a btrfs filesystem. Inodes store file metadata, and this command can help identify the files linked to a particular inode.
Explanation: The “inode-resolve” option is used to print a list of files in the n
-th inode. The “n” argument specifies the inode number, and the “path/to/btrfs_mount” argument specifies the path to the mounted btrfs filesystem.
Example output:
Inode 56 path item 0 name: (null)
Inode 56 gen: 1 parent: 5 trans: 7 flags: 0
Inode 56 uid: 1000 gid: 1000
Inode 56 size: 4096 bytes
Inode 56 ctime: 2022-01-01 12:00:00.000000000
Inode 56 mtime: 2022-01-01 12:00:00.000000000
Inode 56 atime: 2022-01-01 12:00:00.000000000
...
Use case 5: Print list of files at a given logical address
Code:
sudo btrfs inspect-internal logical-resolve logical_address path/to/btrfs_mount
Motivation: This use case is useful when you want to find the files located at a particular logical address within a btrfs filesystem. Logical addresses are used to map the file’s data to physical disk blocks, and this command helps identify the files corresponding to a specific logical address.
Explanation: The “logical-resolve” option is used to print the list of files at the given logical address. The “logical_address” argument specifies the logical address, and the “path/to/btrfs_mount” argument specifies the path to the mounted btrfs filesystem.
Example output:
Inode 57 path item 0 name: (null)
Inode 57 gen: 2 parent: 5 trans: 7 flags: 0
Inode 57 uid: 1000 gid: 1000
Inode 57 size: 8192 bytes
Inode 57 ctime: 2022-01-01 12:00:00.000000000
Inode 57 mtime: 2022-01-01 12:00:00.000000000
Inode 57 atime: 2022-01-01 12:00:00.000000000
...
Use case 6: Print stats of root, extent, csum, and fs trees
Code:
sudo btrfs inspect-internal tree-stats path/to/partition
Motivation: This use case is helpful when you want to gather statistical information about the root, extent, checksum, and filesystem trees of a btrfs filesystem. It can provide insights into the distribution and utilization of different types of data within the filesystem.
Explanation: The “tree-stats” option is used to print the statistics of the root, extent, checksum, and filesystem trees.
Example output:
Root tree: level 1 items 36 free space 667 generation 7 size 4096
generation self 7 top level 0 level 1 num_backrefs 0
bflags 0
Extent tree: level 2 items 119698 free space 60334714 generation 7 size 4096
generation self 7 top level 1 level 2 num_backrefs 0
bflags 0
Checksum tree: level 2 items 8919 free space 4299690 generation 7 size 4096
generation self 7 top level 2 level 2 num_backrefs 0
bflags 0
...
Conclusion:
The “btrfs inspect-internal” command is a powerful tool for accessing internal information of a btrfs filesystem. By utilizing its various options, such as printing the superblock, metadata, inodes, logical addresses, and tree statistics, users gain insights into the filesystem’s structure and contents. This information can aid in troubleshooting, analysis, and understanding the behavior of a btrfs filesystem.