磁盘布局:前 512 个字节故意不被文件系统(ext、xfs、brtfs)和卷管理(lvm、zfs、brtfs)使用,这是设计规则吗?

磁盘布局:前 512 个字节故意不被文件系统(ext、xfs、brtfs)和卷管理(lvm、zfs、brtfs)使用,这是设计规则吗?

我怀疑所有现代文件系统(ext、xfs、brtfs……)和卷管理(lvm、zfs、brtfs……)都故意避免使用磁盘或分区的至少前 512 个字节,这是真的吗?我知道这很难回答,但如果有人分享一些经验,我将不胜感激。如果您知道一些更好的地方可以问这个问题,请告诉我。

到目前为止,我已经测试了 ext、xfs、lvm、zfs、brtfs。

验证很简单:只需在磁盘映像文件中 mkfs.*,为简单起见,命名为a

rm -f a
truncate -s 1G a
mkfs.${FS_TYPE} a
dd if=a count=10 | xxd -g1 | fgrep -v ': 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00'

或者

rm -f a
truncate -s 1G a
LOOPDEV=$(sudo losetup --find--find --partscan --show a)
sudo mkfs.${FS_TYPE} $LOOPDEV
dd if=a count=10 | xxd -g1 | fgrep -v ': 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00'
sudo losetup --detach $LOOPDEV

结果是:(我跳过了那些全为零的行),你可以检查第一个非零数据的起始位置都大于00000200(512)

