1. 使用如下命令创建一个1.45M的img文件并加载格式化
$dd if=/dev/zero of=1440.img bs=1k count=1440
$modprobe loop
$losetup /dev/loop0 1440.img
$mke2fs -t ext2 /dev/loop0 或 mke2fs -t ext2 1440.img
2. 使用dumpe2fs命令查看超级块和块组信息
$ dumpe2fs /dev/loop0
dumpe2fs 1.42.9 (4-Feb-2014)
Filesystem volume name: <none>
Last mounted on: <not available>
Filesystem UUID: 4ff6392f-b5b0-49d8-9908-50b45bdd668d
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: ext_attr resize_inode dir_index filetype sparse_super
Filesystem flags: signed_directory_hash
Default mount options: user_xattr acl
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 184
Block count: 1440
Reserved block count: 72
Free blocks: 1393
Free inodes: 173
First block: 1
Block size: 1024
Fragment size: 1024
Reserved GDT blocks: 5
Blocks per group: 8192
Fragments per group: 8192
Inodes per group: 184
Inode blocks per group: 23
Filesystem created: Fri Jun 25 13:25:36 2021
Last mount time: Fri Jun 25 13:32:04 2021
Last write time: Fri Jun 25 13:32:26 2021
Mount count: 1
Maximum mount count: -1
Last checked: Fri Jun 25 13:25:36 2021
Check interval: 0 (<none>)
Lifetime writes: 3 kB
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
Inode size: 128
Default directory hash: half_md4
Directory Hash Seed: 0297ad5d-9839-449d-b6a4-3c9c6629bbb1
Group 0: (Blocks 1-1439)
Primary superblock at 1, Group descriptors at 2-2
Reserved GDT blocks at 3-7
Block bitmap at 8 (+7), Inode bitmap at 9 (+8)
Inode table at 10-32 (+9)
1393 free blocks, 173 free inodes, 2 directories
Free blocks: 47-1439
Free inodes: 12-184
3. 超级块解析
00000400: b800 0000 a005 0000 4800 0000 7105 0000 ........H...q...
00000410: ad00 0000 0100 0000 0000 0000 0000 0000 ................
00000420: 0020 0000 0020 0000 b800 0000 546a d560 . ... ......Tj.`
00000430: 6a6a d560 0100 ffff 53ef 0100 0100 0000 jj.`....S.......
00000440: d068 d560 0000 0000 0000 0000 0100 0000 .h.`............
00000450: 0000 0000 0b00 0000 8000 0000 3800 0000 ............8...
00000460: 0200 0000 0100 0000 4ff6 392f b5b0 49d8 ........O.9/..I.
00000470: 9908 50b4 5bdd 668d 0000 0000 0000 0000 ..P.[.f.........
00000480: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000490: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000004a0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000004b0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000004c0: 0000 0000 0000 0000 0000 0000 0000 0500 ................
000004d0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000004e0: 0000 0000 0000 0000 0000 0000 0297 ad5d ...............]
000004f0: 9839 449d b6a4 3c9c 6629 bbb1 0100 0000 .9D...<.f)......
00000500: 0c00 0000 0000 0000 d068 d560 0000 0000 .........h.`....
......
000007f0: ....
struct ext2_super_block {
__le32 s_inodes_count; /* Inodes count */ 0000 00b8 = 184
__le32 s_blocks_count; /* Blocks count */ 0000 05a0 = 1440
__le32 s_r_blocks_count; /* Reserved blocks count */ 0000 0048 = 72
__le32 s_free_blocks_count; /* Free blocks count */ 0000 0571 = 1393
__le32 s_free_inodes_count; /* Free inodes count */ 0000 00ad = 173
__le32 s_first_data_block; /* First Data Block */ 0000 0001 = 1
__le32 s_log_block_size; /* Block size */ 0000 0000 = 0
__le32 s_log_frag_size; /* Fragment size */ 0000 0000 = 0
__le32 s_blocks_per_group; /* # Blocks per group */ 0000 2000 = 8192
__le32 s_frags_per_group; /* # Fragments per group */ 2000 = 8192
__le32 s_inodes_per_group; /* # Inodes per group */ 0000 00b8 = 184
__le32 s_mtime; /* Mount time */ 60d5 6a54
__le32 s_wtime; /* Write time */ 60d6 6a6a
__le16 s_mnt_count; /* Mount count */ 0001 = 1
__le16 s_max_mnt_count; /* Maximal mount count */ ffff = -1
__le16 s_magic; /* Magic signature */ ef53
__le16 s_state; /* File system state */ 0001
__le16 s_errors; /* Behaviour when detecting errors */ 0001
__le16 s_minor_rev_level; /* minor revision level */ 0000
__le32 s_lastcheck; /* time of last check */ 60d5 68d0
__le32 s_checkinterval; /* max. time between checks */ 0000 0000
__le32 s_creator_os; /* OS */ 0000 0000
__le32 s_rev_level; /* Revision level */ 0000 0001 = 1
__le16 s_def_resuid; /* Default uid for reserved blocks */ 0000
__le16 s_def_resgid; /* Default gid for reserved blocks */ 0000
__le32 s_first_ino; /* First non-reserved inode */ 0000 000b = 11
__le16 s_inode_size; /* size of inode structure */ 0080 = 128
__le16 s_block_group_nr; /* block group # of this superblock */ 0000
__le32 s_feature_compat; /* compatible feature set */ 0000 0038
__le32 s_feature_incompat; /* incompatible feature set */ 0000 0002
__le32 s_feature_ro_compat; /* readonly-compatible feature set */ 0000 0001
__u8 s_uuid[16]; /* 128-bit uuid for volume */ 4ff6.668d
char s_volume_name[16]; /* volume name */ 0000-0000
char s_last_mounted[64]; /* directory where last mounted */ 0000-0000 = from 488 - to 4c7
__le32 s_algorithm_usage_bitmap; /* For compression */ 0000 0000
__u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/ 00
__u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */ 00
__u16 s_padding1; 0005 = 5 (Reserved GDT blocks)?
__u8 s_journal_uuid[16]; /* uuid of journal superblock */ 0000.0000
__u32 s_journal_inum; /* inode number of journal file */ 0000 0000
__u32 s_journal_dev; /* device number of journal file */ 0000 0000
__u32 s_last_orphan; /* start of list of inodes to delete */ 0000 0002
__u32 s_hash_seed[4]; /* HTREE hash seed */ 0297.bbb1
__u8 s_def_hash_version; /* Default hash version to use */ 01
__u8 s_reserved_char_pad; 00
__u16 s_reserved_word_pad; 0000
__le32 s_default_mount_opts; 0000 000c = 12
__le32 s_first_meta_bg; /* First metablock block group */ 000 0000 = end at 507
__u32 s_reserved[190]; /* Padding to the end of the block */ = end at 7ff
};
4. 组描述解析
00000800: 0800 0000 0900 0000 0a00 0000 7105 ad00 ............q...
00000810: 0200 0400 0000 0000 0000 0000 0000 0000 ................
......
00000C00: ....
struct ext2_group_desc
{
__le32 bg_block_bitmap; /* Blocks bitmap block */ 0000 0008 = 8
__le32 bg_inode_bitmap; /* Inodes bitmap block */ 0000 0009 = 9
__le32 bg_inode_table; /* Inodes table block */ 0000 000a = 10
__le16 bg_free_blocks_count; /* Free blocks count */ 0571 = 1393
__le16 bg_free_inodes_count; /* Free inodes count */ 00ad = 173
__le16 bg_used_dirs_count; /* Directories count */ 0002 = 2
__le16 bg_pad; 0004
__le32 bg_reserved[3]; 0000.0000 = end at 81f
};
5. 块和Inode Bitmap
Blocks bitmap:
00002000: ffff ffff ff3f 0000 0000 0000 0000 0000 .....?..........
00002010: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00002020: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00002030: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00002040: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00002050: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00002060: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00002070: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00002080: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00002090: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000020a0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000020b0: 0000 0080 ffff ffff ffff ffff ffff ffff ................
000023ff: ....
Inodes bitmap:
00002400: ff07 0000 0000 0000 0000 0000 0000 0000 ................
00002410: 0000 0000 0000 00ff ffff ffff ffff ffff ................
000027ff: ....
6. Inodes表
dd if=1440.img of=1440_inode_table.bin bs=1K skip=10 count=1
00002800: 0000 0000 0000 0000 d068 d560 d068 d560 .........h.`.h.`
00002810: d068 d560 0000 0000 0000 0000 0000 0000 .h.`............
00002820: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00002830: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00002840: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00002850: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00002860: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00002870: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00002880: ed41 0000 0004 0000 566a d560 d068 d560 .A......Vj.`.h.`
00002890: d068 d560 0000 0000 0000 0300 0200 0000 .h.`............
000028a0: 0000 0000 0000 0000 2100 0000 0000 0000 ........!.......
000028b0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000028c0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000028d0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000028e0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000028f0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
第一个没有实际数据,以第二个inode结构为例(根目录)
struct ext2_inode {
__le16 i_mode; /* File mode */ 41ed (S_IFDIR)
__le16 i_uid; /* Low 16 bits of Owner Uid */ 0000
__le32 i_size; /* Size in bytes */ 0000 0400
__le32 i_atime; /* Access time */ 60d5 6a56
__le32 i_ctime; /* Creation time */ 60d5 68d0
__le32 i_mtime; /* Modification time */ 60d5 68d0
__le32 i_dtime; /* Deletion Time */ 0000 0000
__le16 i_gid; /* Low 16 bits of Group Id */ 0000
__le16 i_links_count; /* Links count */ 0003 = 3
__le32 i_blocks; /* Blocks count */ 0000 0002 = 2
__le32 i_flags; /* File flags */ 0000 0000 = start 28a0
union {
struct {
__le32 l_i_reserved1; 0000 0000
} linux1;
} osd1; /* OS dependent 1 */
__le32 i_block[EXT2_N_BLOCKS];/* Pointers to blocks */ 0021.0000 = from 28a8 - end 28e3
__le32 i_generation; /* File version (for NFS) */ 0000 0000
__le32 i_file_acl; /* File ACL */ 0000 0000
__le32 i_dir_acl; /* Directory ACL */ 0000 0000
__le32 i_faddr; /* Fragment address */ 0000 0000 = start 2870
union {
struct {
__u8 l_i_frag; /* Fragment number */ 00
__u8 l_i_fsize; /* Fragment size */ 00
__u16 i_pad1; 0000
__le16 l_i_uid_high; /* these 2 fields */ 0000
__le16 l_i_gid_high; /* were reserved2[0] */ 0000
__u32 l_i_reserved2; 0000 0000
} linux2;
} osd2; /* OS dependent 2 */
};
7. 根目录数据块
dd if=1440.img of=1440_root_data_block.bin bs=1K skip=33 count=1
00008400: 0200 0000 0c00 0102 2e00 0000 0200 0000 ................
00008410: 0c00 0202 2e2e 0000 0b00 0000 e803 0a02 ................
00008420: 6c6f 7374 2b66 6f75 6e64 0000 0000 0000 lost+found......
enum {
EXT2_FT_UNKNOWN = 0,
EXT2_FT_REG_FILE = 1,
EXT2_FT_DIR = 2,
EXT2_FT_CHRDEV = 3,
EXT2_FT_BLKDEV = 4,
EXT2_FT_FIFO = 5,
EXT2_FT_SOCK = 6,
EXT2_FT_SYMLINK = 7,
EXT2_FT_MAX
};
struct ext2_dir_entry_2 {
__le32 inode; /* Inode number */
__le16 rec_len; /* Directory entry length, 表示从rec_len字段末尾到下一个rec_len字段末尾的偏移量 */
__u8 name_len; /* Name length */
__u8 file_type;
char name[]; /* File name, up to EXT2_NAME_LEN */
};
0200 0000 0c00 0102 2e00 0000
struct ext2_dir_entry_2 {
__le32 inode; /* Inode number */ 0000 0002
__le16 rec_len; /* Directory entry length */ 000c
__u8 name_len; /* Name length */ 01
__u8 file_type; 02 = EXT2_FT_DIR
char name[]; /* File name, up to EXT2_NAME_LEN */ 2e = .
};
0200 0000 0c00 0202 2e2e 0000
struct ext2_dir_entry_2 {
__le32 inode; /* Inode number */ 0000 0002
__le16 rec_len; /* Directory entry length */ 000c
__u8 name_len; /* Name length */ 02
__u8 file_type; 02
char name[]; /* File name, up to EXT2_NAME_LEN */ 2e 2e = ..
};
0b00 0000 e803 0a02 6c6f 7374 2b66 6f75 6e64 0000
struct ext2_dir_entry_2 {
__le32 inode; /* Inode number */ 0000 000b
__le16 rec_len; /* Directory entry length */ 03e8
__u8 name_len; /* Name length */ 0a
__u8 file_type; 02
char name[]; /* File name, up to EXT2_NAME_LEN */ = lost+found
};