分区里的inode号是0号和1号的block
我相信大家在使用Linux的时候都遇到过误删文件系统数据的情况,不管是自己误删还是帮人家恢复误删
现在用的比较多的恢复工具大概是ext3grep 、extundelete 这两个
当然本文不是要说这两个工具的使用方法,而是介绍每个分区里的inode号为0或1号的block到底是什么
在使用ext3grep 、extundelete 的时候,基本上都会有这样一个步骤
在Linux下可以通过“ls-id”命令来查看某分区目录的inode值,可以输入:
[root@localhost /]#ls –id /
2 /
[root@steven ~]# ls -id /boot
2 /boot
可以看到,无论是哪个分区,它的inode值都是2,而不是0,也不是1
并且当你用find命令来搜索一下0或1号inode的时候也是什么也找不到
find / -inum 0
find: `/proc/1461/task/1461/fd/5': No such file or directory
find: `/proc/1461/task/1461/fdinfo/5': No such file or directory
find: `/proc/1461/fd/5': No such file or directory
find: `/proc/1461/fdinfo/5': No such file or directory
那么inode为0或1的block去哪里了?
boot sector 与 superblock 的关系
block 为 1024 bytes (1K) 时:
如果 block 大小刚好是 1024 的话,那么 boot sector 与 superblock 各会占用掉一个 block , 也表示boot sector 是独立于 superblock 外面的。
[root@www ~]# dumpe2fs /dev/hdc1
dumpe2fs 1.39 (29-May-2006)
Filesystem volume name: /boot
....(中间省略)....
First block: 1
Block size: 1024
....(中间省略)....
Group 0: (Blocks 1-8192)
Primary superblock at 1, Group descriptors at 2-2
Reserved GDT blocks at 3-258
Block bitmap at 259 (+258), Inode bitmap at 260 (+259)
Inode table at 261-511 (+260)
511 free blocks, 1991 free inodes, 2 directories
Free blocks: 5619-6129
Free inodes: 18-2008
看到最后一个特殊字体的地方吗? Group0 的 superblock 是由 1 号 block 开始的
上面结果可以发现 0 号 block 是保留下来留给 boot sector 用的
block 大于 1024 bytes (2K, 4K) 时:
如果 block 大于 1024 的话,那么 superblock 将会在 0 号!
[root@www ~]# dumpe2fs /dev/hdc2
dumpe2fs 1.39 (29-May-2006)
....(中间省略)....
Filesystem volume name: /1
....(中间省略)....
Block size: 4096
....(中间省略)....
Group 0: (Blocks 0-32767)
Primary superblock at 0, Group descriptors at 1-1
Reserved GDT blocks at 2-626
Block bitmap at 627 (+627), Inode bitmap at 628 (+628)
Inode table at 629-1641 (+629)
0 free blocks, 32405 free inodes, 2 directories
Free blocks:
Free inodes: 12-32416
可以发现 superblock 就在第一个 block (第 0 号) 上,但是 superblock 其实就只有 1024bytes
为了怕浪费更多空间,因此第一个 block 内就含有 boot sector 与 superblock
上面结果显示,因为每个 block 占有 4K ,但是 superblock 其实就只有 1024bytes
因此在第一个 block 内 superblock 仅占有 1024-2047 ( 由 0 号起算的话),而 0-1023 就保留给 boot sector 来使用。
而后面的2048bytes 的空间保留
现在也明白了为什麽df命令这麽快了吧,它是读取每个分区inode为0的superblock里面的信息,
而superblock里面就保存了分区文件系统类型、大小、已使用大小、可用大小
我们可以使用tune2fs命令查看某一分区的块大小等信息
tune2fs -l /dev/sdb1
tune2fs 1.41.12 (17-May-2010)
Filesystem volume name: <none>
Last mounted on: <not available>
Filesystem UUID: 4814e6f2-6550-4ac5-bf2d-33109fc53061
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_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: 65280
Block count: 261048
Reserved block count: 13052
Free blocks: 252525
Free inodes: 65269 First block: 0 Block size: 4096
Fragment size: 4096
Reserved GDT blocks: 63 Blocks per group: 32768
Fragments per group: 32768
Inodes per group: 8160
Inode blocks per group: 510
Flex block group size: 16 Filesystem created: Thu Jun 2