用dd修复ext3的superblock

一个磁盘分区上的ext3 filesystem

linux-d4xo:~ # dumpe2fs /dev/sdc1 | grep -i superblock
dumpe2fs 1.42.11 (09-Jul-2014)
Primary superblock at 0, Group descriptors at 1-1
Backup superblock at 32768, Group descriptors at 32769-32769
Backup superblock at 98304, Group descriptors at 98305-98305
Backup superblock at 163840, Group descriptors at 163841-163841
Backup superblock at 229376, Group descriptors at 229377-229377
Backup superblock at 294912, Group descriptors at 294913-294913
Backup superblock at 819200, Group descriptors at 819201-819201
Backup superblock at 884736, Group descriptors at 884737-884737
Backup superblock at 1605632, Group descriptors at 1605633-1605633
linux-d4xo:~ # ls /mnt
linux-d4xo:~ # mkdir /mnt/test
linux-d4xo:~ # mount /dev/sdc1 /mnt/test
linux-d4xo:~ # mount | grep sdc
/dev/sdc1 on /mnt/test type ext3 (rw,relatime,data=ordered)
linux-d4xo:~ # umount /dev/sdc1

部分dumpe2fs/dev/sdc1 的输出 blocksize 4096

linux-d4xo:~ # dumpe2fs /dev/sdc1 | more
dumpe2fs 1.42.11 (09-Jul-2014)
Filesystem volume name:
Last mounted on:
Filesystem UUID: 735aefe6-012d-4184-bb17-7e4027020d40
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype sparse_super large_file
Filesystem flags: signed_directory_hash
Default mount options: user_xattr acl
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 655360
Block count: 2621184
Reserved block count: 131059
Free blocks: 2541488
Free inodes: 655349
First block: 0
Block size: 4096
Fragment size: 4096
Reserved GDT blocks: 639
Blocks per group: 32768
Fragments per group: 32768
Inodes per group: 8192
Inode blocks per group: 512
Filesystem created: Mon Oct 28 22:09:54 2019
Last mount time: Mon Oct 28 22:10:45 2019
Last write time: Wed Oct 30 23:15:55 2019
Mount count: 1
Maximum mount count: -1
Last checked: Mon Oct 28 22:09:54 2019
Check interval: 0 ()
Lifetime writes: 44 kB
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: half_md4
Directory Hash Seed: 95f7038e-6b3b-4260-a8a4-9dbd0f2a42b1
Journal backup: inode blocks
Journal features: (none)
Journal size: 128M
Journal length: 32768
Journal sequence: 0x00000005
Journal start: 0

Group 0: (Blocks 0-32767)
Primary superblock at 0, Group descriptors at 1-1
Reserved GDT blocks at 2-640
Block bitmap at 641 (+641), Inode bitmap at 642 (+642)
Inode table at 643-1154 (+643)
31607 free blocks, 8181 free inodes, 2 directories
Free blocks: 1161-32767
Free inodes: 12-8192
Group 1: (Blocks 32768-65535)
Backup superblock at 32768, Group descriptors at 32769-32769
Reserved GDT blocks at 32770-33408
Block bitmap at 33409 (+641), Inode bitmap at 33410 (+642)
Inode table at 33411-33922 (+643)
31613 free blocks, 8192 free inodes, 0 directories
Free blocks: 33923-65535
Free inodes: 8193-16384
Group 2: (Blocks 65536-98303)
Block bitmap at 65536 (+0), Inode bitmap at 65537 (+1)
Inode table at 65538-66049 (+2)
32254 free blocks, 8192 free inodes, 0 directories
Free blocks: 66050-98303
Free inodes: 16385-24576
Group 3: (Blocks 98304-131071)
Backup superblock at 98304, Group descriptors at 98305-98305
Reserved GDT blocks at 98306-98944
Block bitmap at 98945 (+641), Inode bitmap at 98946 (+642)
Inode table at 98947-99458 (+643)
31613 free blocks, 8192 free inodes, 0 directories
Free blocks: 99459-131071
Free inodes: 24577-32768

ext2_super_block 和ext4_super_block数据结构的前部是一样的,大小都是1024字节

