{"id":885,"date":"2025-05-13T18:48:36","date_gmt":"2025-05-13T10:48:36","guid":{"rendered":"https:\/\/vm1.go2see.me\/?p=885"},"modified":"2025-05-13T20:25:40","modified_gmt":"2025-05-13T12:25:40","slug":"gpt","status":"publish","type":"post","link":"https:\/\/vm1.go2see.me\/?p=885","title":{"rendered":"GPT"},"content":{"rendered":"<h1>Glossary:<\/h1>\n<ul>\n<li>UUID -(Universally Unique Identifier)<\/li>\n<li>GUID &#8211; (Globally Unique ID)<\/li>\n<li>EFI &#8211; (Extensible Firmware Interface)<\/li>\n<li>UEFI &#8211; (Unified EFI) &#8211; EFI evolution<\/li>\n<li>GPT (GUID Partition Table) &#8211; it is the EFI standard part<\/li>\n<li>partitions &#8211; lists of available partitions (defined at u-boot):<br \/>\n.\/include\/configs\/{target}.h<\/li>\n<\/ul>\n<h1>Introduction:<\/h1>\n<p>This document describes the GPT partition table format and usage of the gpt command in u-boot.<\/p>\n<h1>UUID introduction:<\/h1>\n<p>GPT for marking disks\/partitions is using the UUID. It is supposed to be a globally unique value. A UUID is a 16-byte (128-bit) number. The number of theoretically possible UUIDs is therefore about 3 x 10^38.<br \/>\nMore often UUID is displayed as 32 hexadecimal digits, in 5 groups, separated by hyphens, in the form 8-4-4-4-12 for a total of 36 characters<br \/>\n(32 digits and 4 hyphens)<\/p>\n<p>For instance, GUID of Basic data partition: EBD0A0A2-B9E5-4433-87C0-68B6B72699C7 and GUID of Linux filesystem data: 0FC63DAF-8483-4772-8E79-3D69D8477DE4<\/p>\n<p>Historically there are 5 methods to generate this number. The oldest one is combining machine&#8217;s MAC address and timer (epoch) value.<\/p>\n<p>Successive versions are using MD5 hash, random numbers and SHA-1 hash. All major OSes and programming languages are providing libraries to compute UUID (e.g.<br \/>\nuuid command line tool).<\/p>\n<h1>GPT brief explanation:<\/h1>\n<pre><code>Layout:\n----------------------------------------------------------\nLBA 0      |Protective MBR                   | legacy MBR\n----------------------------------------------------------\nLBA 1      |Primary GPT Header               | Primary\n-----------|---------------------------------| GPT\nLBA 2      |Entry 1|Entry 2| Entry 3| Entry 4|\n-----------|---------------------------------|\nLBA 3~33   |Entries 5 ~ 128                  |\n           |                                 |\n           |                                 |\n----------------------------------------------------------\nLBA 34     |Partition 1                      |Partitions\n           |                                 |\n           |---------------------------------|\n           |Partition 2                      |\n           |                                 |\n           |---------------------------------|\n           |Partition n                      |\n           |                                 |\n----------------------------------------------------------\nLBA -34    |Entry 1|Entry 2| Entry 3| Entry 4| Backup\n-----------|---------------------------------| GPT\nLBA -33    |Entries 5 ~ 128                  |\n           |                                 |\n           |                                 |\nLBA -2     |                                 |\n-----------|---------------------------------|\nLBA -1     |Backup GPT Header                |\n----------------------------------------------------------<\/code><\/pre>\n<p>For a legacy reasons, GPT&#8217;s LBA 0 sector has a MBR structure. It is called &quot;protective MBR&quot;.<br \/>\nIts first partition entry ID has 0xEE value, and disk software, which is not handling the GPT sees it as a storage device without free space.<\/p>\n<p>It is possible to define 128 linearly placed partition entries.<\/p>\n<p>&quot;LBA -1&quot; means the last addressable block (in the mmc subsystem:<br \/>\n&quot;dev_desc-&gt;lba &#8211; 1&quot;)<\/p>\n<h2>Primary\/Backup GPT header:<\/h2>\n<pre><code>Offset  Size    Description\n\n0       8 B     Signature (\"EFI PART\", 45 46 49 20 50 41 52 54)\n8       4 B     Revision (For version 1.0, the value is 00 00 01 00)\n12      4 B     Header size (in bytes, usually 5C 00 00 00 meaning 92 bytes)\n16      4 B     CRC32 of header (0 to header size), with this field zeroed during calculation\n20      4 B     Reserved (ZERO);\n24      8 B     Current LBA (location of this header copy)\n32      8 B     Backup LBA (location of the other header copy)\n40      8 B     First usable LBA for partitions (primary partition table last LBA + 1)\n48      8 B     Last usable LBA (secondary partition table first LBA - 1)\n56      16 B    Disk GUID (also referred as UUID on UNIXes)\n72      8 B     Partition entries starting LBA (always 2 in primary copy)\n80      4 B     Number of partition entries\n84      4 B     Size of a partition entry (usually 128)\n88      4 B     CRC32 of partition array\n92      *       Reserved; must be ZERO (420 bytes for a 512-byte LBA)<\/code><\/pre>\n<p>TOTAL: 512 B<\/p>\n<p>IMPORTANT:<\/p>\n<p>GPT headers and partition entries are protected by CRC32 (the POSIX CRC32).<\/p>\n<p>Primary GPT header and Backup GPT header have swapped values of &quot;Current LBA&quot; and &quot;Backup LBA&quot; and therefore different CRC32 check-sum.<\/p>\n<p>CRC32 for GPT headers (field &quot;CRC of header&quot;) are calculated up till &quot;Header size&quot; (92), NOT 512 bytes.<\/p>\n<p>CRC32 for partition entries (field &quot;CRC32 of partition array&quot;) is calculated for the whole array entry ( Number_of_partition_entries *<br \/>\nsizeof(partition_entry_size (usually 128)))<\/p>\n<p>Observe, how Backup GPT is placed in the memory. It is NOT a mirror reflect of the Primary.<\/p>\n<pre><code>   Partition Entry Format: (128 bytes)\n   ----------------------\n   Offset  Size    Description\n   0       16 B    Partition type GUID (Big Endian)\n   16      16 B    Unique partition GUID in (Big Endian)\n   32      8  B    First LBA (Little Endian)\n   40      8  B    Last LBA (inclusive)\n   48      8  B    Attribute flags [+]\n   56      72 B    Partition name (text)\n\n   Attribute flags: (8 bytes\/64 bits)\n   Bit 0     - System partition\n   Bit 1     - Hide from EFI\n   Bit 2     - Legacy BIOS bootable\n   Bit 48-63 - Defined and used by the individual partition type\n\n   For Basic data partition type: (last 4 bits)\n   Bit 60 - Read-only\n   Bit 62 - Hidden\n   Bit 63 - Not mount<\/code><\/pre>\n<h1>Creating GPT partitions in U-Boot:<\/h1>\n<p>To restore GUID partition table one needs to:<\/p>\n<ol>\n<li>\n<p>Define partition layout in the environment.<br \/>\nFormat of partitions layout:<br \/>\n&quot;uuid_disk=&#8230;;name=u-boot,size=60MiB,uuid=&#8230;;<br \/>\nname=kernel,size=60MiB,uuid=&#8230;;&quot;<br \/>\nor<br \/>\n&quot;uuid_disk=${uuid_gpt_disk};name=${uboot_name},<br \/>\nsize=${uboot_size},uuid=${uboot_uuid};&quot;<\/p>\n<p>The fields &#8216;name&#8217; and &#8216;size&#8217; are mandatory for every partition.<br \/>\nThe field &#8216;start&#8217; is optional.<\/p>\n<p>If field &#8216;size&#8217; of the last partition is 0, the partition is extended up to the end of the device.<\/p>\n<p>The fields &#8216;uuid&#8217; and &#8216;uuid_disk&#8217; are optional if CONFIG_RANDOM_UUID is enabled. A random uuid will be used if omitted or they point to an empty\/non-existent environment variable. The environment variable will be set to the generated UUID.  The &#8216;gpt guid&#8217; command reads the current value of the uuid_disk from the GPT.<\/p>\n<p>The field &#8216;bootable&#8217; is optional, it is used to mark the GPT partition bootable (set attribute flags &quot;Legacy BIOS bootable&quot;).<br \/>\n&quot;name=u-boot,size=60MiB;name=boot,size=60Mib,bootable;name=rootfs,size=0&quot;<br \/>\nIt can be used to locate bootable disks with command &quot;part list <interface> <dev> -bootable <varname>&quot;, please check out doc\/README.distro for use.<\/p>\n<\/li>\n<li>\n<p>Define &#8216;CONFIG_EFI_PARTITION&#8217; and &#8216;CONFIG_CMD_GPT&#8217;<\/p>\n<\/li>\n<li>\n<p>From u-boot prompt type:<br \/>\ngpt write mmc 0 $partitions<\/p>\n<\/li>\n<\/ol>\n<h1>Checking (validating) GPT partitions in U-Boot:<\/h1>\n<p>Procedure is the same as above. The only change is at point 3.<\/p>\n<p>At u-boot prompt one needs to write:<br \/>\ngpt verify mmc 0 [$partitions]<\/p>\n<p>where [$partitions] is an optional parameter.<\/p>\n<p>When it is not provided, only basic checks based on CRC32 calculation for GPT header and PTEs are performed.<br \/>\nWhen provided, additionally partition data &#8211; name, size and starting offset (last two in LBA) &#8211; are compared with data defined in &#8216;$partitions&#8217; environment variable.<\/p>\n<p>After running this command, return code is set to 0 if no errors found in on non-volatile medium stored GPT.<\/p>\n<p>Following line can be used to assess if GPT verification has succeed:<\/p>\n<p>U-BOOT&gt; gpt verify mmc 0 $partitions<br \/>\nU-BOOT&gt; if test $? = 0; then echo &quot;GPT OK&quot;; else echo &quot;GPT ERR&quot;; fi<\/p>\n<h1>Renaming GPT partitions from U-Boot:<\/h1>\n<p>GPT partition names are a mechanism via which userspace and U-Boot can communicate about software updates and boot failure.  The &#8216;gpt guid&#8217;, &#8216;gpt read&#8217;, &#8216;gpt rename&#8217; and &#8216;gpt swap&#8217; commands facilitate programmatic renaming of partitions from bootscripts by generating and modifying the partitions layout string.  Here is an illustration of employing &#8216;swap&#8217; to exchange &#8216;primary&#8217; and &#8216;backup&#8217; partition names:<\/p>\n<p>U-BOOT&gt; gpt swap mmc 0 primary backup<\/p>\n<p>Afterwards, all partitions previously named &#8216;primary&#8217; will be named &#8216;backup&#8217;, and vice-versa.  Alternatively, single partitions may be renamed.  In this example, the first partition of mmc0 will be renamed to &#8216;primary&#8217;:<\/p>\n<p>U-BOOT&gt; gpt rename mmc 0 1 primary<\/p>\n<p>The GPT functionality may be tested with the &#8216;sandbox&#8217; board by creating a disk image as described under &#8216;Block Device Emulation&#8217; in doc\/arch\/index.rst:<\/p>\n<p>=&gt;host bind 0 .\/disk.raw<br \/>\n=&gt; gpt read host 0<br \/>\n[ . . . ]<br \/>\n=&gt; gpt swap host 0 name othername<br \/>\n[ . . . ]<\/p>\n<h1>Modifying GPT partition layout from U-Boot:<\/h1>\n<p>The entire GPT partition layout can be exported to an environment variable and then modified enmasse. Users can change the partition numbers, offsets, names and sizes. The resulting variable can used to reformat the device. Here is an example of reading the GPT partitions into a variable and then modifying them:<\/p>\n<p>U-BOOT&gt; gpt read mmc 0 current_partitions<br \/>\nU-BOOT&gt; env edit current_partitions<br \/>\nedit: uuid_disk=[&#8230;];name=part1,start=0x4000,size=0x4000,uuid=[&#8230;];<br \/>\nname=part2,start=0xc000,size=0xc000,uuid=[&#8230;];[ . . . ]<\/p>\n<p>U-BOOT&gt; gpt write mmc 0 $current_partitions<br \/>\nU-BOOT&gt; gpt verify mmc 0 $current_partitions<\/p>\n<h1>Partition type GUID:<\/h1>\n<p>For created partition, the used partition type GUID is PARTITION_BASIC_DATA_GUID (EBD0A0A2-B9E5-4433-87C0-68B6B72699C7).<\/p>\n<p>If you define &#8216;CONFIG_PARTITION_TYPE_GUID&#8217;, a optionnal parameter &#8216;type&#8217; can specify a other partition type guid:<\/p>\n<pre><code> \"uuid_disk=...;name=u-boot,size=60MiB,uuid=...;\nname=kernel,size=60MiB,uuid=...,\ntype=0FC63DAF-8483-4772-8E79-3D69D8477DE4;\"<\/code><\/pre>\n<p>Some strings can be also used at the place of known GUID :<br \/>\n&quot;system&quot;          = PARTITION_SYSTEM_GUID<br \/>\n(C12A7328-F81F-11D2-BA4B-00A0C93EC93B)<br \/>\n&quot;mbr&quot;             = LEGACY_MBR_PARTITION_GUID<br \/>\n(024DEE41-33E7-11D3-9D69-0008C781F39F)<br \/>\n&quot;msft&quot;            = PARTITION_MSFT_RESERVED_GUID<br \/>\n(E3C9E316-0B5C-4DB8-817D-F92DF00215AE)<br \/>\n&quot;data&quot;            = PARTITION_BASIC_DATA_GUID<br \/>\n(EBD0A0A2-B9E5-4433-87C0-68B6B72699C7)<br \/>\n&quot;linux&quot;           = PARTITION_LINUX_FILE_SYSTEM_DATA_GUID<br \/>\n(0FC63DAF-8483-4772-8E79-3D69D8477DE4)<br \/>\n&quot;raid&quot;            = PARTITION_LINUX_RAID_GUID<br \/>\n(A19D880F-05FC-4D3B-A006-743F0F84911E)<br \/>\n&quot;swap&quot;            = PARTITION_LINUX_SWAP_GUID<br \/>\n(0657FD6D-A4AB-43C4-84E5-0933C84B4F4F)<br \/>\n&quot;lvm&quot;             = PARTITION_LINUX_LVM_GUID<br \/>\n(E6D6D379-F507-44C2-A23C-238F2A3DF928)<br \/>\n&quot;u-boot-env&quot;      = PARTITION_U_BOOT_ENVIRONMENT<br \/>\n(3DE21764-95BD-54BD-A5C3-4ABE786F38A8)<\/p>\n<pre><code>\"uuid_disk=...;name=u-boot,size=60MiB,uuid=...;\nname=kernel,size=60MiB,uuid=...,type=linux;\"<\/code><\/pre>\n<p>They are also used to display the type of partition in &quot;part list&quot; command.<\/p>\n<h1>Useful info:<\/h1>\n<p>Two programs, namely: &#8216;gdisk&#8217; and &#8216;parted&#8217; are recommended to work with GPT recovery. Both are able to handle GUID partitions.<br \/>\nPlease, pay attention at -l switch for parted.<\/p>\n<p>&quot;uuid&quot; program is recommended to generate UUID string. Moreover it can decode (-d switch) passed in UUID string. It can be used to generate partitions UUID passed to u-boot environment variables.<br \/>\nIf optional CONFIG_RANDOM_UUID is defined then for any partition which environment uuid is unset, uuid is randomly generated and stored in correspond environment variable.<\/p>\n<h1>GPT<\/h1>\n<h1>\u8a5e\u5f59\u8868\uff1a<\/h1>\n<ul>\n<li>UUID -\uff08\u901a\u7528\u552f\u4e00\u8b58\u5225\u5b50\uff09<\/li>\n<li>GUID \u2013 \uff08\u5168\u57df\u552f\u4e00 ID\uff09<\/li>\n<li>EFI \u2013 \uff08\u53ef\u64f4\u5c55\u56fa\u4ef6\u4ecb\u9762\uff09<\/li>\n<li>UEFI \u2013 \uff08\u7d71\u4e00 EFI\uff09 \u2013 EFI \u7684\u6f14\u8b8a<\/li>\n<li>GPT\uff08GUID \u5206\u5340\u8868\uff09\u2014\u2014\u5b83\u662f EFI \u6a19\u6e96\u90e8\u5206<\/li>\n<li>partitions \u2013 \u53ef\u7528\u5206\u5340\u5217\u8868\uff08\u5728 u-boot \u4e2d\u5b9a\u7fa9\uff09\uff1a<br \/>\n.\/include\/configs\/{target}.h<\/li>\n<\/ul>\n<h1>\u4ecb\u7d39\uff1a<\/h1>\n<p>\u672c\u6587\u4ecb\u7d39\u4e86 u-boot \u4e2d gpt \u547d\u4ee4\u7684 GPT \u5206\u5340\u8868\u683c\u5f0f\u548c\u7528\u6cd5\u3002<\/p>\n<h1>UUID \u7c21\u4ecb\uff1a<\/h1>\n<p>\u7528\u65bc\u6a19\u8a18\u78c1\u789f\/\u5206\u5340\u7684 GPT \u4f7f\u7528 UUID\u3002\u5b83\u61c9\u8a72\u662f\u4e00\u500b\u5168\u57df\u552f\u4e00\u7684\u503c\u3002UUID \u662f\u4e00\u500b 16 \u4f4d\u5143\u7d44 \uff08128 \u4f4d\uff09 \u7684\u6578\u4f4d\u3002\u56e0\u6b64,\u7406\u8ad6\u4e0a\u53ef\u80fd\u7684 UUID \u6578\u91cf\u7d04\u70ba 3 x 10^38\u3002<br \/>\n\u66f4\u5e38\u898b\u7684\u662f,UUID \u986f\u793a\u70ba 32 \u500b\u5341\u516d\u9032\u4f4d\u6578\u4f4d,\u5206\u70ba 5 \u500b\u7d44,\u7528\u9023\u5b57\u5143\u5206\u9694,\u683c\u5f0f\u70ba 8-4-4-4-12,\u7e3d\u5171 36 \u500b\u5b57\u5143<br \/>\n\uff0832 \u4f4d\u6578\u4f4d\u548c 4 \u500b\u9023\u5b57\u5143\uff09<\/p>\n<p>\u4f8b\u5982,\u57fa\u672c\u6578\u64da\u5206\u5340\u7684 GUID\uff1aEBD0A0A2-B9E5-4433-87C0-68B6B72699C7 \u548c Linux \u6587\u4ef6\u7cfb\u7d71\u6578\u64da\u7684 GUID\uff1a0FC63DAF-8483-4772-8E79-3D69D8477DE4<\/p>\n<p>\u6b77\u53f2\u4e0a\u67095\u7a2e\u65b9\u6cd5\u53ef\u4ee5\u751f\u6210\u9019\u500b\u6578\u4f4d\u3002\u6700\u65e9\u7684\u662f\u5c07\u8a08\u7b97\u6a5f\u7684 MAC \u4f4d\u5740\u548c\u8a08\u6642\u5668 \uff08epoch\uff09 \u503c\u7d44\u5408\u5728\u4e00\u8d77\u3002<\/p>\n<p>\u5f8c\u7e8c\u7248\u672c\u4f7f\u7528 MD5 \u54c8\u5e0c\u3001\u96a8\u6a5f\u6578\u548c SHA-1 \u54c8\u5e0c\u3002\u6240\u6709\u4e3b\u8981\u7684\u4f5c\u7cfb\u7d71\u548c\u7a0b\u5f0f\u8a2d\u8a08\u8a9e\u8a00\u90fd\u63d0\u4f9b\u4e86\u8a08\u7b97 UUID \u7684\u5eab\uff08\u4f8b\u5982<br \/>\nuuid \u547d\u4ee4\u884c\u5de5\u5177\uff09\u3002<\/p>\n<h1>GPT\u7c21\u8981\u8aaa\u660e\uff1a<\/h1>\n<pre><code>Layout:\n----------------------------------------------------------\nLBA 0      |Protective MBR                   | legacy MBR\n----------------------------------------------------------\nLBA 1      |Primary GPT Header               | Primary\n-----------|---------------------------------| GPT\nLBA 2      |Entry 1|Entry 2| Entry 3| Entry 4|\n-----------|---------------------------------|\nLBA 3~33   |Entries 5 ~ 128                  |\n           |                                 |\n           |                                 |\n----------------------------------------------------------\nLBA 34     |Partition 1                      |Partitions\n           |                                 |\n           |---------------------------------|\n           |Partition 2                      |\n           |                                 |\n           |---------------------------------|\n           |Partition n                      |\n           |                                 |\n----------------------------------------------------------\nLBA -34    |Entry 1|Entry 2| Entry 3| Entry 4| Backup\n-----------|---------------------------------| GPT\nLBA -33    |Entries 5 ~ 128                  |\n           |                                 |\n           |                                 |\nLBA -2     |                                 |\n-----------|---------------------------------|\nLBA -1     |Backup GPT Header                |\n----------------------------------------------------------<\/code><\/pre>\n<p>\u7531\u65bc\u907a\u7559\u539f\u56e0,GPT \u7684 LBA 0 \u6247\u5340\u5177\u6709 MBR \u7d50\u69cb\u3002\u5b83\u88ab\u7a31\u70ba\u300c\u4fdd\u8b77\u6027 MBR\u300d\u3002<br \/>\n\u5b83\u7684\u7b2c\u4e00\u500b\u5206\u5340\u689d\u76ee ID \u5177\u6709 0xEE \u503c,\u800c\u4e0d\u8655\u7406 GPT \u7684\u78c1\u789f\u8edf\u9ad4\u5c07\u5176\u8996\u70ba\u6c92\u6709\u53ef\u7528\u7a7a\u9593\u7684\u5132\u5b58\u8a2d\u5099\u3002<\/p>\n<p>\u53ef\u4ee5\u5b9a\u7fa9128\u500b\u7dda\u6027\u653e\u7f6e\u7684\u5206\u5340\u689d\u76ee\u3002<\/p>\n<p>&quot;LBA -1&quot; \u8868\u793a\u6700\u5f8c\u4e00\u500b\u53ef\u5c0b\u5740\u584a\uff08\u5728 mmc \u5b50\u7cfb\u7d71\u4e2d\uff1a&quot;<br \/>\ndev_desc-&gt;lba \u2013 1&quot;\uff09<\/p>\n<h2>\u4e3b\/\u5099\u4efd GPT \u6a19\u982d\uff1a<\/h2>\n<pre><code>Offset  Size    Description\n\n0       8 B     Signature (\"EFI PART\", 45 46 49 20 50 41 52 54)\n8       4 B     Revision (For version 1.0, the value is 00 00 01 00)\n12      4 B     Header size (in bytes, usually 5C 00 00 00 meaning 92 bytes)\n16      4 B     CRC32 of header (0 to header size), with this field zeroed during calculation\n20      4 B     Reserved (ZERO);\n24      8 B     Current LBA (location of this header copy)\n32      8 B     Backup LBA (location of the other header copy)\n40      8 B     First usable LBA for partitions (primary partition table last LBA + 1)\n48      8 B     Last usable LBA (secondary partition table first LBA - 1)\n56      16 B    Disk GUID (also referred as UUID on UNIXes)\n72      8 B     Partition entries starting LBA (always 2 in primary copy)\n80      4 B     Number of partition entries\n84      4 B     Size of a partition entry (usually 128)\n88      4 B     CRC32 of partition array\n92      *       Reserved; must be ZERO (420 bytes for a 512-byte LBA)<\/code><\/pre>\n<p>\u7e3d\u8a08\uff1a 512 B<\/p>\n<p>\u91cd\u8981\uff1a<\/p>\n<p>GPT \u6a19\u982d\u548c\u5206\u5340\u689d\u76ee\u53d7 CRC32 \uff08POSIX CRC32\uff09 \u4fdd\u8b77\u3002<\/p>\n<p>\u4e3b GPT \u5831\u982d\u548c\u5099\u4efd GPT \u5831\u982d\u4ea4\u63db\u4e86&quot;\u7576\u524d LBA&quot;\u548c&quot;\u5099\u4efd LBA&quot;\u7684\u503c,\u56e0\u6b64 CRC32 \u6821\u9a57\u548c\u4e0d\u540c\u3002<\/p>\n<p>GPT \u5831\u982d\u7684 CRC32\uff08\u4f4d\u5143\u6bb5&quot;\u5831\u982d\u7684 CRC&quot;\uff09\u8a08\u7b97\u5230&quot;\u5831\u982d\u5927\u5c0f&quot;\uff0892\uff09,\u800c\u4e0d\u662f 512 \u4f4d\u5143\u7d44\u3002<\/p>\n<p>\u5206\u5340\u689d\u76ee\u7684 CRC32\uff08\u5b57\u6bb5&quot;\u5206\u5340\u9663\u5217\u7684CRC32&quot;\uff09\u662f\u91dd\u5c0d\u6574\u500b\u9663\u5217\u689d\u76ee\u8a08\u7b97\u7684 \uff08 Number_of_partition_entries *<br \/>\nsizeof\uff08partition_entry_size \uff08\u901a\u5e38\u70ba 128\uff09\uff09\uff09<\/p>\n<p>\u89c0\u5bdfBackup GPT\u662f\u5982\u4f55\u653e\u7f6e\u5728\u8a18\u61b6\u9ad4\u4e2d\u7684\u3002\u5b83\u4e0d\u662f Primary \u7684\u93e1\u50cf\u3002<\/p>\n<pre><code>   Partition Entry Format: (128 bytes)\n   ----------------------\n   Offset  Size    Description\n   0       16 B    Partition type GUID (Big Endian)\n   16      16 B    Unique partition GUID in (Big Endian)\n   32      8  B    First LBA (Little Endian)\n   40      8  B    Last LBA (inclusive)\n   48      8  B    Attribute flags [+]\n   56      72 B    Partition name (text)\n\n   Attribute flags: (8 bytes\/64 bits)\n   Bit 0     - System partition\n   Bit 1     - Hide from EFI\n   Bit 2     - Legacy BIOS bootable\n   Bit 48-63 - Defined and used by the individual partition type\n\n   For Basic data partition type: (last 4 bits)\n   Bit 60 - Read-only\n   Bit 62 - Hidden\n   Bit 63 - Not mount<\/code><\/pre>\n<h1>\u5728 U-Boot \u4e2d\u5efa\u7acb GPT \u5206\u5340\uff1a<\/h1>\n<p>\u8981\u6062\u5fa9 GUID \u5206\u5340\u8868,\u9700\u8981\uff1a<\/p>\n<ol>\n<li>\n<p>\u5728\u74b0\u5883\u4e2d\u5b9a\u7fa9\u5206\u5340\u4f48\u5c40\u3002<br \/>\n\u5206\u5340\u4f48\u5c40\u683c\u5f0f\u70ba\uff1a<\/p>\n<pre><code>\"uuid_disk=...;name=u-boot,size=60MiB,uuid=...;name=kernel,size=60MiB,uuid=...;\"<\/code><\/pre>\n<p>\u6216<\/p>\n<pre><code>\"uuid_disk=${uuid_gpt_disk};name=${uboot_name},size=${uboot_size},uuid=${uboot_uuid};\" <\/code><\/pre>\n<ul>\n<li>\u6b04\u4f4d &#8216;name&#8217; \u548c &#8216;size&#8217; \u5c0d\u65bc\u6bcf\u500b\u5206\u5340\u90fd\u662f\u5f37\u5236\u6027\u7684\u3002<\/li>\n<li>\u6b04\u4f4d &#8216;start&#8217; \u662f\u53ef\u9078\u7684\u3002<\/li>\n<li>\u5982\u679c\u6700\u5f8c\u4e00\u500b\u5206\u5340\u7684\u6b04\u4f4d &#8216;size&#8217; \u70ba 0,\u5247\u5206\u5340\u5c07\u64f4\u5c55\u5230\u8a2d\u5099\u7684\u672b\u5c3e\u3002<\/li>\n<li>\u5982\u679c\u555f\u7528\u4e86 CONFIG_RANDOM_UUID,\u5247\u5b57\u6bb5 &#8216;uuid&#8217; \u548c &#8216;uuid_disk&#8217; \u662f\u53ef\u9078\u7684\u3002\u5982\u679c\u7701\u7565,\u5247\u5c07\u4f7f\u7528\u96a8\u6a5f uuid,\u6216\u8005\u5b83\u5011\u6307\u5411\u7a7a\/\u4e0d\u5b58\u5728\u7684\u74b0\u5883\u8b8a\u6578\u3002\u74b0\u5883\u8b8a\u6578\u5c07\u8a2d\u7f6e\u70ba\u751f\u6210\u7684 UUID\u3002&quot;gpt guid&quot;\u547d\u4ee4\u5f9e GPT \u4e2d\u8b80\u53d6uuid_disk\u7684\u7576\u524d\u503c\u3002<\/li>\n<li>\u6b04\u4f4d &#8216;bootable&#8217; \u662f\u53ef\u9078\u7684,\u5b83\u7528\u65bc\u5c07 GPT \u5206\u5340\u6a19\u8a18\u70ba\u53ef\u555f\u52d5\uff08\u8a2d\u7f6e\u5c6c\u6027\u6a19\u8a8c &quot;Legacy BIOS bootable&quot;\uff09\u3002<\/li>\n<li>&quot;\u540d\u7a31=u-boot,\u5927\u5c0f=60MiB;name=boot,size=60Mib,\u53ef\u555f\u52d5;name=rootfs,size=0&quot; \u53ef\u4ee5\u901a\u904e\u547d\u4ee4 &quot;part list -bootable &quot; \u4f86\u5b9a\u4f4d\u53ef\u555f\u52d5\u78c1\u789f ,\u8acb\u67e5\u770b doc\/README.distro \u4f7f\u7528\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u5b9a\u7fa9 &#8216;CONFIG_EFI_PARTITION&#8217; \u548c &#8216;CONFIG_CMD_GPT&#8217;<\/li>\n<li>\n<p>\u5f9e u-boot \u63d0\u793a\u7b26\u9375\u5165\uff1a<\/p>\n<pre><code>gpt write mmc 0 $partitions<\/code><\/pre>\n<\/li>\n<\/ol>\n<h1>\u5728 U-Boot \u4e2d\u6aa2\u67e5\uff08\u9a57\u8b49\uff09GPT \u5206\u5340\uff1a<\/h1>\n<p>\u7a0b\u5f0f\u540c\u4e0a\u3002\u552f\u4e00\u7684\u8b8a\u5316\u662f\u5728\u7b2c 3 \u9ede\u3002<\/p>\n<p>\u5728 u-boot \u63d0\u793a\u7b26\u8655,\u9700\u8981\u5beb\u6210\uff1a<\/p>\n<pre><code>gpt verify mmc 0 [$partitions]\n<\/code><\/pre>\n<p>\u5176\u4e2d [$partitions] \u662f\u53ef\u9078\u53c3\u6578\u3002<\/p>\n<p>\u5982\u679c\u672a\u63d0\u4f9b,\u5247\u50c5\u57f7\u884c\u57fa\u65bc GPT \u6a19\u982d\u548c PTE \u7684 CRC32 \u8a08\u7b97\u7684\u57fa\u672c\u6aa2\u67e5\u3002<br \/>\n\u5982\u679c\u63d0\u4f9b,\u9084\u6703\u5c07\u5206\u5340\u6578\u64da\uff08\u540d\u7a31\u3001\u5927\u5c0f\u548c\u8d77\u59cb\u504f\u79fb\u91cf\uff08LBA \u4e2d\u7684\u6700\u5f8c\u5169\u500b\uff09\uff09\u8207 \u300e$partitions\u300f \u74b0\u5883\u8b8a\u6578\u4e2d\u5b9a\u7fa9\u7684\u6578\u64da\u9032\u884c\u6bd4\u8f03\u3002<\/p>\n<p>\u904b\u884c\u6b64\u547d\u4ee4\u540e,\u5982\u679c\u5728\u5b58\u5132\u7684\u975e\u6613\u5931\u6027\u4ecb\u8cea GPT \u4e0a\u672a\u767c\u73fe\u932f\u8aa4,\u5247\u8fd4\u56de\u4ee3\u78bc\u5c07\u8a2d\u7f6e\u70ba 0\u3002<\/p>\n<p>\u4ee5\u4e0b\u884c\u53ef\u7528\u65bc\u8a55\u4f30 GPT \u9a57\u8b49\u662f\u5426\u6210\u529f\uff1a<\/p>\n<pre><code class=\"language-bash\">U-BOOT> gpt verify mmc 0 $partitions\nU-BOOT> if test $? = 0; then echo \"GPT OK\"; else echo \"GPT ERR\"; fi<\/code><\/pre>\n<h1>\u5f9e U-Boot \u91cd\u65b0\u547d\u540d GPT \u5206\u5340\uff1a<\/h1>\n<p>GPT \u5206\u5340\u540d\u7a31\u662f\u4e00\u7a2e\u6a5f\u5236,\u7528\u6236\u7a7a\u9593\u548c U-Boot \u53ef\u4ee5\u901a\u904e\u8a72\u6a5f\u5236\u5c31\u8edf\u9ad4\u66f4\u65b0\u548c\u555f\u52d5\u5931\u6557\u9032\u884c\u901a\u4fe1\u3002&#8217;gpt guid&#8217;\u3001&#8217;gpt read&#8217;\u3001&#8217;gpt rename&#8217; \u548c &#8216;gpt swap&#8217; \u547d\u4ee4\u901a\u904e\u751f\u6210\u548c\u4fee\u6539\u5206\u5340\u4f48\u5c40\u5b57\u5143\u4e32,\u6709\u52a9\u65bc\u5f9e\u5f15\u5c0e\u8173\u672c\u4e2d\u4ee5\u7a0b\u5f0f\u8a2d\u8a08\u65b9\u5f0f\u91cd\u547d\u540d\u5206\u5340\u3002\u4e0b\u9762\u662f\u4e00\u500b\u4f7f\u7528 &#8216;swap&#8217; \u4f86\u4ea4\u63db &#8216;primary&#8217; \u548c &#8216;backup&#8217; \u5206\u5340\u540d\u7a31\u7684\u4f8b\u5b50\uff1a<\/p>\n<pre><code class=\"language-bash\">U-BOOT> gpt swap mmc 0 primary backup<\/code><\/pre>\n<p>\u4e4b\u5f8c,\u6240\u6709\u4ee5\u524d\u547d\u540d\u70ba &#8216;primary&#8217; \u7684\u5206\u5340\u5c07\u88ab\u547d\u540d\u70ba &#8216;backup&#8217;,\u53cd\u4e4b\u4ea6\u7136\u3002\u6216\u8005,\u53ef\u4ee5\u91cd\u547d\u540d\u55ae\u500b\u5206\u5340\u3002\u5728\u6b64\u7bc4\u4f8b\u4e2d,mmc0 \u7684\u7b2c\u4e00\u500b\u5206\u5340\u5c07\u91cd\u65b0\u547d\u540d\u70ba &#8216;primary&#8217;\uff1a<\/p>\n<pre><code class=\"language-bash\">U-BOOT> gpt rename mmc 0 1 primary<\/code><\/pre>\n<p>GPT \u529f\u80fd\u53ef\u4ee5\u901a\u904e\u5275\u5efa\u78c1\u789f\u6620\u5c04\u4f86\u4f7f\u7528 &#8216;sandbox&#8217; \u677f\u9032\u884c\u6e2c\u8a66,\u5982 doc\/arch\/index.rst \u4e2d\u7684&quot;\u584a\u8a2d\u5099\u6a21\u64ec&quot;\u4e2d\u6240\u8ff0\uff1a<\/p>\n<pre><code class=\"language-bash\">=>host bind 0 .\/disk.raw\n=> gpt read host 0\n[ . . . ]\n=> gpt swap host 0 name othername\n[ . . . ]<\/code><\/pre>\n<h1>\u5f9e U-Boot \u4fee\u6539 GPT \u5206\u5340\u4f48\u5c40\uff1a<\/h1>\n<p>\u6574\u500b GPT \u5206\u5340\u4f48\u5c40\u53ef\u4ee5\u532f\u51fa\u5230\u74b0\u5883\u8b8a\u6578,\u7136\u5f8c\u4fee\u6539 enmasse\u3002\u7528\u6236\u53ef\u4ee5\u66f4\u6539\u5206\u5340\u7de8\u865f\u3001\u504f\u79fb\u91cf\u3001\u540d\u7a31\u548c\u5927\u5c0f\u3002\u751f\u6210\u7684\u8b8a\u6578\u53ef\u7528\u65bc\u91cd\u65b0\u683c\u5f0f\u5316\u8a2d\u5099\u3002\u4e0b\u9762\u662f\u5c07 GPT \u5206\u5340\u8b80\u53d6\u5230\u8b8a\u6578\u4e2d,\u7136\u5f8c\u4fee\u6539\u5b83\u5011\u7684\u7bc4\u4f8b\uff1a<\/p>\n<pre><code class=\"language-bash\">U-BOOT> gpt read mmc 0 current_partitions\nU-BOOT> env edit current_partitions\nedit: uuid_disk=[...];name=part1,start=0x4000,size=0x4000,uuid=[...];\nname=part2,start=0xc000,size=0xc000,uuid=[...];[ . . . ]\n\nU-BOOT> gpt write mmc 0 $current_partitions\nU-BOOT> gpt verify mmc 0 $current_partitions<\/code><\/pre>\n<h1>\u5206\u5340\u985e\u578b (Partition type):<\/h1>\n<p>\u5c0d\u65bc\u5275\u5efa\u7684\u5206\u5340,\u4f7f\u7528\u7684\u5206\u5340\u985e\u578b GUID \u70ba PARTITION_BASIC_DATA_GUID \uff08EBD0A0A2-B9E5-4433-87C0-68B6B72699C7\uff09\u3002<\/p>\n<p>\u5982\u679c uboot \u5b9a\u7fa9 \u300eCONFIG_PARTITION_TYPE_GUID\u300f,\u5247\u9078\u9805\u53c3\u6578 \u300etype\u300f \u53ef\u4ee5\u6307\u5b9a\u5176\u4ed6\u5206\u5340\u985e\u578b guid\uff1a<\/p>\n<pre><code> \"uuid_disk=...;name=u-boot,size=60MiB,uuid=...;\nname=kernel,size=60MiB,uuid=...,\ntype=0FC63DAF-8483-4772-8E79-3D69D8477DE4;\"<\/code><\/pre>\n<p>\u4e00\u4e9b\u5b57\u4e32\u4e5f\u53ef\u4ee5\u5728\u5df2\u77e5 GUID \u7684\u4f4d\u7f6e\u4f7f\u7528\uff1a<br \/>\n&quot;system&quot; = PARTITION_SYSTEM_GUID \uff08C12A7328-F81F-11D2-BA4B-00A0C93EC93B\uff09<br \/>\n&quot;mbr&quot; = LEGACY_MBR_PARTITION_GUID \uff08024DEE41-33E7-11D3-9D69-0008C781F39F\uff09<br \/>\n&quot;msft&quot; = PARTITION_MSFT_RESERVED_GUID \uff08E3C9E316-0B5C-4DB8-817D-F92DF00215AE\uff09<br \/>\n&quot;data&quot; = PARTITION_BASIC_DATA_GUID \uff08EBD0A0A2-B9E5-4433-87C0-68B6B72699C7\uff09<br \/>\n&quot;linux&quot; = PARTITION_LINUX_FILE_SYSTEM_DATA_GUID \uff080FC63DAF-8483-4772-8E79-3D69D8477DE4\uff09<br \/>\n&quot;raid&quot; = PARTITION_LINUX_RAID_GUID \uff08A19D880F-05FC-4D3B-A006-743F0F84911E\uff09<br \/>\n&quot;swap&quot; = PARTITION_LINUX_SWAP_GUID \uff080657FD6D-A4AB-43C4-84E5-0933C84B4F4F\uff09<br \/>\n&quot;lvm&quot; = PARTITION_LINUX_LVM_GUID \uff08E6D6D379-F507-44C2-A23C-238F2A3DF928\uff09<br \/>\n&quot;u-boot-env&quot; = PARTITION_U_BOOT_ENVIRONMENT \uff083DE21764-95BD-54BD-A5C3-4ABE786F38A8\uff09<\/p>\n<pre><code>\"uuid_disk=...;name=u-boot,size=60MiB,uuid=...;\nname=kernel,size=60MiB,uuid=...,type=linux;\"<\/code><\/pre>\n<p>\u5b83\u5011\u9084\u7528\u65bc\u5728 \u300cpart list\u300d \u547d\u4ee4\u4e2d\u986f\u793a\u5206\u5340\u985e\u578b\u3002<\/p>\n<h1>\u6709\u7528\u7684\u8cc7\u8a0a\uff1a<\/h1>\n<p>\u5efa\u8b70\u4f7f\u7528\u5169\u500b\u7a0b\u5f0f,\u5373\uff1a\u300egdisk\u300f \u548c \u300eparted\u300f \u4f86\u4f7f\u7528 GPT \u6062\u5fa9\u3002\u5169\u8005\u90fd\u80fd\u5920\u8655\u7406 GUID \u5206\u5340\u3002<br \/>\n\u8acb\u6ce8\u610f parted \u7684 -l \u958b\u95dc\u3002<\/p>\n<p>\u5efa\u8b70\u4f7f\u7528 uuid \u7a0b\u5f0f\u751f\u6210 UUID \u5b57\u4e32\u3002\u6b64\u5916,\u5b83\u53ef\u4ee5\u89e3\u78bc UUID \u5b57\u4e32\u4e2d\u50b3\u905e\u7684 \uff08-d \u958b\u95dc\uff09\u3002\u5b83\u53ef\u7528\u65bc\u751f\u6210\u50b3\u905e\u7d66 u-boot \u74b0\u5883\u8b8a\u6578\u7684\u5206\u5340 UUID\u3002<br \/>\n\u5982\u679c\u5b9a\u7fa9\u4e86\u53ef\u9078 CONFIG_RANDOM_UUID,\u5247\u5c0d\u65bc\u672a\u8a2d\u7f6e\u74b0\u5883 uuid \u7684\u4efb\u4f55\u5206\u5340,\u5c07\u96a8\u6a5f\u751f\u6210 uuid \u4e26\u5c07\u5176\u5b58\u5132\u5728\u76f8\u61c9\u7684\u74b0\u5883\u8b8a\u6578\u4e2d\u3002<\/p>\n<p>\u6ce8\u610f\uff1a<br \/>\n\u7a0b\u5f0f \u300cuuid\u300d \u7522\u751f\u7684\u6bcf\u500b UUID \u5b57\u4e32\u584a\u90fd\u662f\u5927\u7aef\u7684,\u5b83\u4e5f\u5b58\u5132\u5728\u78c1\u789f GPT \u7684\u5927\u7aef\u4e2d\u3002<br \/>\n\u53ef\u4ee5\u901a\u904e\u9375\u5165 \u300cmmc part\u300d \u4f86\u5217\u5370\u5206\u5340\u4f48\u5c40\u3002\u8acb\u6ce8\u610f,\u6bcf\u500b\u5206\u5340 GUID \u7684\u4f4d\u5143\u7d44\u9806\u5e8f\u8207\u4e4b\u524d\u751f\u6210\u7684 UUID \u4e0d\u540c,\u9019\u662f\u56e0\u70ba GUID \u5b57\u4e32\u7684\u524d\u4e09\u500b\u584a\u4f4d\u65bc Little Endian \u4e2d\u3002<br \/>\nnote:<br \/>\nEach string block of UUID generated by program &quot;uuid&quot; is in big endian and it is also stored in big endian in disk GPT.<br \/>\nPartitions layout can be printed by typing &quot;mmc part&quot;. Note that each partition GUID has different byte order than UUID generated before, this is because first three blocks of GUID string are in Little Endian.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Glossary: UUID -(Universally Unique Identifier) GUID &#038;#&#8230; &raquo; <a class=\"read-more-link\" href=\"https:\/\/vm1.go2see.me\/?p=885\">\u95b1\u8b80\u5168\u6587<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-885","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/vm1.go2see.me\/index.php?rest_route=\/wp\/v2\/posts\/885","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vm1.go2see.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vm1.go2see.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vm1.go2see.me\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vm1.go2see.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=885"}],"version-history":[{"count":10,"href":"https:\/\/vm1.go2see.me\/index.php?rest_route=\/wp\/v2\/posts\/885\/revisions"}],"predecessor-version":[{"id":887,"href":"https:\/\/vm1.go2see.me\/index.php?rest_route=\/wp\/v2\/posts\/885\/revisions\/887"}],"wp:attachment":[{"href":"https:\/\/vm1.go2see.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=885"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vm1.go2see.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=885"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vm1.go2see.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=885"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}