【嵌入式Linux】MBR分区表 和 GPT分区表

文章详细介绍了GPT分区表与传统的MBR分区表的区别,包括GPT的分区结构、LBA逻辑区块地址、分区表头信息,以及如何使用Python脚本来生成GPT分区表。GPT提供更好的大容量磁盘支持、分区备份和CRC校验,而MBR则有分区数量限制和不支持大容量磁盘的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原文:http://www.pedestrian.com.cn/embedded/gpt/gpt_partition.html

 GPT分区表中有一个比较重要的概念是LBA, 翻译为中文可解释为逻辑区块地址。是描述存储设备上数据所在区块的通用机制,一般用在硬盘或者SD卡这种记忆设备,我们俗称扇区。

  • MBR:主引导记录(Master Boot Record)
  • GPT:GUID分区表(GUID Partition Table)
  • GUID:全局唯一标识符(Globally Unique Identifier),是一种由算法生成的二进制长度为16字节(128位)的数字标识符。通常表示成32个16进制数字(0-9,A-F)组成的字符串,GUID 的格式为“xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”。例如:6F9619FF-8B86-D011-B42D-00C04FC964FF 即为有效的 GUID 值。

GUID以及分区表

MBR分区方案

 传统的分区方案是将分区信息保存在磁盘的第一个扇区中的64个字节中,每个分区项占16个字节。由于MBR扇区只有64个字节用于分区表,所以只能记录4个分区信息,这就是硬盘主分区数目 不能超过4个的原因,后来为了支持更多的分区引入了扩展分区及逻辑分区的概念,但每个分区项仍用16个字节存储。

 MBR分区有一个比较大的缺陷是不能支持超过2T容量的磁盘,因为这一方案用4个字节存储分区的总扇区数,最大能表示2的32次方的扇区个数,按每个扇区512字节计算,每个分区最大不能超过2T。

计算机硬盘分区:
 MBR(Main Boot Record 主引导记录区)位于整个硬盘的0磁道0柱面1扇区。在512字节的主引导扇区中,MBR只占用了其中的446个字节,另外的64个字节交给了 DPT(Disk Partition Table硬盘分区表),最后两个字节“55,AA”是分区的结束标志。这个整体构成了硬盘的主引导扇区。

主引导扇区由三个部分组成:主引导记录(MBR,Master Boot Record)、硬盘分区表(DPT,Disk Partition Table)、引导记录标志(或者说结束标志)(BRID,Boot Record ID)。

在这里插入图片描述

主引导扇区大小是512字节,其中MBR占据446个字节,DPT占据64字节,BRID占据两个字节。
在这里插入图片描述

相对来说复杂一些。

嵌入式Linux SD启动卡:

地址描述长度(Byte)
0代码区440(最大446)
440选用磁盘标志4
444一般为空值: 0x00002
446标准MBR分区规划(第一个主分区入口)16
462标准MBR分区规划(第二个主分区入口)16
478标准MBR分区规划(第三个主分区入口)16
494标准MBR分区规划(第四个主分区入口)16
510MBR有效标志2

全志V3s的SD卡固件
在这里插入图片描述

数据起始字节数长度描述
08 4F 8A 2B4404标志
00 004442空值
下图红色框区域44616分区表
下图绿色框区域46216分区表
55 AA5102标志

在这里插入图片描述
16字节分区表描述

偏移长度(字节)意义
00H1分区状态:00–>非活动分区;80–>活动分区;其它数值没有意义
01H1分区起始磁头号(HEAD),用到全部8位
02H2分区起始扇区号(SECTOR),占据02H的位0-5;该分区的起始磁柱号(CYLINDER),占据02H的位6-7和03H的全部8位
04H1文件系统标志位
05H1分区结束磁头号(HEAD),用到全部8位
06H2分区结束扇区号(SECTOR),占据06H的位0-5;该分区的结束磁柱号(CYLINDER),占据06H的位6-7和
08H4分区起始相对扇区号
0CH4分区总的扇区数

在这里插入图片描述

软件winhex中在ANSI ASCII区域下拉菜单中选择“分区表(模板)”,可以获取该部分一些信息。
在这里插入图片描述
有两个分区信息。

不是绝对的是在百问网T113-s3的固件里面(如下)地址440~445就没有数据。
在这里插入图片描述
总结

  • ARM开发板的启动卡的MBR,前0~440字节区域都是0,计算机MBR的这块区域有大量的数据和代码。
  • MBR的446~510字节区域,ARM开发板和计算机的都是一样的。四个16字节的分区描述区域(DPT)。

