Linux/GParted 可以看到分区表,但 dd bs=512 count=1 看不到

Linux/GParted 可以看到分区表,但 dd bs=512 count=1 看不到

我有一个 MBR 格式的 SD 卡,当连接到 Linux 机器(xubuntu 12.04)时,它可以挂载分区并解析文件系统(GParted 也可以)。然而,当我尝试使用 dd 从设备读取 MBR 时,它给了我一堆虚假数据。

当 dd 无法读取 MBR 时,任何人都可以阐明 Linux/GParted 如何读取并理解 MBR。他们是否使用不同的方法来获取数据?IE 无法打开()、读取()

DD命令是:

dd if=/dev/sdb of=mbr.bin bs=512 count=1

DD 输出为:

1+0 records in
1+0 records out
512 bytes transferred in 0.000786 secs (651345 bytes/sec)

mbr.bin 转储hexdump -C mbr.bin为:

00000000  04 16 41 53 4d 49 2d 53  44 03 00 00 00 00 16 f1  |..ASMI-SD.......|
00000010  00 7f 00 32 1f 5b 80 00  36 db bf bf 96 c0 00 01  |...2.[..6.......|
00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000030  6f 00 00 10 00 00 02 2e  00 00 00 00 00 00 00 00  |o...............|
00000040  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000200

答案1

该卡没有主引导记录 (MBR)。如果它有你的十六进制转储,将会在偏移量0x1C055aa末尾处为你提供至少一个分区条目。

并非所有分区表都将数据布局在前 512 字节中。这虚假数据你看到的是(一张/一张)SD卡的SID和CSD寄存器。但从表面上看,这不是卡的正确数据(除非是旧的 1 MiB 2001 型号。)

前 16 个字节是:

CID Register:
----------------------------------------------------------------------------
Manufacturer ID       (MID): 04               => (Transcend)
OEM/Application ID    (OID): 16 41            =  ?A
Product name          (PNM): 53 4d 49 2d 53   =  SMI-S
Product revision      (PRV): 44               =  0100 0100 => 4.4
Product serial number (PSN): 03 00 00 00
reserved               (-) : 00 >> 4          = 0000b
Manufacturing date    (MDT): (00 & 0x0f)|0x16 = 0001b,0110b => 2000+1,6=> Jun 2001
CRC7 checksum         (CRC): 1f >> 1          = 120
always 1               (1) : 1f & 1           = 1

接下来的 16 个字节(至少是其中的一部分):

CSD Register:
----------------------------------------------------------------------------
CSD Structure        (CSD_STRUCTURE): 00 >> 6  = 00b => CSD Version 1.0
reserved                         (-): 00 & 3f  = 00 0000b
Data read access time 1       (TAAC): 7f = 1111b => time val 8.0, 111b => 7=10ms
Data read access time 2       (NSAC): 00
Max. data transfer rate (TRAN_SPEED): 32 = 0110,010 time val 2.5, 2=10Mbit/s 25MHz
Card command classes           (CCC): 1f << 4 | 5b >> 4 = 0x1f5

...
Device size (C_SIZE) : (0x80 & 0x03) << 0xa | 00h | 36 >> 6 : 0

Max. read  current @VDD min (VDD_R_CURR_MIN) : 110 => 60mA
Max. read  current @VDD max (VDD_R_CURR_MAX) : 110 => 80mA
Max. write current @VDD min (VDD_W_CURR_MIN) : 110 => 60mA
Max. write current @VDD max (VDD_W_CURR_MAX) : 110 => 80mA
Device size multiplier         (C_SIZE_MULT) : 111 => 2^(7 + 2) = 512
Erase single block enable     (ERASE_BLK_EN) : 0
Erase sector size              (SECTOR_SIZE) : 1111111 => 127 + 1 = 128
Write protect group size       (WP_GRP_SIZE) : 0111111 =>  63 + 1 = 64

MULT      = 2^(C_SIZE_MULT + 2)  = 2^(7 + 2) = 512
BLOCKNR   = (C_SIZE + 1) * MULT  = 1 * 512   = 512
BLOCK_LEN = 2^READ_BL_LEN        = 2^11      = 2048

memory capacity = 
BLOCKNR * BLOCK_LEN = 512 * 2048 = 1048576 bytes = 1024 KiB = 1 MiB

另外,CSD 寄存器的 CRC7 检查是错误的。它可能是消遣时留下的旧数据。

这些寄存器等可以通过各种命令直接从卡中查询。这是由模块驱动程序、卡集线器等完成的。


看看 Stephane Chazelas、slm 等给出的命令会发现什么,这会很有趣。

答案2

我会尝试使用该sfdisk命令而不是dd.例如:

$ sudo sfdisk -d /dev/sda > /tmp/mbr_using_sfdisk.bin
Warning: extended partition does not start at a cylinder boundary.
DOS and Linux will interpret the contents differently.

现在查看mbr_using_sfdisk.bin揭示了您正在寻找的内容:

$ more /tmp/mbr_using_sfdisk.bin
# partition table of /dev/sda
unit: sectors

/dev/sda1 : start=     2048, size=  2457600, Id= 7, bootable
/dev/sda2 : start=  2459648, size=314765312, Id= 7
/dev/sda3 : start=956291072, size= 20480000, Id= 7
/dev/sda4 : start=317224960, size=639066112, Id= 5
/dev/sda5 : start=317227008, size=  1024000, Id=83
/dev/sda6 : start=318253056, size=638038016, Id=8e

那么为什么我看不到分区表呢dd

我不完全确定为什么,但我确实遇到了这个技巧,它向您展示了如何使用mbr.bin命令查看分区表file

例如:

$ sudo dd if=/dev/sda bs=512 count=1 of=mbr.bin
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.000184924 s, 2.8 MB/s

$ file mbr.bin 
mbr.bin: x86 boot sector; GRand Unified Bootloader, stage1 version 0x3, boot drive 0x80, 1st sector stage2 0x12f0c26a, GRUB version 0.94; 
partition 1: ID=0x7, active, starthead 32, startsector 2048, 2457600 sectors; 
partition 2: ID=0x7, starthead 162, startsector 2459648, 314765312 sectors;
partition 3: ID=0x7, starthead 239, startsector 956291072, 20480000 sectors;
partition 4: ID=0x5, starthead 239, startsector 317224960, 639066112 sectors, code offset 0x48

参考

答案3

该数据不是您的 SD 卡内存,而是由您的 SD 卡控制器 (ASMI) 发送的。此页面描述了发生在我身上的问题:

http://www.idioten-notschlachten.de/blog/2011/11/13/kennen-sie-asmi/

相关内容