crash> struct -x -o ext4_super_block
struct ext4_super_block {
[0x0] __le32 s_inodes_count;
[0x4] __le32 s_blocks_count_lo;
[0x8] __le32 s_r_blocks_count_lo;
[0xc] __le32 s_free_blocks_count_lo;
[0x10] __le32 s_free_inodes_count;
[0x14] __le32 s_first_data_block;
[0x18] __le32 s_log_block_size;
[0x1c] __le32 s_log_cluster_size;
[0x20] __le32 s_blocks_per_group;
[0x24] __le32 s_clusters_per_group;
[0x28] __le32 s_inodes_per_group;
[0x2c] __le32 s_mtime;
[0x30] __le32 s_wtime;
[0x34] __le16 s_mnt_count;
[0x36] __le16 s_max_mnt_count;
[0x38] __le16 s_magic;
[0x3a] __le16 s_state;
[0x3c] __le16 s_errors;
[0x3e] __le16 s_minor_rev_level;
[0x40] __le32 s_lastcheck;
[0x44] __le32 s_checkinterval;
[0x48] __le32 s_creator_os;
[0x4c] __le32 s_rev_level;
[0x50] __le16 s_def_resuid;
[0x52] __le16 s_def_resgid;
[0x54] __le32 s_first_ino;
[0x58] __le16 s_inode_size;
[0x5a] __le16 s_block_group_nr;
[0x5c] __le32 s_feature_compat;
[0x60] __le32 s_feature_incompat;
[0x64] __le32 s_feature_ro_compat;
[0x68] __u8 s_uuid[16];
[0x78] char s_volume_name[16];
[0x88] char s_last_mounted[64];
[0xc8] __le32 s_algorithm_usage_bitmap;
[0xcc] __u8 s_prealloc_blocks;
[0xcd] __u8 s_prealloc_dir_blocks;
[0xce] __le16 s_reserved_gdt_blocks;
[0xd0] __u8 s_journal_uuid[16];
[0xe0] __le32 s_journal_inum;
[0xe4] __le32 s_journal_dev;
[0xe8] __le32 s_last_orphan;
[0xec] __le32 s_hash_seed[4];
[0xfc] __u8 s_def_hash_version;
[0xfd] __u8 s_jnl_backup_type;
[0xfe] __le16 s_desc_size;
[0x100] __le32 s_default_mount_opts;
[0x104] __le32 s_first_meta_bg;
[0x108] __le32 s_mkfs_time;
[0x3fc] __le32 s_checksum;
}
SIZE: 0x400

struct ext2_super_block {
__le32 s_inodes_count; /* Inodes count /
__le32 s_blocks_count; /
Blocks count /
__le32 s_r_blocks_count; /
Reserved blocks count /
__le32 s_free_blocks_count; /
Free blocks count /
__le32 s_free_inodes_count; /
Free inodes count /
__le32 s_first_data_block; /
First Data Block /
__le32 s_log_block_size; /
Block size /
__le32 s_log_frag_size; /
Fragment size /
__le32 s_blocks_per_group; /
# Blocks per group /
__le32 s_frags_per_group; /
# Fragments per group /
__le32 s_inodes_per_group; /
# Inodes per group /
__le32 s_mtime; /
Mount time /
__le32 s_wtime; /
Write time /
__le16 s_mnt_count; /
Mount count /
__le16 s_max_mnt_count; /
Maximal mount count /
__le16 s_magic; /
Magic signature /
__le16 s_state; /
File system state /
__le16 s_errors; /
Behaviour when detecting errors /
__le16 s_minor_rev_level; /
minor revision level /
__le32 s_lastcheck; /
time of last check /
__le32 s_checkinterval; /
max. time between checks /
__le32 s_creator_os; /
OS /
__le32 s_rev_level; /
Revision level /
__le16 s_def_resuid; /
Default uid for reserved blocks /
__le16 s_def_resgid; /
Default gid for reserved blocks /
__le32 s_first_ino; /
First non-reserved inode /
__le16 s_inode_size; /
size of inode structure /
__le16 s_block_group_nr; /
block group # of this superblock /
__le32 s_feature_compat; /
compatible feature set /
__le32 s_feature_incompat; /
incompatible feature set /
__le32 s_feature_ro_compat; /
readonly-compatible feature set /
__u8 s_uuid[16]; /
128-bit uuid for volume /
char s_volume_name[16]; /
volume name /
char s_last_mounted[64]; /
directory where last mounted /
__le32 s_algorithm_usage_bitmap; /
For compression /
__u8 s_prealloc_blocks; /
Nr of blocks to try to preallocate*/
__u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs /
__u16 s_padding1;
__u8 s_journal_uuid[16]; /
uuid of journal superblock /
__u32 s_journal_inum; /
inode number of journal file /
__u32 s_journal_dev; /
device number of journal file /
__u32 s_last_orphan; /
start of list of inodes to delete /
__u32 s_hash_seed[4]; /
HTREE hash seed /
__u8 s_def_hash_version; /
Default hash version to use /
__u8 s_reserved_char_pad;
__u16 s_reserved_word_pad;
__le32 s_default_mount_opts;
__le32 s_first_meta_bg; /
First metablock block group /
__u32 s_reserved[190]; /
Padding to the end of the block */
};