GPT 分区方案

 GUID分区表(简称GPT)是源自EFI标准的一种新的磁盘分区表结构的标准。相较于mbr有以下优点:

  1. 支持2TB 以上的磁盘。
  2. 分区表自带备份,在磁盘的收尾部分分别保存了一份相同的分区表,其中一份被破坏后可通过另一份恢复。
  3. 增加CRC校验机制。
  4. GPT使用一个16字节的全局唯一标识符(guid)来标识分区类型,这使分区类型不容易冲突
  5. 每个分区可以有一个名称。

GPT分区表结构

  • LBA:逻辑区块地址
    在这里插入图片描述

从上图可以看到的是,GPT 的结构是有着 主备两部分的,

  • 上面有Primary GUID Partition(主区),下面有Backup GUID Partition(备用区)。
  • 跟现代的MBR一样,GPT也使用LBA(Logical Block Address,逻辑区块地址)取代了早期的CHS寻址方式。传统MBR信息仅存储于LBA 0,而GPT使用了34个LBA,GPT头存储于LBA 1,接下来才是分区表本身。
  • GPT的每一个分区都可以独立存在,没有所谓的扩展、逻辑分区的概念,即所有分区都是主分区。

GPT分区表LBA

下图是百问网T113-s3(双核ARM A7)的固件:
在这里插入图片描述

  • 可以看出红框内就是一个典型的MBR数据块,这个应该就是LBA0(MBR兼容部分)。
  • 绿框内的前八个字节是"EFI PART",代表这是一个LBA区域。

LBA0(MBR兼容部分)

 在GPT分区表的最开头处,由于兼容性考虑仍然存储了一份传统的MBR,这个MBR叫做保护性
MBR(protective MBR)。在这个MBR中只有一个标识为0xEE的分区,以此来表示这块磁盘使用GPT分区表。

LBA1

分区表头(LBA1)定义了磁盘的可用空间以及组成分区的大小和数量,分区表头结构的详细信息如下

起始字节偏移量内容
08签名(“EFI PART”)
84修订
124分区表头的大小
164分区表头(92字节)的CRC32校验,在计算时先把这个字段写作0处理
204保留,必须是0
248当前LBA(这个分区表头的位置)
328备份LBA(另一个分区表头的位置)
408第一个可用于分区的LBA(主分区表的最后一个LBA+1)
488最后一个可用于分区的LBA(备份分区表的第一个LBA‐1)
5616磁盘GUID(在类unix系统中也叫UUID)
728分区表项的起始LBA(在主分区中是2)
804分区表的数量(windows是128,没用这么多页先占用空间)
844一个分区表项的大小
884分区表项的CRC32校验(计算的是所有分区表项的校验和即128*128字节)
92420保留,剩余字节必须是0(420是针对512字节的LBA磁盘)

LBA 2-33

LBA2‐33的位置存放的是分区表项,分区表项的结构如下

起始字节偏移量内容
016分区类型GUID
1616分区GUID
328起始LBA(小端格式)
408末尾LBA
488属性标签
5272分区名

GUID为固定值,以下列举常见几种

在这里插入图片描述在这里插入图片描述

分区属性:低位4字节表示与主分区类型无关的属性,高位4字节表示与主分区类型有关的属性

BIT解释
0系统分区
1EFI隐藏分区
2传统的BIOS的可引导分区标志
60只读
62隐藏
63不自动挂载,也就是不自动分配盘符

python生成GPT分区表

使用python脚本生成gpt分区表

gen_gpt.py

#!/usr/bin/env python2

import binascii
import uuid
from struct import pack, unpack

import sys


OS_TYPES = {
    0x00: 'Empty',
    0xEE: 'GPT Protective',
    0xFF: 'UEFI System Partition'
}

PARTITION_TYPE_GUIDS = {
    '024DEE41-33E7-11D3-9D69-0008C781F39F': 'Legacy MBR',
    'C12A7328-F81F-11D2-BA4B-00A0C93EC93B': 'EFI System Partition',
    '21686148-6449-6E6F-744E-656564454649': 'BIOS boot partition',
    '0FC63DAF-8483-4772-8E79-3D69D8477DE4': 'Linux filesystem data',
    '4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709': 'Root partition (x86-64)',
    '0657FD6D-A4AB-43C4-84E5-0933C84B4F4F': 'Swap partition',
    '7C3457EF-0000-11AA-AA11-00306543ECAC': 'Apple APFS'
}

def decode_guid(guid_as_bytes):
    return uuid.UUID(bytes_le=guid_as_bytes)

