星空网 > 软件开发 > 操作系统

分区里的inode号是0号和1号的block

分区里的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 /boot2 /boot

 

可以看到,无论是哪个分区,它的inode值都是2,而不是0,也不是1

并且当你用find命令来搜索一下0或1号inode的时候也是什么也找不到

 find / -inum 0find: `/proc/1461/task/1461/fd/5': No such file or directoryfind: `/proc/1461/task/1461/fdinfo/5': No such file or directoryfind: `/proc/1461/fd/5': No such file or directoryfind: `/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/hdc1dumpe2fs 1.39 (29-May-2006)Filesystem volume name:  /boot....(中间省略)....First block:       1Block 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 用的

分区里的inode号是0号和1号的blockimages/loading.gif' data-original="http://images2015.cnblogs.com/blog/257159/201606/257159-20160602103506992-822489449.jpg" />

 

block 大于 1024 bytes (2K, 4K) 时:

如果 block 大于 1024 的话,那么 superblock 将会在 0 号!

[root@www ~]# dumpe2fs /dev/hdc2dumpe2fs 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-1Reserved GDT blocks at 2-626Block bitmap at 627 (+627), Inode bitmap at 628 (+628)Inode table at 629-1641 (+629)0 free blocks, 32405 free inodes, 2 directoriesFree 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 的空间保留

分区里的inode号是0号和1号的block

 

 

现在也明白了为什麽df命令这麽快了吧,它是读取每个分区inode为0的superblock里面的信息,

而superblock里面就保存了分区文件系统类型、大小、已使用大小、可用大小

分区里的inode号是0号和1号的block

 

 

 

 

我们可以使用tune2fs命令查看某一分区的块大小等信息

tune2fs -l /dev/sdb1tune2fs 1.41.12 (17-May-2010)Filesystem volume name:  <none>Last mounted on:     <not available>Filesystem UUID:     4814e6f2-6550-4ac5-bf2d-33109fc53061Filesystem magic number: 0xEF53Filesystem 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_isizeFilesystem flags:     signed_directory_hash Default mount options:  (none)Filesystem state:     cleanErrors behavior:     ContinueFilesystem OS type:    LinuxInode count:       65280Block count:       261048Reserved block count:   13052Free blocks:       252525Free inodes:       65269First block:       0Block size:        4096Fragment size:      4096Reserved GDT blocks:   63Blocks per group:     32768Fragments per group:   32768Inodes per group:     8160Inode blocks per group:  510Flex block group size:  16Filesystem created:    Thu Jun 2 12:23:23 2016Last mount time:     Thu Jun 2 12:24:06 2016Last write time:     Thu Jun 2 12:24:06 2016Mount count:       1Maximum mount count:   20Last checked:       Thu Jun 2 12:23:23 2016Check interval:      15552000 (6 months)Next check after:     Tue Nov 29 12:23:23 2016Lifetime writes:     32 MBReserved blocks uid:   0 (user root)Reserved blocks gid:   0 (group root)First inode:       11Inode size:       256Required extra isize:   28Desired extra isize:   28Journal inode:      8Default directory hash:  half_md4Directory Hash Seed:   fad5ad24-52ef-482c-a54b-367a5bb4f122Journal backup:      inode blocks

 

通过上面的信息就可以知道superblock是在block 0还是block 1

那么上面的信息又是从哪里读取出来的

答案是:还是superblock

 

superblock如此重要,所以系统也对superblock做了一些保护措施

文件系统会有一些备用超级块,备用超级块一般创建于块 8193、16384 或 32768

ext类文件系统会把block分区一组一组来管理,可以看到Blocks per group这一行,就是每个group都包含了32768个block

每个group都会有一个备用superblock,所以备用超级块一般创建于块 8193、16384 或 32768,根据格式化时的block size而定

tune2fs -l /dev/sda4 |grep group
Blocks per group: 32768
Fragments per group: 32768
Inodes per group: 8192
Inode blocks per group: 512
Flex block group size: 16
Reserved blocks gid: 0 (group root)

 

 

注意:非ext类文件系统是不能用tune2fs命令的,而且原理和内部格式跟ext类文件系统不相同!!

tune2fs -l /dev/sdb1tune2fs 1.41.12 (17-May-2010)tune2fs: Bad magic number in super-block while trying to open /dev/sdb1Couldn't find valid filesystem superblock.

 

 

 

以上内容针对于ext类文件系统,不对的地方欢迎拍砖

部分参考了鸟哥文章:http://vbird.dic.ksu.edu.tw/linux_basic/0230filesystem_6.php




原标题:分区里的inode号是0号和1号的block

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流