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

2023-05-16

文章目录

  • GUID以及分区表
    • MBR分区方案
    • GPT 分区方案
    • GPT分区表结构
  • GPT分区表LBA
    • LBA0(MBR兼容部分)
    • LBA1
    • LBA 2-33
    • python生成GPT分区表
    • gpt分区表实例
  • gpt分区表查看
    • 查看百问网T113-s3固件
    • 查看友善之臂nanopi-m1-plus官方固件
    • 查看荣品RV1126固件
    • 查看f1c200s固件
    • 查看V3s的SD启动卡

原文: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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

【嵌入式Linux】MBR分区表 和 GPT分区表 的相关文章

  • SNMPV3的实现原理

    在snmp发展到V3版本后 xff0c 把snmp的安全性提升到一个新高度 xff0c 这同时也带来了实现上的复杂性 在02年 xff0c 03年我都曾经想进一步的了解它的实现 xff0c 但都没什么进展 这次在实现Csnmp的过程中 xf
  • ubuntu更新错误:dists/artful/main/binary-arm64/Packages 404 Not Found

    Failed to fetch http archive ubuntu com ubuntu dists artful main binary arm64 Packages 404 Not Found IP 91 189 88 162 80
  • 个人公众号开通啦!!!!

    已经开通了个人微信公众号 xff1a 编程时光机 以后会在公众号里和大家分享知识和生吞活 xff0c 欢迎大家关注 xff01 xff01
  • 小白学AI系列(一)-- AI简史

    经过一段时间的酝酿 xff0c 小白学AI系列也正是开始了 xff01 小编将从三个阶段和大家一起入门人工智能 xff0c 掌握常用机器学习算法和数据分析技巧 小编专业为数据融合方向 xff0c 也曾接触过机器学习 xff0c 但由于人工智
  • 小白学AI系列(二) -- Python模块和函数

    原文地址 xff1a 小白学AI系列 xff08 二 xff09 Python模块和函数 今天的内容是带大家学习解释性语言 Python 小编有学过一段时间的C 43 43 和Matlab 相对于二者而言 xff0c Python是作为学习
  • PX4固定翼调试校准流程及实验相关问题记录分析

    pixhawk固定翼调试流程 对于px4固件 xff0c 其对应选择的一般是qgroundcontrol地面站 xff08 APM一般使用Mission Planner xff09 本次调试的固件版本是1 6 5dev xff08 最新的固
  • Ubuntu16.04下PX4环境快速搭建及uORB通信机制

    Ubuntu16 04下的环境搭建 之前搭建PX4环境常常编译不通 xff0c cmake gcc 以及交叉编译器gcc arm none eabi的版本问题导致make固件报错 xff0c 好不容易编译通过了 xff0c 在进行安装jMA
  • PX4固件通过UART连接串口读取超声波,和树莓派3通信

    添加串口读取程序 首先在Firmware msg文件夹下添加rw uart msg span class hljs keyword char span span class hljs number 5 span datastr span c
  • PX4自主飞行相关问题

    调试入坑 赶在回去之前把10月1日新校区试飞相关问题记录一下 首先是调试相关问题 调试具体流程 在校准遥控器时经常出现校准一半就停止的问题 xff0c 期初认为是固件问题 xff0c 换了1 6 5 1 6 3 xff0c 1 5 5三个固
  • PID控制器及其C++实现

    PID控制器原理 PID控制器实际上是对偏差的控制 其原理图如下 其数学的表达如下 u x 61 K p e r r t 43 1 T e r r t d t 43 T D d e r r t d t u x
  • Oracle Systimestamp 函数

    在Oracle PLSQL中 xff0c Systimestamp 函数返回本机数据库上当前系统日期和时间 包括微秒和时区 Systimestamp 函数的语法是 xff1a systimestamp 应用于 xff1a Oracle 9i
  • px4源码解读之fw_att_control

    目录 程序和控制流程源码解读总结 程序和控制流程 个人简单的总结了一下整个程序的流程如下 整个的控制流程图可以在官网中找到 源码解读 在解读源码之前 需要提几个公式 第一个就是协调转弯中的偏航控制 也就是流程图中为什么输入是空速 p 61
  • 安装Mavlink generator出现UnicodeEncodeError错误

    最近在看mavlink 在执行官网的操作时出现了问题 问题如下 span class hljs constant Exception span span class hljs keyword in span span class hljs
  • mc_att_control基础知识:向量运算和罗德里格斯旋转

    向量的叉乘和点乘 在我们的mc att control中有我们的向量的点乘和叉乘 一般遇到的都是三维的运算 S O 3 S O 3 李群 向量点乘 假设向量 a 61 a 1 a 2 a 3
  • 低通滤波器和高通滤波器的程序实现原理推导

    傅立叶变换 拉普拉斯变换和Z变换 对于信号分析而言 傅立叶变换是必不可少的 我们都知道傅立叶变换是把系统从时域变换到频域进行分析 那么拉普拉斯变换和Z变换是干什么的 简单的来说 由于傅里叶变换的收敛有一个狄利克雷条件 xff0c 要求信号绝
  • PX4源码解读之fw_pos_control_l1

    固定翼的位置控制是一个很重要问题 它不同于旋翼的控制 需要对速度和高度进行解耦控制 并且其不能像旋翼那样进行悬停 其转弯的时候有一个转弯半径 本博客不会对源码进行详细的解读 主要是分享一些自己读源码时的资料 自己读的过程中也有注释 想要的同
  • 四元数表示旋转的理解

    哈密尔顿 为了纪念四元数的发明者哈密尔顿 爱尔兰于1943年11月15日发行了下面这张邮票 哈密尔顿简直是个天才 哈密尔顿从小到进入大学之前没有进过学校读书 xff0c 他的教育是靠叔父传授以及自学 他找到了法国数学家克莱罗 xff08 C
  • mc_att_control源码解析

    目录 源码分析内环控制外环控制 之前写了博客分析了一下旋翼姿态控制的基础知识 mc att control基础知识 这次就对照代码将整个旋翼姿态控制过程呈现一遍 先看一下整个程序的框图 从图中可以看到 实际上整个控制分成内外两个环进行控制
  • PX4下载指定版本代码和刷固件的三种方式

    由于之前下载的是1 7版本的代码 现在v5版本的px4需要最新的代码固件 因此这里记录一下 查看自己代码版本 查看自己仓库代码版本的命令如下 git describe always tags 输出 v1 7 0 rc3 9 g0e1c7eb
  • Python怎么调用matlab的

    文章目录 环境的安装安装合适的python环境安装用于 Python 的 MATLAB 引擎 API 环境的安装 安装合适的python环境 研究这个也是在知乎上突然看到的 xff0c 以前python写的多 xff0c 现在由于工作需要

随机推荐