def nts_to_str(buf):
    s = buf.decode('utf-16')
    return s.split('\0', 1)[0]

def decode_gpt_partition_type_guid(guid):
    if isinstance(guid, uuid.UUID):
        guid = str(guid)

    guid = guid.upper()
    return PARTITION_TYPE_GUIDS.get(guid, "?")

def decode_gpt_partition_entry_attribute(attribute_value):
    r = []
    if (attribute_value & 0x1):
        r.append("Requitted Partition")
    if (attribute_value & 0x2):
        r.append("No Block Io Protocal")
    if (attribute_value & 0x4):
        r.append("Legacy BIOS Bootable")
    return r


def decode_gpt_partition_entry(data):
    (partition_type_guid,
     unique_partition_guid,
     starting_lba,
     ending_lba,
     attributes,
     partition_name) = unpack('< 16s 16s Q Q Q 72s', data[0:128])
    return GPTPartitionEntry(partition_type_guid,
                             unique_partition_guid,
                             starting_lba,
                             ending_lba,
                             attributes,
                             partition_name)

def encode_gpt_partition_entry(gpt_partition_entry):  
    data = pack('<16s 16s Q Q Q 72s',
		gpt_partition_entry.partition_type_guid_raw,
		gpt_partition_entry.unique_partition_guid_raw, 
		gpt_partition_entry.starting_lba,        
		gpt_partition_entry.ending_lba,        
		gpt_partition_entry.attributes_raw,
		gpt_partition_entry.partition_name_raw)
    return data



def encode_gpt_partition_entry_array(gpt_partition_entries, size, count):
    data  = bytearray()
    for i in range(0, count):
        d = encode_gpt_partition_entry(gpt_partition_entries[i])
        data.extend(d)
        if len(d) < size:
            data.extend(bytearray(size - len(d)))
    return bytes(data)

def calculate_partition_entry_array_crc32(data):
    return binascii.crc32(data) & 0xffffffff


class GPTPartitionEntry():
    def __init__(
        self,
        partition_type_guid,
        unique_partition_guid,
        starting_lba,
        ending_lba,
        attributes,
        partition_name):
        self.partition_type_guid_raw = partition_type_guid
        self.partition_type_guid = decode_guid(partition_type_guid)
        self.partition_type = decode_gpt_partition_type_guid(self.partition_type_guid)
        self.unique_partition_guid_raw = unique_partition_guid
        self.unique_partition_guid = decode_guid(unique_partition_guid)
        self.starting_lba = starting_lba
        self.ending_lba = ending_lba
        self.attributes_raw = attributes
        self.attributes = decode_gpt_partition_entry_attribute(attributes)
        self.partition_name_raw =  partition_name
        self.partition_name = nts_to_str(partition_name)

    def is_empty(self):
        return all(x == 0 for x in self.partition_type_guid_raw)

class GPTheader():
    def __init__(self,
                signature,
                revision,
                header_size,
                header_crc32,
                reserved,
                my_lba,
                alternate_lba,
                first_usable_lba,
                last_usable_lba,
                disk_guid,
                partition_entry_lba,
                number_of_partition_entries,
                size_of_partition_entry,
                partition_entry_array_crc32):
        self.signature = signature
        self.revision = revision
        self.header_size = header_size
        self.header_crc32 = header_crc32
        self.reserved = reserved
        self.my_lba = my_lba
        self.alternate_lba = alternate_lba
        self.first_usable_lba = first_usable_lba
        self.last_usable_lba = last_usable_lba
        self.disk_guid = disk_guid
        self.partition_entry_lba = partition_entry_lba
        self.number_of_partition_entries = number_of_partition_entries
        self.size_of_partition_entry = size_of_partition_entry
        self.partition_of_entry_array_crc32 = partition_entry_array_crc32 

    def is_valid(self):
        return self.signature == 'EFI PART'.encode('ascii')

    def calculate_header_crc32(self):
        header_crc32_input = pack('<8s 4s I I 4s Q Q Q Q 16s Q I I I',
                                      self.signature,
                                      self.revision,
                                      self.header_size,
                                      0,
                                      self.reserved,
                                      self.my_lba,
                                      self.alternate_lba,
                                      self.first_usable_lba,
                                      self.last_usable_lba,
                                      self.disk_guid,
                                      self.partition_entry_lba,
                                      self.number_of_partition_entries,
                                      self.size_of_partition_entry,
                                      self.partition_entry_array_crc32)
        return binascii.crc32(header_crc32_input) & 0xffffffff


