一 基本概念
inode: 索引节点
superblock: 超级块
block: 文件系统块
block group: 文件系统块组
disk block: 磁盘块(512字节)
block device: 块设备
二 工具
block块位图
这个就是一个块使用情况记录表。记录哪些块使用,哪些块未使用。
它的原理就是对整个块组中0-32767这总共32768个块中作一个映射。
根据一个bytes有8个位00000000,一个块有4096bytes也就是有4096*8=32768个位,
这32768个位刚好对应了块组中32768的块。如果第N个块被使用了则标记第N位为1,否则为0。
推算出一个块组 32768*blockszie(4k) = 128M
inode位图
和上面的块位图一样,这个是inode的使用情况记录表。由超级块基本信息可以看到每个块组有8128个inode,
这里对inode的映射原理和块位图也是一样,只不过没有用满一个块。
inode表
inode表就是具体存放inode信息的地方。在ext4中,inode的大小为256字节(ext2/3中仅有它的一半,128字节),
一个块可以存放16个inode,由于一个块组有8128 个inode,总共需要8128/16=508个块存放inode表。这个值可以在超级块基本信息中的Inode blocks per group中看到。
dumpe2fs /tmp/unsparse_system-SpgENC.img
dumpe2fs 1.42 (29-Nov-2011)
Filesystem volume name:
Last mounted on:
Filesystem UUID: 57f8f4bc-abf4-655f-bf67-946fc0f9f25b
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode filetype extent sparse_super large_file uninit_bg
Filesystem flags: unsigned_directory_hash
Default mount options: (none)
Filesystem state: clean
Errors behavior: Remount read-only
Filesystem OS type: Linux
Inode count: 98304
Block count: 393216
Reserved block count: 0
Free blocks: 379875
Free inodes: 97907
First block: 0
Block size: 4096
Fragment size: 4096
Reserved GDT blocks: 95
Blocks per group: 32768 (4096*8)
Fragments per group: 32768
Inodes per group: 8192
Inode blocks per group: 512
Last mount time: n/a
Last write time: Thu Jan 1 08:00:00 1970
Mount count: 0
Maximum mount count: -1
Last checked: Thu Jan 1 08:00:00 1970
Check interval: 0 ()
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
Inode size: 256
Required extra isize: 28
Desired extra isize: 28
Journal inode: 8
Default directory hash: tea
Journal backup: inode blocks
Journal features: (none)
Journal size: 24M
Journal length: 6144
Journal sequence: 0x00000001
Journal start: 0
Group 0: (Blocks 0-32767)
Checksum 0x2f75, unused inodes 0
Primary superblock at 0, Group descriptors at 1-1
Reserved GDT blocks at 2-96
Block bitmap at 97 (+97), Inode bitmap at 98 (+98)
Inode table at 99-610 (+99)
25566 free blocks, 7795 free inodes, 65 directories
Free blocks: 7202-32767
Free inodes: 398-8192
Group 1: (Blocks 32768-65535) [INODE_UNINIT]
Checksum 0xb1af, unused inodes 0
Backup superblock at 32768, Group descriptors at 32769-32769
Reserved GDT blocks at 32770-32864
Block bitmap at 32865 (+97), Inode bitmap at 32866 (+98)
Inode table at 32867-33378 (+99)
32157 free blocks, 8192 free inodes, 0 directories
Free blocks: 33379-65535
Free inodes: 8193-16384
三 python 流程
1.add_img_to_target_files.py build_image.py
|1. main |
|2. AddImagesToTargetFiles |
|3. AddSystem |
|4. BuildSystem |
|5. CreateImage------------------------->|6.BuildImage
| | mkuserimg.sh 生成spare.img
| | UnsparseImage 生成 unspare.img Running simg2img
| | e2fsck 检查unspare.img 的完成性
| | Running: e2fsck -f -n /tmp/unsparse_system-SpgENC.img
| | OK 删除 unsparse_sysstem.img
| return spare.img(fn)<------------ |
| |
|7. zip to targetfile
阅读(1279) | 评论(0) | 转发(0) |