debugfs 中找到对应的superblock 数据,

block 0 是从偏移量1024开始的1024个字节(第一列的数字除2才是字节偏移量)
block 32768 和98304都是从偏移量0 开始的1024个字节

linux-d4xo:~ # debugfs /dev/sdc1
debugfs 1.42.11 (09-Jul-2014)
debugfs: block_dump 0
0000 0000 0000 0000 0000 0000 0000 0000 0000 …
*
2000 0000 0a00 00ff 2700 f3ff 0100 b0c7 2600 …’…&.
2020 f5ff 0900 0000 0000 0200 0000 0200 0000 …
2040 0080 0000 0080 0000 0020 0000 a2a5 305e … …0^
2060 b5a5 305e 0200 ffff 53ef 0100 0100 0000 …0^…S…
2100 729f b75d 0000 0000 0000 0000 0100 0000 r…]…
2120 0000 0000 0b00 0000 0001 0000 3c00 0000 …<…
2140 0200 0000 0300 0000 735a efe6 012d 4184 …sZ…-A.
2160 bb17 7e40 2702 0d40 0000 0000 0000 0000 …~@’…@…
2200 0000 0000 0000 0000 0000 0000 0000 0000 …
*
2300 0000 0000 0000 0000 0000 0000 0000 7f02 …
2320 0000 0000 0000 0000 0000 0000 0000 0000 …
2340 0800 0000 0000 0000 0000 0000 95f7 038e …
2360 6b3b 4260 a8a4 9dbd 0f2a 42b1 0101 0000 k;B`…*B…
2400 0c00 0000 0000 0000 729f b75d 0202 1300 …r…]…
2420 0302 1300 0402 1300 0502 1300 0602 1300 …
2440 0702 1300 0802 1300 0902 1300 0a02 1300 …
2460 0b02 1300 0c02 1300 0d02 1300 0e02 1300 …
2500 0f06 1300 0000 0000 0000 0000 0000 0008 …
2520 0000 0000 0000 0000 0000 0000 1c00 1c00 …
2540 0100 0000 0000 0000 0000 0000 0000 0000 …
2560 0000 0000 0000 0000 3000 0000 0000 0000 …0…
2600 0000 0000 0000 0000 0000 0000 0000 0000 …
*

debugfs: block_dump 32768
0000 0000 0a00 00ff 2700 f3ff 0100 b0c7 2600 …’…&.
0020 f5ff 0900 0000 0000 0200 0000 0200 0000 …
0040 0080 0000 0080 0000 0020 0000 0000 0000 … …
0060 729f b75d 0000 ffff 53ef 0000 0100 0000 r…]…S…
0100 729f b75d 0000 0000 0000 0000 0100 0000 r…]…
0120 0000 0000 0b00 0000 0001 0100 3c00 0000 …<…
0140 0200 0000 0300 0000 735a efe6 012d 4184 …sZ…-A.
0160 bb17 7e40 2702 0d40 0000 0000 0000 0000 …~@’…@…
0200 0000 0000 0000 0000 0000 0000 0000 0000 …
*
0300 0000 0000 0000 0000 0000 0000 0000 7f02 …
0320 0000 0000 0000 0000 0000 0000 0000 0000 …
0340 0800 0000 0000 0000 0000 0000 95f7 038e …
0360 6b3b 4260 a8a4 9dbd 0f2a 42b1 0101 0000 k;B`…*B…
0400 0c00 0000 0000 0000 729f b75d 0202 1300 …r…]…
0420 0302 1300 0402 1300 0502 1300 0602 1300 …
0440 0702 1300 0802 1300 0902 1300 0a02 1300 …
0460 0b02 1300 0c02 1300 0d02 1300 0e02 1300 …
0500 0f06 1300 0000 0000 0000 0000 0000 0008 …
0520 0000 0000 0000 0000 0000 0000 1c00 1c00 …
0540 0100 0000 0000 0000 0000 0000 0000 0000 …
0560 0000 0000 0000 0000 0000 0000 0000 0000 …
*