def encode_gpt_header(gpt_header):
    data = pack(
                '< 8s 4s I I 4s Q Q Q Q 16s Q I I I',
                gpt_header.signature,
                gpt_header.revision,
                gpt_header.header_size,
                gpt_header.header_crc32,
                gpt_header.reserved,
                gpt_header.my_lba,
                gpt_header.alternate_lba,
                gpt_header.first_usable_lba,
                gpt_header.last_usable_lba,
                gpt_header.disk_guid,
                gpt_header.partition_entry_lba,
                gpt_header.number_of_partition_entries,
                gpt_header.size_of_partition_entry,
                gpt_header.partition_entry_array_crc32)
    return data

def decode_gpt_header(gpt_header):
    (signature,
     revision,
     header_size,
     header_crc32,
     reserved,
     my_lba,
     alternate_lba,
     first_usable_lba,
     last_usable_lba,
     disk_guid,
     partition_entry_lba,
     number_of_partition_entrires,
     size_of_partition_entry,
     partition_entry_array_crc32) = unpack(
         '< 8s 4s I I 4s Q Q Q Q 16s Q I I I',
         data[0:92]
     )
    gpt_header = GPTheader(signature,
                            revision,      
		            header_size,      
			    header_crc32,
                            reserved,
                            my_lba,
                            alternate_lba,
                            first_usable_lba,
                            last_usable_lba,
                            disk_guid,
                            partition_entry_lba,      
			    number_of_partition_entries,
                            size_of_partition_entry,
                            partition_entry_array_crc32)
    return gpt_header

def create_empty_gpt_entry():
    partition_type_guid = b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    unique_partition_guid = b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    starting_lba = 0
    ending_lba = 0
    attributes = 0
    partition_name = "\x00\x00".encode('utf-16')[2:]
    print(partition_name)

    entry = GPTPartitionEntry(partition_type_guid, unique_partition_guid,
                                starting_lba,
                                ending_lba,
                                attributes,
                                partition_name)
    return entry

def create_gpt_entry(start_lba, end_lba, name):
    partition_type_guid = uuid.uuid4().bytes
    unique_partition_guid = uuid.uuid4().bytes
    starting_lba = start_lba
    ending_lba = end_lba
    attributes = 0
    partition_name = name.decode("utf-8").encode('utf-16')[2:]

    entry = GPTPartitionEntry(partition_type_guid,
                              unique_partition_guid,
                              starting_lba,
                              ending_lba,
                              attributes,
                              partition_name)
    return entry


def complete_gpt_entries(entrylist):
    an = create_empty_gpt_entry()
    for i  in range(len(entrylist), 0x80, 1):
        entrylist.append(an)

def create_gpt_header(current_lba):
    signature = b"EFI PART"
    revision = b"\x00\x00\x01\x00"
    header_size = 0x5c
    header_crc32 = 0
    reserved = b"\x00\x00\x00\x00"
    my_lba = current_lba
    alternate_lba = 0
    first_usable_lba = 34
    last_usable_lba = 0
    disk_guid = uuid.uuid4().bytes
    partition_entry_lba = 2
    number_of_partition_entries = 0x80
    size_of_partition_entry = 0x80
    partition_entry_array_crc32 = 0
    hdr = GPTheader(signature, revision, header_size, header_crc32, reserved, my_lba,
                    alternate_lba, first_usable_lba, last_usable_lba, disk_guid,
                   partition_entry_lba, number_of_partition_entries, size_of_partition_entry,
                   partition_entry_array_crc32)

    return hdr

class MBRfilling():
    def __init__(self, boot_indicator, start_head, start_sector, start_cylinder, partion_type, 
                 end_head, end_sector, end_cylinder, partition_reset, partition_sectors):
        self.boot_indicator = boot_indicator
        self.start_head = start_head
        self.start_sector = start_sector
        self.start_cylinder = start_cylinder
        self.partion_type = partion_type
        self.end_head = end_head
        self.end_sector = end_sector
        self.end_cylinder = end_cylinder
        self.partition_reset = partition_reset
        self.partition_sectors = partition_sectors
        

def encode_mbr_pack(mbr_pack):
    data = pack('< B B B B B B B B I I',
                mbr_pack.boot_indicator, mbr_pack.start_head, mbr_pack.start_sector, mbr_pack.start_cylinder,
                mbr_pack.partion_type, mbr_pack.end_head, mbr_pack.end_sector, mbr_pack.end_cylinder, mbr_pack.partition_reset, mbr_pack.partition_sectors
                )
    return data

