/ dev / sda1不是/ dev / sda的子集?


18

我的分区表的第一项是:

$ sudo hexdump -Cv -n 16 -s 446 /dev/sda
000001be  80 01 01 00 83 fe ff ff  3f 00 00 00 81 1c 20 03  |........?..... .|

-Cv描述输出格式,-n 16要求16个字节,-s 446跳过前446个字节)
您可以看到我的第一个分区是主Linux分区,并且该分区始于扇区63(例如,请参见[此处] [1]表示分区表的结构。
然后,我希望除了前63个扇区和其他分区之外,/ dev / sda1和/ dev / sda完全相同。

但是情况并非如此,/ dev / sda1的扇区#2与/ dev / sda的扇区#65并不完全相同(但它们非常相似,只有16个字节不同):

$ sudo hexdump -Cv -n 512 -s 65b /dev/sda
00008200  00 20 19 00 90 03 64 00  2d 00 05 00 5a 2f 56 00  |. ....d.-...Z/V.|
00008210  b6 b1 16 00 00 00 00 00  02 00 00 00 02 00 00 00  |................|
00008220  00 80 00 00 00 80 00 00  00 20 00 00 d8 38 ee 4c  |......... ...8.L|
00008230  9a 01 ef 4c 05 00 24 00  53 ef 01 00 01 00 00 00  |...L..$.S.......|
00008240  59 23 e9 4c 00 4e ed 00  00 00 00 00 01 00 00 00  |Y#.L.N..........|
00008250  00 00 00 00 0b 00 00 00  00 01 00 00 3c 00 00 00  |............<...|
00008260  42 02 00 00 7b 00 00 00  85 23 eb f2 71 67 44 f5  |B...{....#..qgD.|
00008270  bb 8f 6f f2 3a 59 ff 4d  55 62 75 6e 74 75 00 00  |..o.:Y.MUbuntu..|
00008280  00 00 00 00 00 00 00 00  2f 75 62 75 6e 74 75 00  |......../ubuntu.|
00008290  d8 3c df 5d 00 88 ff ff  52 d0 ef 1d 00 00 00 00  |.<.]....R.......|
000082a0  c0 40 51 b6 00 88 ff ff  00 4e c8 bb 00 88 ff ff  |.@Q......N......|
000082b0  c0 f6 86 b8 00 88 ff ff  30 2e 0d a0 ff ff ff ff  |........0.......|
000082c0  38 3d df 5d 00 88 ff ff  00 00 00 00 00 00 fe 03  |8=.]............|
000082d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000082e0  08 00 00 00 00 00 00 00  00 00 00 00 8a 53 d3 0e  |.............S..|
000082f0  7c 7a 43 e4 8b fb ca e0  72 b7 fa c8 01 01 00 00  ||zC.....r.......|
00008300  00 00 00 00 00 00 00 00  16 4c 47 4b 0a f3 03 00  |.........LGK....|
00008310  04 00 00 00 00 00 00 00  00 00 00 00 fe 7f 00 00  |................|
00008320  24 b7 0c 00 fe 7f 00 00  01 00 00 00 22 37 0d 00  |$..........."7..|
00008330  ff 7f 00 00 01 00 00 00  23 37 0d 00 00 00 00 00  |........#7......|
00008340  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 08  |................|
00008350  00 00 00 00 00 00 00 00  00 00 00 00 1c 00 1c 00  |................|
00008360  01 00 00 00 e9 7f 00 00  00 00 00 00 00 00 00 00  |................|
00008370  00 00 00 00 04 00 00 00  9f 7d bb 00 00 00 00 00  |.........}......|
00008380  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00008390  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000083a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000083b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000083c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000083d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000083e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000083f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

$ sudo hexdump -Cv -n 512 -s 2b /dev/sda1
00000400  00 20 19 00 90 03 64 00  2d 00 05 00 5a 2f 56 00  |. ....d.-...Z/V.|
00000410  b6 b1 16 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 df 76 ef 4c  |......... ...v.L|
00000430  df 76 ef 4c 06 00 24 00  53 ef 01 00 01 00 00 00  |.v.L..$.S.......|
00000440  59 23 e9 4c 00 4e ed 00  00 00 00 00 01 00 00 00  |Y#.L.N..........|
00000450  0