debugfs: block_dump 98304
0000 0000 0a00 00ff 2700 f3ff 0100 b0c7 2600 …’…&.
0020 f5ff 0900 0000 0000 0200 0000 0200 0000 …
0040 0080 0000 0080 0000 0020 0000 0000 0000 … …
0060 729f b75d 0000 ffff 53ef 0000 0100 0000 r…]…S…
0100 729f b75d 0000 0000 0000 0000 0100 0000 r…]…
0120 0000 0000 0b00 0000 0001 0300 3c00 0000 …<…
0140 0200 0000 0300 0000 735a efe6 012d 4184 …sZ…-A.
0160 bb17 7e40 2702 0d40 0000 0000 0000 0000 …~@’…@…
0200 0000 0000 0000 0000 0000 0000 0000 0000 …
*
0300 0000 0000 0000 0000 0000 0000 0000 7f02 …
0320 0000 0000 0000 0000 0000 0000 0000 0000 …
0340 0800 0000 0000 0000 0000 0000 95f7 038e …
0360 6b3b 4260 a8a4 9dbd 0f2a 42b1 0101 0000 k;B`…*B…
0400 0c00 0000 0000 0000 729f b75d 0202 1300 …r…]…
0420 0302 1300 0402 1300 0502 1300 0602 1300 …
0440 0702 1300 0802 1300 0902 1300 0a02 1300 …
0460 0b02 1300 0c02 1300 0d02 1300 0e02 1300 …
0500 0f06 1300 0000 0000 0000 0000 0000 0008 …
0520 0000 0000 0000 0000 0000 0000 1c00 1c00 …
0540 0100 0000 0000 0000 0000 0000 0000 0000 …
0560 0000 0000 0000 0000 0000 0000 0000 0000 …
*

dd 命令及参数

linux-d4xo:~ # dd if=/dev/sdc1 bs=4096 of=/root/sdc1_blk0 count=1 skip=0 iflag=direct oflag=direct conv=sync
1+0 records in
1+0 records out
4096 bytes (4.1 kB, 4.0 KiB) copied, 0.000881506 s, 4.6 MB/s
linux-d4xo:~ # rm /root/sdc1_blk*
linux-d4xo:~ # dd if=/dev/sdc1 bs=4096 of=/root/sdc1_blk0 count=1 skip=0 iflag=direct oflag=direct conv=sync
1+0 records in
1+0 records out
4096 bytes (4.1 kB, 4.0 KiB) copied, 0.000496754 s, 8.2 MB/s
linux-d4xo:~ # dd if=/dev/sdc1 bs=4096 of=/root/sdc1_blk32768 count=1 skip=32768 iflag=direct oflag=direct conv=sync
1+0 records in
1+0 records out
4096 bytes (4.1 kB, 4.0 KiB) copied, 0.000868856 s, 4.7 MB/s
linux-d4xo:~ # dd if=/dev/sdc1 bs=4096 of=/root/sdc1_blk98304 count=1 skip=98304 iflag=direct oflag=direct conv=sync
1+0 records in
1+0 records out
4096 bytes (4.1 kB, 4.0 KiB) copied, 0.000846853 s, 4.8 MB/s
linux-d4xo:~ # dd if=/root/sdc1_blk0 bs=1024 of=/root/sdc1_blk0_1024 count=1 skip=1
1+0 records in
1+0 records out
1024 bytes (1.0 kB, 1.0 KiB) copied, 0.000616964 s, 1.7 MB/s
linux-d4xo:~ # dd if=/root/sdc1_blk32768 bs=1024 of=/root/sdc1_blk32768_0 count=1 skip=0
1+0 records in
1+0 records out
1024 bytes (1.0 kB, 1.0 KiB) copied, 0.000744035 s, 1.4 MB/s
linux-d4xo:~ # dd if=/root/sdc1_blk98304 bs=1024 of=/root/sdc1_blk98304_0 count=1 skip=0
1+0 records in
1+0 records out
1024 bytes (1.0 kB, 1.0 KiB) copied, 0.000442559 s, 2.3 MB/s
linux-d4xo:~ # md5sum /root/sdc1_blk*
df5611a615bc02f1038f309c575389e8 /root/sdc1_blk0
63b990dffd8cfd4d9018557594cc653b /root/sdc1_blk0_1024
e428c7903de5a8d6fe8f5801a2ae1e3f /root/sdc1_blk32768
8908a64237422d5901f20b7bce3c36c5 /root/sdc1_blk32768_0
4520336c4dc6f0c5a4054b32571c65dd /root/sdc1_blk98304
66dfb930d7c4109549f9551dde6a0ebc /root/sdc1_blk98304_0

每个文件的MD5都不一样

比较superblock内容

备用superblock只有[0x5a] __le16 s_block_group_nr这一点不同

primary 多出来一些其他信息不同。

linux-d4xo:~ # hexdump -x /root/sdc1_blk98304_0 >/root/sdc1_blk98304_0.txt
linux-d4xo:~ # hexdump -x /root/sdc1_blk0_1024
0000000    0000    000a    ff00    0027    fff3    0001    c7b0    0026
0000010    fff5    0009    0000    0000    0002    0000    0002    0000
0000020    8000    0000    8000    0000    2000    0000    a5a2    5e30
0000030    a5b5    5e30    0002    ffff    ef53    0001    0001    0000
0000040    9f72    5db7    0000    0000    0000    0000    0001    0000
0000050    0000    0000    000b    0000    0100    0000    003c    0000
0000060    0002    0000    0003    0000    5a73    e6ef    2d01    8441
0000070    17bb    407e    0227    400d    0000    0000    0000    0000
0000080    0000    0000    0000    0000    0000    0000    0000    0000
*
00000c0    0000    0000    0000    0000    0000    0000    0000    027f
00000d0    0000    0000    0000    0000    0000    0000    0000    0000
00000e0    0008    0000    0000    0000    0000    0000    f795    8e03
00000f0    3b6b    6042    a4a8    bd9d    2a0f    b142    0101    0000
0000100    000c    0000    0000    0000    9f72    5db7    0202    0013
0000110    0203    0013    0204    0013    0205    0013    0206    0013
0000120    0207    0013    0208    0013    0209    0013    020a    0013
0000130    020b    0013    020c    0013    020d    0013    020e    0013
0000140    060f    0013    0000    0000    0000    0000    0000    0800
0000150    0000    0000    0000    0000    0000    0000    001c    001c
0000160    0001    0000    0000    0000    0000    0000    0000    0000
0000170    0000    0000    0000    0000    0030    0000    0000    0000
0000180    0000    0000    0000    0000    0000    0000    0000    0000
*
0000400
linux-d4xo:~ # hexdump -x /root/sdc1_blk0_1024 > /root/sdc1_blk0_1024.txt
linux-d4xo:~ # diff /root/sdc1_blk0_1024.txt /root/sdc1_blk98304_0.txt
3,4c3,4
< 0000020    8000    0000    8000    0000    2000    0000    a5a2    5e30
< 0000030    a5b5    5e30    0002    ffff    ef53    0001    0001    0000
---
> 0000020    8000    0000    8000    0000    2000    0000    0000    0000
> 0000030    9f72    5db7    0000    ffff    ef53    0000    0001    0000
6c6
< 0000050    0000    0000    000b    0000    0100    0000    003c    0000
---
> 0000050    0000    0000    000b    0000    0100    0003    003c    0000
22,23c22
< 0000170    0000    0000    0000    0000    0030    0000    0000    0000
< 0000180    0000    0000    0000    0000    0000    0000    0000    0000
---
> 0000170    0000    0000    0000    0000    0000    0000    0000    0000
linux-d4xo:~ # hexdump -x /root/sdc1_blk32768_0 >/root/sdc1_blk32768_0.txt
linux-d4xo:~ # diff /root/sdc1_blk32768_0.txt /root/sdc1_blk98304_0.txt
6c6
< 0000050    0000    0000    000b    0000    0100    0001    003c    0000
---
> 0000050    0000    0000    000b    0000    0100    0003    003c    0000

尝试覆盖primary

读备份的1024字节,写入sdc1,偏移量1个1024(seek=1),大小一个1024字节(count=1)
linux-d4xo:~ # dd if=/root/sdc1_blk32768_0 bs=1024 of=/dev/sdc1 count=1 seek=1 iflag=direct oflag=direct conv=sync
1+0 records in
1+0 records out
1024 bytes (1.0 kB, 1.0 KiB) copied, 0.00127753 s, 802 kB/s

linux-d4xo:~ # dd if=/dev/sdc1 bs=1024 of=/root/sdc1_blk0_1024_after_change count=1 skip=1 iflag=direct oflag=direct conv=sync
1+0 records in
1+0 records out
1024 bytes (1.0 kB, 1.0 KiB) copied, 0.000440939 s, 2.3 MB/s
linux-d4xo:~ # md5 /root/sdc1_blk0
sdc1_blk0 sdc1_blk0_1024 sdc1_blk0_1024.txt sdc1_blk0_1024_after_change
linux-d4xo:~ # md5sum /root/sdc1_blk0_1024 /root/sdc1_blk0_1024_after_change /root/sdc1_blk32768_0
63b990dffd8cfd4d9018557594cc653b /root/sdc1_blk0_1024
8908a64237422d5901f20b7bce3c36c5 /root/sdc1_blk0_1024_after_change 《《《《 same as below
8908a64237422d5901f20b7bce3c36c5 /root/sdc1_blk32768_0 《《《《

reboot后再次检查,主要是时间做了更新 by fsck and mount.

linux-d4xo:~ # lsblk -f
NAME   FSTYPE LABEL UUID                                 MOUNTPOINT
sda
├─sda1 swap         1cdf6a9a-b731-4756-9dd1-dabbb13222a5 [SWAP]
└─sda2 btrfs        afb9d818-1917-4c23-8a63-06e73b4f89cd /var/lib/mysql
sdb
└─sdb1 swap         b5a34fa3-1431-45b5-98ff-88f63c26c24c
sdc
└─sdc1 ext3         735aefe6-012d-4184-bb17-7e4027020d40
sr0
linux-d4xo:~ # fsck.ext3 /dev/sdc1
e2fsck 1.42.11 (09-Jul-2014)
/dev/sdc1 was not cleanly unmounted, check forced.
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sdc1: 11/655360 files (0.0% non-contiguous), 79696/2621184 blocks
linux-d4xo:~ # dumpe2fs /dev/sdc1 | more
dumpe2fs 1.42.11 (09-Jul-2014)

... ...
Last mount time:          Tue Jan 28 17:48:27 2020
Last write time:          Tue Jan 28 17:51:14 2020
Mount count:              0
Maximum mount count:      -1
Last checked:             Tue Jan 28 17:51:14 2020
... ...

linux-d4xo:~ # dd if=/dev/sdc1 bs=1024 of=/root/sdc1_blk0_1024_after_change_then_reboot count=1 skip=1 iflag=direct oflag=direct conv=sync
1+0 records in
1+0 records out
1024 bytes (1.0 kB, 1.0 KiB) copied, 0.000497444 s, 2.1 MB/s
linux-d4xo:~ # md5sum /root/sdc1_blk0*
df5611a615bc02f1038f309c575389e8  /root/sdc1_blk0
63b990dffd8cfd4d9018557594cc653b  /root/sdc1_blk0_1024
0efab5f5192928017991d0f273cb6337  /root/sdc1_blk0_1024.txt
8908a64237422d5901f20b7bce3c36c5  /root/sdc1_blk0_1024_after_change
151fa2d0e5846ca3380463f66895c6ae  /root/sdc1_blk0_1024_after_change_then_reboot
linux-d4xo:~ # hexdump -x /root/sdc1_blk0_1024_after_change_then_reboot >/root/sdc1_blk0_1024_after_change_then_reboot.txt
linux-d4xo:~ # diff /root/sdc1_blk0_1024.txt /root/sdc1_blk0_1024_after_change_then_reboot.txt
3,5c3,5
< 0000020    8000    0000    8000    0000    2000    0000    a5a2    5e30
< 0000030    a5b5    5e30    0002    ffff    ef53    0001    0001    0000
< 0000040    9f72    5db7    0000    0000    0000    0000    0001    0000
---
> 0000020    8000    0000    8000    0000    2000    0000    ba3b    5e30
> 0000030    bae2    5e30    0000    ffff    ef53    0001    0001    0000
> 0000040    bae2    5e30    0000    0000    0000    0000    0001    0000
22c22
< 0000170    0000    0000    0000    0000    0030    0000    0000    0000
---
> 0000170    0000    0000    0000    0000    0008    0000    0000    0000

总结:

用dd将备用的superblock覆盖prinary superblock是可行的。

从block number 32768读出备份superblock,保存到文件

dd if=/dev/sdc1 bs=4096 of=/root/sdc1_blk32768 count=1 skip=32768 iflag=direct oflag=direct conv=sync
dd if=/root/sdc1_blk32768 bs=1024 of=/root/sdc1_blk32768_0 count=1 skip=0

可选,修改s_block_group_nr, 偏移量0x5a, 改为0.

vim /root/sdc1_blk32768_0
:%!xxd -g 1
:%!xxd -r
:wq

写到primary superblock

dd if=/root/sdc1_blk32768_0 bs=1024 of=/dev/sdc1 count=1 seek=1 iflag=direct oflag=direct conv=sync

经验证同样适用于lv上的文件系统, primary superblock位于同样的偏移1024字节的位置

linux-d4xo:~ # debugfs /dev/vg1/lv1
debugfs 1.42.11 (09-Jul-2014)
debugfs: block_dump 0
0000 0000 0000 0000 0000 0000 0000 0000 0000 …
*
2000 0000 0a00 0000 2800 0000 0200 b0c8 2600 …(…&.
2020 f5ff 0900 0000 0000 0200 0000 0200 0000 …
2040 0080 0000 0080 0000 0020 0000 0000 0000 … …
2060 dbc6 305e 0000 ffff 53ef 0100 0100 0000 …0^…S…
2100 d6c6 305e 0000 0000 0000 0000 0100 0000 …0^…
2120 0000 0000 0b00 0000 0001 0000 3c00 0000 …<…
2140 0200 0000 0300 0000 410e a980 48d6 495a …A…H.IZ
2160 a7b0 2255 24c0 82c9 0000 0000 0000 0000 …"U$…
2200 0000 0000 0000 0000 0000 0000 0000 0000 …
*
2300 0000 0000 0000 0000 0000 0000 0000 7f02 …
2320 0000 0000 0000 0000 0000 0000 0000 0000 …
2340 0800 0000 0000 0000 0000 0000 6d75 06d3 …mu…
2360 4431 41b5 82b4 7eb4 651d f395 0101 0000 D1A…~.e…
2400 0c00 0000 0000 0000 d6c6 305e 0282 1300 …0^…
2420 0382 1300 0482 1300 0582 1300 0682 1300 …
2440 0782 1300 0882 1300 0982 1300 0a82 1300 …
2460 0b82 1300 0c82 1300 0d82 1300 0e82 1300 …
2500 0f86 1300 0000 0000 0000 0000 0000 0008 …
2520 0000 0000 0000 0000 0000 0000 1c00 1c00 …
2540 0100 0000 0000 0000 0000 0000 0000 0000 …
2560 0000 0000 0000 0000 0000 0000 0000 0000 …
*

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值