def mbr_partition_pack(sectors):
    boot_indicator = 0x00
    start_head = 0x00
    start_sector = 0x02
    start_cylinder = 0x00
    partion_type = 0xee
    end_head = 0xff
    end_sector = 0xff
    end_cylinder = 0xff
    partition_reset = 0x0001
    partition_sectors = sectors
    mbr_pack = MBRfilling(boot_indicator, start_head, start_sector, start_cylinder, partion_type,
                          end_head, end_sector, end_cylinder, partition_reset, partition_sectors)

    data = encode_mbr_pack(mbr_pack)
    return data


def create_mbr():
    mbr_data = bytearray()    
    mbr_data.extend(bytearray(0x1be))
    mbr_partition_data = mbr_partition_pack(0x01dacbff)
    mbr_data.extend(mbr_partition_data)
    mbr_data.extend(bytearray(48))
    end_data = pack('< B B', 0x55, 0xaa)
    mbr_data.extend(end_data)
    return mbr_data    


def create(back_lba, alternate_lba, entrylist):
    complete_gpt_entries(entrylist)

    entriesdata = encode_gpt_partition_entry_array(entrylist, 0x80, 0x80)

    hdr = create_gpt_header(1)
    hdr.alternate_lba = alternate_lba 
    hdr.last_usable_lba = alternate_lba - 33
    hdr.partition_entry_array_crc32 = calculate_partition_entry_array_crc32(entriesdata)
    hdr.header_crc32 = hdr.calculate_header_crc32()


    gptdata = encode_gpt_header(hdr)

    mbrdata = create_mbr()
    #gpt main
    maindata = bytearray()
    #mbr
    #maindata.extend(bytearray(0x200))
    maindata.extend(mbrdata)
    #gpt header
    maindata.extend(gptdata)
    maindata.extend(bytearray(0x200 - len(gptdata)))
    #gpt rable
    maindata.extend(entriesdata)

    hdr.my_lba = alternate_lba 
    hdr.alternate_lba = 1
    hdr.partition_entry_array_crc32 = calculate_partition_entry_array_crc32(entriesdata)
    hdr.header_crc32 = hdr.calculate_header_crc32()

    gptdata = encode_gpt_header(hdr)
    #gpt backup
    backdata = bytearray()
    backdata.extend(entriesdata)
    #gpt header
    backdata.extend(gptdata)
    backdata.extend(bytearray(0x200 - len(gptdata)))
    #gpt table

    
    return (bytes(maindata), bytes(backdata))

def parse_conf(path, entrylist):
    maxsize = 0
    partition_num = 0
    with open(path, "rb") as f:
         items = f.readlines()

    for item in items:
        (ispart, name, fstype, starts, stops, crop) = item.split(b':')
        if int(ispart) == 1:
            partition_num = partition_num + 1
            if name.find('/') != -1:
                name = name[:name.find(b'/')]

            entry = create_gpt_entry(int(starts[:-1]), int(stops[:-1]), name)
            entrylist.append(entry)
            maxsize = stops[:-1]
    return (int(maxsize)+33, int(partition_num))

                                              

if __name__ == '__main__':
    if len(sys.argv) != 4:
        print("Error: args number is not 3")
        print("Usage: sys.argv[0] gpt.conf main_img")
        sys.exit(1)

    path = sys.argv[1]
    main_img = sys.argv[2]
    back_img = sys.argv[3]
    entrylist = []
    (alternate_lba, back_lba)  = parse_conf(path, entrylist)
    print(alternate_lba)
    print(back_lba)
    (main_data, back_data) = create(back_lba, alternate_lba, entrylist)

    create_mbr()
    with open(main_img, "wb") as f:
        f.write(main_data)
    with open(back_img, "wb") as f:
        f.write(back_data)

gen_gpt.py 会解析分区表配置文件生成主分区表以及备份分区表
配置文件的示例如下
gpt配置文件

gpt_partition.conf

1:uboot/vfat:none:34s:262144s:1
1:system:ext4:262145s:31116254s:1

可使用如下命令生成分区表

python gen_gpt.py gpt_partition.conf main_partition.img back_partition.img

gpt分区表实例

主分区表