好问题...虽然答案不知道+1
RobotHumans

可以有适当的差异?
Hello71 2011年

Answers:


6

很好的发现,因为我也能够在系统上重现这种效果。在我的站点上,它发生在/ dev / hda上,因此这不是SCSI问题。

# uname -a
Linux X.X.X 2.6.26-2-686 #1 SMP Tue Mar 9 17:35:51 UTC 2010 i686 GNU/Linux

我认为whitequark这是缓存问题,这是正确的。这是我对您网站上发生的事情的解释(请注意,尽管我不确定我的解释是正确的):

/ dev / sda1正在使用中。因此,每次刷新日志(或类似日志)时,“同步”都会更新超级块。因此磁盘/ dev / sda1已更改。

但是,内核不为/ dev / sda和/ dev / sda1使用组合的缓存,而是两个“文件”都是自己缓存的。为此,更新/ dev / sda1(同步)不会使/ dev / sda的缓存无效。因此,从/ dev / sda读取将显示旧的缓存值(因此,缓存与硬盘驱动器不同步),而/ dev / sda1则显示正确的(新)值。

这是我身边的情况。我来这里之前在/ dev / hda上做了一些转储,所以它已经缓存了一些旧数据:

# od -tx1z -N 10k /dev/hda2 > NOW1
# dd ibs=512 skip=1975995 if=/dev/hda | od -tx1z -N 10k > MAIN1
# diff NOW1 MAIN1
3,4c3,4
< 0002000 00 00 31 01 57 c4 61 02 04 7d 1e 00 be 1a 39 00  >..1.W.a..}....9.<
< 0002020 4e ea 21 01 00 00 00 00 02 00 00 00 02 00 00 00  >N.!.............<
---
> 0002000 00 00 31 01 57 c4 61 02 04 7d 1e 00 4e 1b 39 00  >..1.W.a..}..N.9.<
> 0002020 52 ea 21 01 00 00 00 00 02 00 00 00 02 00 00 00  >R.!.............<

# od -tx1z -N 10k /dev/hda2 > NOW1
# diff NOW1 MAIN1
3,4c3,4
< 0002000 00 00 31 01 57 c4 61 02 04 7d 1e 00 be 1a 39 00  >..1.W.a..}....9.<
< 0002020 4e ea 21 01 00 00 00 00 02 00 00 00 02 00 00 00  >N.!.............<
---
> 0002000 00 00 31 01 57 c4 61 02 04 7d 1e 00 4e 1b 39 00  >..1.W.a..}..N.9.<
> 0002020 52 ea 21 01 00 00 00 00 02 00 00 00 02 00 00 00  >R.!.............<

# od -tx1z -N 10k /dev/hda2 > NOW2
# dd ibs=512 skip=1975995 if=/dev/hda | od -tx1z -N 10k > MAIN2
# diff MAIN1 MAIN2
# diff NOW2 MAIN2
3,4c3,4
< 0002000 00 00 31 01 57 c4 61 02 04 7d 1e 00 f0 19 39 00  >..1.W.a..}....9.<
< 0002020 41 ea 21 01 00 00 00 00 02 00 00 00 02 00 00 00  >A.!.............<
---
> 0002000 00 00 31 01 57 c4 61 02 04 7d 1e 00 4e 1b 39 00  >..1.W.a..}..N.9.<
> 0002020 52 ea 21 01 00 00 00 00 02 00 00 00 02 00 00 00  >R.!.............<
106c106
< 0012440 00 80 14 00 01 80 14 00 02 80 14 00 00 00 01 00  >................<
---
> 0012440 00 80 14 00 01 80 14 00 02 80 14 00 00 00 00 00  >................<
334c334
< 0021540 00 80 4d 00 01 80 4d 00 02 80 4d 00 02 00 63 3e  >..M...M...M...c><
---
> 0021540 00 80 4d 00 01 80 4d 00 02 80 4d 00 02 00 64 3e  >..M...M...M...d><

/ dev / hda不显示任何更新,而/ dev / hda2显示一些更改。但是,当我刷新缓存并重试时,一切都显示相同:

# hdparm -f /dev/hda

/dev/hda:

# dd ibs=512 skip=1975995 if=/dev/hda | od -tx1z -N 10k > MAIN2
# diff MAIN1 MAIN2
3,4c3,4
< 0002000 00 00 31 01 57 c4 61 02 04 7d 1e 00 4e 1b 39 00  >..1.W.a..}..N.9.<
< 0002020 52 ea 21 01 00 00 00 00 02 00 00 00 02 00 00 00  >R.!.............<
---
> 0002000 00 00 31 01 57 c4 61 02 04 7d 1e 00 dc 1a 39 00  >..1.W.a..}....9.<
> 0002020 96 ea 21 01 00 00 00 00 02 00 00 00 02 00 00 00  >..!.............<
36,37c36,37
< 0010300 00 00 03 00 01 00 03 00 02 00 03 00 00 00 bb 3b  >...............;<
< 0010320 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
---
> 0010300 00 00 03 00 01 00 03 00 02 00 03 00 00 00 bc 3b  >...............;<
> 0010320 7f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
48c48
< 0010600 00 00 06 00 01 00 06 00 02 00 06 00 03 00 18 3f  >...............?<
---
> 0010600 00 00 06 00 01 00 06 00 02 00 06 00 04 00 18 3f  >...............?<
106c106
< 0012440 00 80 14 00 01 80 14 00 02 80 14 00 00 00 00 00  >................<
---
> 0012440 00 80 14 00 01 80 14 00 02 80 14 00 00 00 01 00  >................<

# od -tx1z -N 10k /dev/hda2 > NOW2
# diff NOW2 MAIN2
# diff MAIN1 MAIN2
3,4c3,4
< 0002000 00 00 31 01 57 c4 61 02 04 7d 1e 00 4e 1b 39 00  >..1.W.a..}..N.9.<
< 0002020 52 ea 21 01 00 00 00 00 02 00 00 00 02 00 00 00  >R.!.............<
---
> 0002000 00 00 31 01 57 c4 61 02 04 7d 1e 00 dc 1a 39 00  >..1.W.a..}....9.<
> 0002020 96 ea 21 01 00 00 00 00 02 00 00 00 02 00 00 00  >..!.............<
36,37c36,37
< 0010300 00 00 03 00 01 00 03 00 02 00 03 00 00 00 bb 3b  >...............;<
< 0010320 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
---
> 0010300 00 00 03 00 01 00 03 00 02 00 03 00 00 00 bc 3b  >...............;<
> 0010320 7f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
48c48
< 0010600 00 00 06 00 01 00 06 00 02 00 06 00 03 00 18 3f  >...............?<
---
> 0010600 00 00 06 00 01 00 06 00 02 00 06 00 04 00 18 3f  >...............?<
106c106
< 0012440 00 80 14 00 01 80 14 00 02 80 14 00 00 00 00 00  >................<
---
> 0012440 00 80 14 00 01 80 14 00 02 80 14 00 00 00 01 00  >................<

关于如何复制的简短说明:

  • 确保您的系统空闲并且有足够的RAM用于缓存。
  • 运行fdisk -u -l以查找分区的起始位置。在我这边是1975995
  • 选择一个已安装的分区和完整的驱动器。
  • 然后进行两个转储(NOW1,MAIN1)并进行比较。他们应该比较平等。
  • 更改分区的一部分,同步。
  • 留出更多时间。
  • 更改一下,然后再次同步。
  • 不要转储NOW2,它应不同于NOW1
  • 做一个转储MAIN2,应该不是从MAIN1不同!
  • 执行hdparm驱动器的生产线
  • 再次转储MAIN2,现在它将不同于MAIN1。
  • 如果速度足够快,NOW2和MAIN2将比较相等。

0

经过类似的测试后,我没有分歧。可能是在每个转储之间写入了特定的扇区。

以下命令比较从/ dev / sda和/ dev / sda1提取的同一扇区的前48MB:

$ diff <(sudo hexdump -Cv -n $((512*100000)) -s 0x7e00 /dev/sda | awk '{$1=""}1' ) <(sudo hexdump -Cv -n $((512*100000)) /dev/sda1 | awk '{$1=""}1' )

其中0x7e00是第一个分区的偏移量。


1
它也可能以某种方式与磁盘缓存有关。
whitequark 2011年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.