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


8

我有一个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

给出什么输出dd
qdii

dd无法读取数据是什么意思?
qdii

前512个字节应为包含分区表的MBR,但显然不是这种情况
Tom Booth,

嗯。也许是因为您不使用一个?GPT的魔力在于可以代替MBR的分区表(但是可以保留MBR,以使引导加载程序希望MBR继续工作)。
qdii

1
什么是输出fdisk -lu /dev/sdbgdisk -l /dev/sdb以及grep sdb /proc/partitions
斯特凡Chazelas

Answers:


2

该卡没有主启动记录(MBR)。如果有hexdump,则会在offset 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等提供的命令中找到什么,将非常有趣。


1

我会尝试使用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

参考文献


为什么有人要使用hexdump(纯文本)输出sfdisk -d /dev/sda
Hauke Laging

太好了,我没有注意到这是纯文本。我将在答案8-)中修复它。
slm

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.