liefyuan@ubuntu:~/work/gpt$ hexdump main_partition.img 
0000000 0000 0000 0000 0000 0000 0000 0000 0000
*
00001c0 0002 ffee ffff 0001 0000 cbff 01da 0000
00001d0 0000 0000 0000 0000 0000 0000 0000 0000
*
00001f0 0000 0000 0000 0000 0000 0000 0000 aa55
0000200 4645 2049 4150 5452 0000 0001 005c 0000
0000210 9229 830f 0000 0000 0001 0000 0000 0000
0000220 cbff 01da 0000 0000 0022 0000 0000 0000
0000230 cbde 01da 0000 0000 8c98 f34d 36ef 5645
0000240 8799 e483 2578 f760 0002 0000 0000 0000
0000250 0080 0000 0080 0000 fb56 8758 0000 0000
0000260 0000 0000 0000 0000 0000 0000 0000 0000
*
0000400 a05e fbd4 a7f9 8e40 6cbd 9ecd cf49 9ba0
0000410 2db5 fb66 40aa 9543 8a86 be7d 45ae 366c
0000420 0022 0000 0000 0000 0000 0004 0000 0000
0000430 0000 0000 0000 0000 0075 0062 006f 006f
0000440 0074 0000 0000 0000 0000 0000 0000 0000
0000450 0000 0000 0000 0000 0000 0000 0000 0000
*
0000480 0ed5 4faf 8ed7 504b 3a8f 2ddc 0f60 5482
0000490 aa68 0ab5 dbda 6f4c b290 51f3 fe6a 23dd
00004a0 0001 0004 0000 0000 cbde 01da 0000 0000
00004b0 0000 0000 0000 0000 0073 0079 0073 0074
00004c0 0065 006d 0000 0000 0000 0000 0000 0000
00004d0 0000 0000 0000 0000 0000 0000 0000 0000
*
0004400

备份分区表

liefyuan@ubuntu:~/work/gpt$ hexdump back_partition.img 
0000000 a05e fbd4 a7f9 8e40 6cbd 9ecd cf49 9ba0
0000010 2db5 fb66 40aa 9543 8a86 be7d 45ae 366c
0000020 0022 0000 0000 0000 0000 0004 0000 0000
0000030 0000 0000 0000 0000 0075 0062 006f 006f
0000040 0074 0000 0000 0000 0000 0000 0000 0000
0000050 0000 0000 0000 0000 0000 0000 0000 0000
*
0000080 0ed5 4faf 8ed7 504b 3a8f 2ddc 0f60 5482
0000090 aa68 0ab5 dbda 6f4c b290 51f3 fe6a 23dd
00000a0 0001 0004 0000 0000 cbde 01da 0000 0000
00000b0 0000 0000 0000 0000 0073 0079 0073 0074
00000c0 0065 006d 0000 0000 0000 0000 0000 0000
00000d0 0000 0000 0000 0000 0000 0000 0000 0000
*
0004000 4645 2049 4150 5452 0000 0001 005c 0000
0004010 072f 2af5 0000 0000 cbff 01da 0000 0000
0004020 0001 0000 0000 0000 0022 0000 0000 0000
0004030 cbde 01da 0000 0000 8c98 f34d 36ef 5645
0004040 8799 e483 2578 f760 0002 0000 0000 0000
0004050 0080 0000 0080 0000 fb56 8758 0000 0000
0004060 0000 0000 0000 0000 0000 0000 0000 0000
*
0004200

gpt分区表查看

一般fdisk适用于MBR分区,而gdisk使用GPT分区.gdisk命令常用格式如下

gdisk 设备文件名(绝对路径)

示例如下

$ gdisk system.img
GPT fdisk (gdisk) version 1.0.5
Warning! Disk size is smaller than the main header indicates! Loading
secondary header from the last sector of the disk! You should use 'v' to
verify disk integrity, and perhaps options on the experts' menu to repair
the disk.
Caution: invalid backup GPT header, but valid main header; regenerating
backup header from main header.
Warning! Error 25 reading partition table for CRC check!
Warning! One or more CRCs don't match. You should repair the disk!
Main header: OK
Backup header: ERROR
Main partition table: OK
Backup partition table: ERROR
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: damaged
****************************************************************************
Caution: Found protective or hybrid MBR and corrupt GPT. Using GPT, but disk
verification and recovery are STRONGLY recommended.
****************************************************************************
Command (? for help): print
Disk system.img: 526336 sectors, 257.0 MiB
Sector size (logical): 512 bytes
Disk identifier (GUID): CB0A9716‐409B‐FD40‐8DD9‐5FB082604799
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 62160862
Partitions will be aligned on 2048‐sector boundaries
Total free space is 2014 sectors (1007.0 KiB)
Number Start (sector) End (sector) Size Code Name
1 2048 2099199 1024.0 MiB FFFF system_A
2 2099200 4196351 1024.0 MiB FFFF system_B
3 4196352 62160862 27.6 GiB FFFF user
Command (? for help):