sudo zpool create pool1 /dev/loop13
dd if=a count=1000 | xxd -g1 | fgrep -v ': 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00'
00003fd0: 00 00 00 00 00 00 00 00 11 7a 0c b1 7a da 10 02  .........z..z...
00003fe0: 3f 2a 6e 7f 80 8f f4 97 fc ce aa 58 16 9f 90 af  ?*n........X....
00003ff0: 8b b4 6d ff 57 ea d1 cb ab 5f 46 0d db 92 c6 6e  ..m.W...._F....n
00004000: 01 01 00 00 00 00 00 00 00 00 00 01 00 00 00 24  ...............$
00004010: 00 00 00 20 00 00 00 07 76 65 72 73 69 6f 6e 00  ... ....version.
00004020: 00 00 00 08 00 00 00 01 00 00 00 00 00 00 13 88  ................
00004030: 00 00 00 24 00 00 00 20 00 00 00 04 6e 61 6d 65  ...$... ....name
00004040: 00 00 00 09 00 00 00 01 00 00 00 05 70 6f 6f 6c  ............pool
00004050: 31 00 00 00 00 00 00 24 00 00 00 20 00 00 00 05  1......$... ....
00004060: 73 74 61 74 65 00 00 00 00 00 00 08 00 00 00 01  state...........
00004070: 00 00 00 00 00 00 00 00 00 00 00 20 00 00 00 20  ........... ...
00004080: 00 00 00 03 74 78 67 00 00 00 00 08 00 00 00 01  ....txg.........
00004090: 00 00 00 00 00 00 00 04 00 00 00 28 00 00 00 28  ...........(...(
000040a0: 00 00 00 09 70 6f 6f 6c 5f 67 75 69 64 00 00 00  ....pool_guid...
000040b0: 00 00 00 08 00 00 00 01 6b 45 2f 72 95 a0 67 a8  ........kE/r..g.

mkfs.btrfs a
dd if=a count=1000 | xxd -g1 | fgrep -v ': 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00'
00010000: d3 8b 5c 20 00 00 00 00 00 00 00 00 00 00 00 00  ..\ ............
00010020: 7d 8d da 9c 52 4e 4f db 96 12 9a 82 6c 28 ba f5  }...RNO.....l(..
00010030: 00 00 01 00 00 00 00 00 01 00 00 00 00 00 00 00  ................
00010040: 5f 42 48 52 66 53 5f 4d 06 00 00 00 00 00 00 00  _BHRfS_M........
00010050: 00 80 d0 01 00 00 00 00 00 40 50 01 00 00 00 00  .........@P.....
00010070: 00 00 00 40 00 00 00 00 00 00 02 00 00 00 00 00  ...@............
00010080: 06 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00  ................
00010090: 00 10 00 00 00 40 00 00 00 40 00 00 00 10 00 00  .....@...@......
000100a0: 81 00 00 00 05 00 00 00 00 00 00 00 00 00 00 00  ................
000100b0: 00 00 00 00 00 00 00 00 00 00 00 00 61 01 00 00  ............a...
000100c0: 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00  ................
000100d0: 00 00 00 00 40 00 00 00 00 00 00 e6 07 00 00 00  ....@...........
000100e0: 00 00 10 00 00 00 10 00 00 00 10 00 00 00 00 00  ................
00010100: 00 00 00 00 00 00 00 00 00 00 00 d6 b0 b3 09 e2  ................
00010110: 99 42 c0 9e 41 da e3 56 ab 10 5e 7d 8d da 9c 52  .B..A..V..^}...R
00010120: 4e 4f db 96 12 9a 82 6c 28 ba f5 00 00 00 00 00  NO.....l(.......
00010220: 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 00  ................
00010320: 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00  ................
00010330: 00 00 00 e4 00 00 50 01 00 00 00 00 00 00 80 00  ......P.........
00010340: 00 00 00 00 02 00 00 00 00 00 00 00 00 00 01 00  ................
00010350: 00 00 00 00 22 00 00 00 00 00 00 00 00 00 01 00  ...."...........
00010360: 00 00 01 00 00 10 00 00 02 00 00 00 01 00 00 00  ................
00010370: 00 00 00 00 00 00 50 01 00 00 00 00 d6 b0 b3 09  ......P.........

mkfs.ext4 a
dd if=a count=3 | xxd -g1 | fgrep -v ': 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00'
00000400: 00 00 01 00 00 00 04 00 33 33 00 00 65 cd 03 00  ........33..e...
00000410: f5 ff 00 00 00 00 00 00 02 00 00 00 02 00 00 00  ................
00000420: 00 80 00 00 00 80 00 00 00 20 00 00 00 00 00 00  ......... ......
00000430: 03 93 71 5f 00 00 ff ff 53 ef 01 00 01 00 00 00  ..q_....S.......
00000440: 03 93 71 5f 00 00 00 00 00 00 00 00 01 00 00 00  ..q_............
00000450: 00 00 00 00 0b 00 00 00 00 01 00 00 3c 00 00 00  ............<...
00000460: c2 02 00 00 6b 04 00 00 9e c2 1a 03 14 3f 41 e1  ....k........?A.
00000470: 8d 7b 45 e7 b1 48 49 af 00 00 00 00 00 00 00 00  .{E..HI.........
000004c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 7f 00  ................
000004e0: 08 00 00 00 00 00 00 00 00 00 00 00 e7 a9 5f 27  .............._'
000004f0: 7f 61 4d 92 97 9c cf f7 67 24 ef b0 01 01 40 00  .aM.....g$....@.
00000500: 0c 00 00 00 00 00 00 00 03 93 71 5f 0a f3 01 00  ..........q_....
00000510: 04 00 00 00 00 00 00 00 00 00 00 00 00 20 00 00  ............. ..
00000520: 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000540: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02  ................
00000550: 00 00 00 00 00 00 00 00 00 00 00 00 20 00 20 00  ............ . .
00000560: 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00000570: 00 00 00 00 04 01 00 00 15 02 00 00 00 00 00 00  ................

mkfs.xfs a
dd if=a count=2 | xxd -g1 | fgrep -v ': 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00'
00000000: 58 46 53 42 00 00 10 00 00 00 00 00 00 04 00 00  XFSB............
00000020: ef 76 e8 dc 47 ec 4e 81 9d 8c fc ad c9 2d 76 e3  .v..G.N......-v.
00000030: 00 00 00 00 00 02 00 05 00 00 00 00 00 00 00 60  ...............`
00000040: 00 00 00 00 00 00 00 61 00 00 00 00 00 00 00 62  .......a.......b
00000050: 00 00 00 01 00 01 00 00 00 00 00 04 00 00 00 00  ................
00000060: 00 00 0a 00 b4 a5 02 00 02 00 00 08 00 00 00 00  ................
00000070: 00 00 00 00 00 00 00 00 0c 09 09 03 10 00 00 19  ................
00000080: 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00 3d  .......@.......=
00000090: 00 00 00 00 00 03 f5 e4 00 00 00 00 00 00 00 00  ................
000000b0: 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 00  ................
000000c0: 00 00 00 00 00 00 00 01 00 00 01 8a 00 00 01 8a  ................
000000d0: 00 00 00 00 00 00 00 01 00 00 00 01 00 00 00 00  ................
000000e0: aa 7c 01 e4 00 00 00 00 00 00 00 00 00 00 00 00  .|..............
00000200: 58 41 47 46 00 00 00 01 00 00 00 00 00 01 00 00  XAGF............
00000210: 00 00 00 01 00 00 00 02 00 00 00 00 00 00 00 01  ................
00000220: 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 03  ................
00000230: 00 00 00 04 00 00 ff ef 00 00 ff ec 00 00 00 00  ................
00000240: ef 76 e8 dc 47 ec 4e 81 9d 8c fc ad c9 2d 76 e3  .v..G.N......-v.
000002d0: 00 00 00 00 00 00 00 00 33 bc d1 e6 00 00 00 00  ........3.......

我还发现了一个负面情况:NTFS,它继承了MBR中的前512字节设计。

mkfs.ntfs /dev/loop13
dd if=a count=10 | xxd -g1 | fgrep -v ': 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00'
00000000: eb 52 90 4e 54 46 53 20 20 20 20 00 02 08 00 00  .R.NTFS    .....
00000010: 00 00 00 00 00 f8 00 00 00 00 00 00 00 00 00 00  ................
00000020: 00 00 00 00 80 00 80 00 ff ff 1f 00 00 00 00 00  ................
00000030: 04 00 00 00 00 00 00 00 ff ff 01 00 00 00 00 00  ................
00000040: f6 00 00 00 01 00 00 00 5b 23 b8 64 42 cc d5 61  ........[#.dB..a
00000050: 00 00 00 00 0e 1f be 71 7c ac 22 c0 74 0b 56 b4  .......q|.".t.V.
00000060: 0e bb 07 00 cd 10 5e eb f0 32 e4 cd 16 cd 19 eb  ......^..2......
00000070: fe 54 68 69 73 20 69 73 20 6e 6f 74 20 61 20 62  .This is not a b
00000080: 6f 6f 74 61 62 6c 65 20 64 69 73 6b 2e 20 50 6c  ootable disk. Pl
00000090: 65 61 73 65 20 69 6e 73 65 72 74 20 61 20 62 6f  ease insert a bo
000000a0: 6f 74 61 62 6c 65 20 66 6c 6f 70 70 79 20 61 6e  otable floppy an
000000b0: 64 0d 0a 70 72 65 73 73 20 61 6e 79 20 6b 65 79  d..press any key
000000c0: 20 74 6f 20 74 72 79 20 61 67 61 69 6e 20 2e 2e   to try again ..
000000d0: 2e 20 0d 0a 00 00 00 00 00 00 00 00 00 00 00 00  . ..............
000001f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa  ..............U.

编辑于 2020/09/28:我的错,我没有注意到 XFS 使用前 512 个字节,

mkfs.xfs a
dd if=a count=2 | xxd -g1 | fgrep -v ': 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00'
00000000: 58 46 53 42 00 00 10 00 00 00 00 00 00 04 00 00  XFSB............
00000020: ef 76 e8 dc 47 ec 4e 81 9d 8c fc ad c9 2d 76 e3  .v..G.N......-v.
00000030: 00 00 00 00 00 02 00 05 00 00 00 00 00 00 00 60  ...............`
00000040: 00 00 00 00 00 00 00 61 00 00 00 00 00 00 00 62  .......a.......b
00000050: 00 00 00 01 00 01 00 00 00 00 00 04 00 00 00 00  ................
00000060: 00 00 0a 00 b4 a5 02 00 02 00 00 08 00 00 00 00  ................
00000070: 00 00 00 00 00 00 00 00 0c 09 09 03 10 00 00 19  ................
00000080: 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00 3d  .......@.......=
00000090: 00 00 00 00 00 03 f5 e4 00 00 00 00 00 00 00 00  ................
000000b0: 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 00  ................
000000c0: 00 00 00 00 00 00 00 01 00 00 01 8a 00 00 01 8a  ................
000000d0: 00 00 00 00 00 00 00 01 00 00 00 01 00 00 00 00  ................
000000e0: aa 7c 01 e4 00 00 00 00 00 00 00 00 00 00 00 00  .|..............
00000200: 58 41 47 46 00 00 00 01 00 00 00 00 00 01 00 00  XAGF............
00000210: 00 00 00 01 00 00 00 02 00 00 00 00 00 00 00 01  ................
00000220: 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 03  ................
00000230: 00 00 00 04 00 00 ff ef 00 00 ff ec 00 00 00 00  ................
00000240: ef 76 e8 dc 47 ec 4e 81 9d 8c fc ad c9 2d 76 e3  .v..G.N......-v.
000002d0: 00 00 00 00 00 00 00 00 33 bc d1 e6 00 00 00 00  ........3.......

所以我的猜测是不合逻辑的,是否使用前 512 字节完全取决于文件系统/卷设计者。

但很高兴了解其他的经历,谢谢大家。

相关内容