查看百问网T113-s3固件

主芯片是全志T113-s3,32位,双核ARM A7

liefyuan@ubuntu:~/work/img-test$ gdisk 100ask-t113-pro_sdcard.img 
GPT fdisk (gdisk) version 1.0.3

Partition table scan:
  MBR: hybrid
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with hybrid MBR; using GPT.

Command (? for help): print
Disk 100ask-t113-pro_sdcard.img: 1154152 sectors, 563.6 MiB
Sector size (logical): 512 bytes
Disk identifier (GUID): 6BDDD82D-66B5-4034-95C6-FB3F1EF3C922
Partition table holds up to 128 entries
Main partition table begins at sector 2048 and ends at sector 2079
First usable sector is 35392, last usable sector is 1154118
Partitions will be aligned on 64-sector boundaries
Total free space is 7 sectors (3.5 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1           35392           39487   2.0 MiB     8300  boot-resource
   2           39488           39743   128.0 KiB   8300  env
   3           39744           39999   128.0 KiB   8300  env-redund
   4           40000          105535   32.0 MiB    8300  boot
   5          105536          629823   256.0 MiB   8300  rootfs
   6          629824         1154111   256.0 MiB   8300  share

Command (? for help): 

liefyuan@ubuntu:~/work/img-test$ fdisk 100ask-t113-pro_sdcard.img 

Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

A hybrid GPT was detected. You have to sync the hybrid MBR manually (expert command 'M').

Command (m for help): print

Disk 100ask-t113-pro_sdcard.img: 563.6 MiB, 590925824 bytes, 1154152 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 6BDDD82D-66B5-4034-95C6-FB3F1EF3C922

Device                       Start     End Sectors  Size Type
100ask-t113-pro_sdcard.img1  35392   39487    4096    2M Linux filesystem
100ask-t113-pro_sdcard.img2  39488   39743     256  128K Linux filesystem
100ask-t113-pro_sdcard.img3  39744   39999     256  128K Linux filesystem
100ask-t113-pro_sdcard.img4  40000  105535   65536   32M Linux filesystem
100ask-t113-pro_sdcard.img5 105536  629823  524288  256M Linux filesystem
100ask-t113-pro_sdcard.img6 629824 1154111  524288  256M Linux filesystem

Command (m for help): 

查看友善之臂nanopi-m1-plus官方固件

主芯片是全志H3,32位,四核ARM A7

liefyuan@ubuntu:~/work/img-test$ gdisk nanopi-m1-plus_sd_ubuntu-tft-xenial_4.14_armhf_20210425.img 
GPT fdisk (gdisk) version 1.0.3

Partition table scan:
  MBR: MBR only
  BSD: not present
  APM: not present
  GPT: not present


***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format
in memory. THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by
typing 'q' if you don't want to convert your MBR partitions
to GPT format!
***************************************************************


Warning! Secondary partition table overlaps the last partition by
1626041 blocks!
You will need to delete this partition or resize it in another utility.

Command (? for help): print
Disk nanopi-m1-plus_sd_ubuntu-tft-xenial_4.14_armhf_20210425.img: 958568 sectors, 468.1 MiB
Sector size (logical): 512 bytes
Disk identifier (GUID): D221F4BC-40C0-4E19-93ED-A5C1FE413A2A
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 958534
Partitions will be aligned on 2048-sector boundaries
Total free space is 49118 sectors (24.0 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1           49152          131071   40.0 MiB    0700  Microsoft basic data
   2          131072         2516991   1.1 GiB     8300  Linux filesystem
   3         2516992         2584575   33.0 MiB    8300  Linux filesystem

Command (? for help): ^C
liefyuan@ubuntu:~/work/img-test$ fdisk nanopi-m1-plus_sd_ubuntu-tft-xenial_4.14_armhf_20210425.img 

Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): print
Disk nanopi-m1-plus_sd_ubuntu-tft-xenial_4.14_armhf_20210425.img: 577.9 MiB, 605933568 bytes, 1183464 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device                                                       Boot   Start     End Sectors  Size Id Type
nanopi-m1-plus_sd_ubuntu-tft-xenial_4.14_armhf_20210425.img1        49152  131071   81920   40M  b W95 FAT32
nanopi-m1-plus_sd_ubuntu-tft-xenial_4.14_armhf_20210425.img2       131072 2516991 2385920  1.1G 83 Linux
nanopi-m1-plus_sd_ubuntu-tft-xenial_4.14_armhf_20210425.img3      2516992 2584575   67584   33M 83 Linux

Command (m for help): ^C

查看荣品RV1126固件

主芯片瑞芯微RV1126,32位,双核ARM A7

liefyuan@ubuntu:~/work/img-test$ fdisk update-pro-rv1126-5-720-1280-20220505.img 

Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0xb57e8937.

Command (m for help): print
Disk update-pro-rv1126-5-720-1280-20220505.img: 820.9 MiB, 860753920 bytes, 1681160 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xb57e8937

Command (m for help): ^C
Do you really want to quit? 

liefyuan@ubuntu:~/work/img-test$ gdisk update-pro-rv1126-5-720-1280-20220505.img 
GPT fdisk (gdisk) version 1.0.3

Warning: File size is not a multiple of 512 bytes! Misbehavior is likely!
Warning: File size is not a multiple of 512 bytes! Misbehavior is likely!
Warning: File size is not a multiple of 512 bytes! Misbehavior is likely!
Partition table scan:
  MBR: not present
  BSD: not present
  APM: not present
  GPT: not present

Creating new GPT entries.

Command (? for help): print
Disk update-pro-rv1126-5-720-1280-20220505.img: 2136216 sectors, 1.0 GiB
Sector size (logical): 512 bytes
Disk identifier (GUID): 893418C0-ABD5-4E1A-98F0-6AF69C7C472A
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 2136182
Partitions will be aligned on 2048-sector boundaries
Total free space is 2136149 sectors (1.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name

Command (? for help): ^[[^H^H^H^H^C

查看f1c200s固件

主芯片全志F1c200s,32位,ARM11

liefyuan@ubuntu:~/work/img-test$ fdisk sysimage-sdcard.img 

Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): print
Disk sysimage-sdcard.img: 109 MiB, 114294784 bytes, 223232 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device               Boot Start    End Sectors  Size Id Type
sysimage-sdcard.img1         16   2047    2032 1016K  0 Empty
sysimage-sdcard.img2 *     2048  18431   16384    8M  c W95 FAT32 (LBA)
sysimage-sdcard.img3      18432 223231  204800  100M 83 Linux

Command (m for help): ^C
liefyuan@ubuntu:~/work/img-test$ gdisk sysimage-sdcard.img 
GPT fdisk (gdisk) version 1.0.3

Partition table scan:
  MBR: MBR only
  BSD: not present
  APM: not present
  GPT: not present


***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format
in memory. THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by
typing 'q' if you don't want to convert your MBR partitions
to GPT format!
***************************************************************


Warning! Secondary partition table overlaps the last partition by
33 blocks!
You will need to delete this partition or resize it in another utility.

Command (? for help): print
Disk sysimage-sdcard.img: 223232 sectors, 109.0 MiB
Sector size (logical): 512 bytes
Disk identifier (GUID): 1CBF2B75-23D9-4529-AD2B-5A15A4833D26
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 223198
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   2            2048           18431   8.0 MiB     0700  Microsoft basic data
   3           18432          223231   100.0 MiB   8300  Linux filesystem

Command (? for help): ^C

目前手上的这些开发板的固件,分区类型都不是很清晰啊!

查看V3s的SD启动卡

分区:
在这里插入图片描述在这里插入图片描述

liefyuan@ubuntu:/media/liefyuan$ sudo fdisk /dev/sdb

Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): print
Disk /dev/sdb: 29.1 GiB, 31243370496 bytes, 61022208 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x28b6d4cf

Device     Boot Start      End  Sectors  Size Id Type
/dev/sdb1        2048    34815    32768   16M  6 FAT16
/dev/sdb2       34816 61022207 60987392 29.1G 83 Linux

Command (m for help): ^C 
liefyuan@ubuntu:/media/liefyuan$ sudo gdisk /dev/sdb
GPT fdisk (gdisk) version 1.0.1

Partition table scan:
  MBR: MBR only
  BSD: not present
  APM: not present
  GPT: not present


***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format
in memory. THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by
typing 'q' if you don't want to convert your MBR partitions
to GPT format!
***************************************************************


Warning! Secondary partition table overlaps the last partition by
33 blocks!
You will need to delete this partition or resize it in another utility.

Command (? for help): print
Disk /dev/sdb: 61022208 sectors, 29.1 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 3883B406-E1D8-4041-9BA1-1CA32D678B1A
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 61022174
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048           34815   16.0 MiB    0700  Microsoft basic data
   2           34816        61022207   29.1 GiB    8300  Linux filesystem

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值