Joshua Watt | 446de7c | 2023-08-31 10:51:35 -0600 | [diff] [blame] | 1 | .. SPDX-License-Identifier: GPL-2.0+ |
| 2 | |
Heinrich Schuchardt | 1b0c316 | 2024-01-14 14:53:13 +0100 | [diff] [blame] | 3 | .. index:: |
| 4 | single: gpt (command) |
| 5 | |
Joshua Watt | 446de7c | 2023-08-31 10:51:35 -0600 | [diff] [blame] | 6 | gpt command |
| 7 | =========== |
| 8 | |
| 9 | Synopsis |
| 10 | -------- |
| 11 | |
| 12 | :: |
| 13 | |
| 14 | gpt enumerate <interface> <dev> |
| 15 | gpt guid <interface> <dev> [<varname>] |
| 16 | gpt read <interface> <dev> [<varname>] |
| 17 | gpt rename <interface> <dev> <part> <name> |
| 18 | gpt repair <interface> <dev> |
Joshua Watt | 44d6233 | 2023-08-31 10:51:38 -0600 | [diff] [blame] | 19 | gpt set-bootable <interface> <dev> <partition list> |
Joshua Watt | 446de7c | 2023-08-31 10:51:35 -0600 | [diff] [blame] | 20 | gpt setenv <interface> <dev> <partition name> |
| 21 | gpt swap <interface> <dev> <name1> <name2> |
Joshua Watt | d88ba5f | 2023-08-31 10:51:41 -0600 | [diff] [blame] | 22 | gpt transpose <interface> <dev> <part1> <part2> |
Joshua Watt | 446de7c | 2023-08-31 10:51:35 -0600 | [diff] [blame] | 23 | gpt verify <interface> <dev> [<partition string>] |
| 24 | gpt write <interface> <dev> <partition string> |
| 25 | |
| 26 | Description |
| 27 | ----------- |
| 28 | |
| 29 | The gpt command lets users read, create, modify, or verify the GPT (GUID |
| 30 | Partition Table) partition layout. |
| 31 | |
| 32 | Common arguments: |
| 33 | |
| 34 | interface |
| 35 | interface for accessing the block device (mmc, sata, scsi, usb, ....) |
| 36 | |
| 37 | dev |
| 38 | device number |
| 39 | |
| 40 | partition string |
| 41 | Describes the GPT partition layout for a disk. The syntax is similar to |
| 42 | the one used by the :doc:`mbr command <mbr>` command. The string contains |
| 43 | one or more partition descriptors, each separated by a ";". Each descriptor |
| 44 | contains one or more fields, with each field separated by a ",". Fields are |
| 45 | either of the form "key=value" to set a specific value, or simple "flag" to |
| 46 | set a boolean flag |
| 47 | |
| 48 | The first descriptor can optionally be used to describe parameters for the |
| 49 | whole disk with the following fields: |
| 50 | |
| 51 | * uuid_disk=UUID - Set the UUID for the disk |
| 52 | |
| 53 | Partition descriptors can have the following fields: |
| 54 | |
| 55 | * name=<NAME> - The partition name, required |
| 56 | * start=<BYTES> - The partition start offset in bytes, required |
Patrick Delaunay | cccbaf4 | 2025-06-16 13:27:48 +0200 | [diff] [blame] | 57 | * size=<BYTES> - The partition size in bytes or "-" for the last partition to expand it to the whole free area |
Joshua Watt | 446de7c | 2023-08-31 10:51:35 -0600 | [diff] [blame] | 58 | * bootable - Set the legacy bootable flag |
| 59 | * uuid=<UUID> - The partition UUID, optional if CONFIG_RANDOM_UUID=y is enabled |
| 60 | * type=<UUID> - The partition type GUID, requires CONFIG_PARTITION_TYPE_GUID=y |
| 61 | |
| 62 | |
| 63 | If 'uuid' is not specified, but CONFIG_RANDOM_UUID is enabled, a random UUID |
| 64 | will be generated for the partition |
| 65 | |
Patrick Delaunay | cccbaf4 | 2025-06-16 13:27:48 +0200 | [diff] [blame] | 66 | If 'type' is not specified or without CONFIG_PARTITION_TYPE_GUID=y, |
| 67 | the used partition type GUID is PARTITION_BASIC_DATA_GUID. |
| 68 | |
| 69 | Some strings can be also used at the place of the known partition type GUID: |
| 70 | * "mbr" = LEGACY_MBR_PARTITION_GUID (024DEE41-33E7-11D3-9D69-0008C781F39F) |
| 71 | * "msft" = PARTITION_MSFT_RESERVED_GUID (E3C9E316-0B5C-4DB8-817D-F92DF00215AE) |
| 72 | * "data" = PARTITION_BASIC_DATA_GUID (EBD0A0A2-B9E5-4433-87C0-68B6B72699C7) |
| 73 | * "linux" = PARTITION_LINUX_FILE_SYSTEM_DATA_GUID (0FC63DAF-8483-4772-8E79-3D69D8477DE4) |
| 74 | * "raid" = PARTITION_LINUX_RAID_GUID (A19D880F-05FC-4D3B-A006-743F0F84911E) |
| 75 | * "swap" = PARTITION_LINUX_SWAP_GUID (0657FD6D-A4AB-43C4-84E5-0933C84B4F4F) |
| 76 | * "lvm" = PARTITION_LINUX_LVM_GUID (E6D6D379-F507-44C2-A23C-238F2A3DF928) |
| 77 | * "u-boot-env" = PARTITION_U_BOOT_ENVIRONMENT(3DE21764-95BD-54BD-A5C3-4ABE786F38A8) |
| 78 | * "system" = PARTITION_SYSTEM_GUID (C12A7328-F81F-11D2-BA4B-00A0C93EC93B) |
| 79 | |
| 80 | The GPT partitions layout and associated 'type' are also printed with the |
| 81 | :doc:`part command <part>` command by typing "part list". |
| 82 | |
Joshua Watt | 446de7c | 2023-08-31 10:51:35 -0600 | [diff] [blame] | 83 | gpt enumerate |
| 84 | ~~~~~~~~~~~~~ |
| 85 | |
| 86 | Sets the variable 'gpt_partition_list' to be a list of all the partition names |
| 87 | on the device. |
| 88 | |
| 89 | gpt guid |
| 90 | ~~~~~~~~ |
| 91 | |
| 92 | Report the GUID of a disk. If 'varname' is specified, the command will set the |
| 93 | variable to the GUID, otherwise it will be printed out. |
| 94 | |
| 95 | gpt read |
| 96 | ~~~~~~~~ |
| 97 | |
| 98 | Prints the current state of the GPT partition table. If 'varname' is specified, |
| 99 | the variable will be filled with a partition string in the same format as a |
| 100 | '<partition string>', suitable for passing to other 'gpt' commands. If the |
| 101 | argument is omitted, a human readable description is printed out. |
| 102 | CONFIG_CMD_GPT_RENAME=y is required. |
| 103 | |
| 104 | gpt rename |
| 105 | ~~~~~~~~~~ |
| 106 | |
| 107 | Renames all partitions named 'part' to be 'name'. CONFIG_CMD_GPT_RENAME=y is |
| 108 | required. |
| 109 | |
| 110 | gpt repair |
| 111 | ~~~~~~~~~~ |
| 112 | |
| 113 | Repairs the GPT partition tables if it they become corrupted. |
| 114 | |
Joshua Watt | 44d6233 | 2023-08-31 10:51:38 -0600 | [diff] [blame] | 115 | gpt set-bootable |
| 116 | ~~~~~~~~~~~~~~~~ |
| 117 | |
| 118 | Sets the bootable flag for all partitions in the table. If the partition name |
| 119 | is in 'partition list' (separated by ','), the bootable flag is set, otherwise |
| 120 | it is cleared. CONFIG_CMD_GPT_RENAME=y is required. |
| 121 | |
Joshua Watt | 446de7c | 2023-08-31 10:51:35 -0600 | [diff] [blame] | 122 | gpt setenv |
| 123 | ~~~~~~~~~~ |
| 124 | |
| 125 | The 'gpt setenv' command will set a series of environment variables with |
| 126 | information about the partition named '<partition name>'. The variables are: |
| 127 | |
| 128 | gpt_partition_addr |
| 129 | the starting offset of the partition in blocks as a hexadecimal number |
| 130 | |
| 131 | gpt_partition_size |
| 132 | the size of the partition in blocks as a hexadecimal number |
| 133 | |
| 134 | gpt_partition_name |
| 135 | the name of the partition |
| 136 | |
| 137 | gpt_partition_entry |
| 138 | the partition number in the table, e.g. 1, 2, 3, etc. |
| 139 | |
Joshua Watt | fd1134e | 2023-08-31 10:51:37 -0600 | [diff] [blame] | 140 | gpt_partition_bootable |
| 141 | 1 if the partition is marked as bootable, 0 if not |
| 142 | |
Joshua Watt | 446de7c | 2023-08-31 10:51:35 -0600 | [diff] [blame] | 143 | gpt swap |
| 144 | ~~~~~~~~ |
| 145 | |
| 146 | Changes the names of all partitions that are named 'name1' to be 'name2', and |
| 147 | all partitions named 'name2' to be 'name1'. CONFIG_CMD_GPT_RENAME=y is |
| 148 | required. |
| 149 | |
Joshua Watt | d88ba5f | 2023-08-31 10:51:41 -0600 | [diff] [blame] | 150 | gpt transpose |
| 151 | ~~~~~~~~~~~~~ |
| 152 | |
| 153 | Swaps the order of two partition table entries with indexes 'part1' and 'part2' |
| 154 | in the partition table, but otherwise leaves the actual partition data |
| 155 | untouched. |
| 156 | |
Joshua Watt | 446de7c | 2023-08-31 10:51:35 -0600 | [diff] [blame] | 157 | gpt verify |
| 158 | ~~~~~~~~~~ |
| 159 | |
| 160 | Sets return value $? to 0 (true) if the partition layout on the |
| 161 | specified disk matches the one in the provided partition string, and 1 (false) |
| 162 | if it does not match. If no partition string is specified, the command will |
| 163 | check if the disk is partitioned or not. |
| 164 | |
| 165 | gpt write |
| 166 | ~~~~~~~~~ |
| 167 | |
| 168 | (Re)writes the partition table on the disk to match the provided |
| 169 | partition string. It returns 0 on success or 1 on failure. |
| 170 | |
| 171 | Configuration |
| 172 | ------------- |
| 173 | |
| 174 | To use the 'gpt' command you must specify CONFIG_CMD_GPT=y. To enable 'gpt |
| 175 | read', 'gpt swap' and 'gpt rename', you must specify CONFIG_CMD_GPT_RENAME=y. |
| 176 | |
| 177 | Examples |
| 178 | ~~~~~~~~ |
Tom Fitzhenry | bc36455 | 2023-10-24 22:59:06 +1100 | [diff] [blame] | 179 | |
Joshua Watt | 446de7c | 2023-08-31 10:51:35 -0600 | [diff] [blame] | 180 | Create 6 partitions on a disk:: |
| 181 | |
Patrick Delaunay | cccbaf4 | 2025-06-16 13:27:48 +0200 | [diff] [blame] | 182 | => setenv gpt_parts 'uuid_disk=bec9fc2a-86c1-483d-8a0e-0109732277d7;\ |
| 183 | name=boot,start=4M,size=128M,bootable,type=ebd0a0a2-b9e5-4433-87c0-68b6b72699c7;\ |
| 184 | name=rootfs,size=3072M,type=0fc63daf-8483-4772-8e79-3d69d8477de4;\ |
| 185 | name=system-data,size=512M,type=0fc63daf-8483-4772-8e79-3d69d8477de4;\ |
| 186 | name=user,size=512M,type=0fc63daf-8483-4772-8e79-3d69d8477de4;\ |
| 187 | name=modules,size=100M,type=0fc63daf-8483-4772-8e79-3d69d8477de4;\ |
| 188 | name=ramdisk,size=8M,type=0fc63daf-8483-4772-8e79-3d69d8477de4;\ |
| 189 | name=[ext],size=-,type=0fc63daf-8483-4772-8e79-3d69d8477de4' |
Joshua Watt | 446de7c | 2023-08-31 10:51:35 -0600 | [diff] [blame] | 190 | => gpt write mmc 0 $gpt_parts |
| 191 | |
Patrick Delaunay | cccbaf4 | 2025-06-16 13:27:48 +0200 | [diff] [blame] | 192 | Last partition "[ext]" with '-' is extended up to the end of the disk |
Joshua Watt | 446de7c | 2023-08-31 10:51:35 -0600 | [diff] [blame] | 193 | |
| 194 | Verify that the device matches the partition layout described in the variable |
| 195 | $gpt_parts:: |
| 196 | |
| 197 | => gpt verify mmc 0 $gpt_parts |
| 198 | |
| 199 | |
| 200 | Get the information about the partition named 'rootfs':: |
| 201 | |
| 202 | => gpt setenv mmc 0 rootfs |
| 203 | => echo ${gpt_partition_addr} |
| 204 | 2000 |
| 205 | => echo ${gpt_partition_size} |
| 206 | 14a000 |
| 207 | => echo ${gpt_partition_name} |
| 208 | rootfs |
| 209 | => echo ${gpt_partition_entry} |
| 210 | 2 |
Joshua Watt | fd1134e | 2023-08-31 10:51:37 -0600 | [diff] [blame] | 211 | => echo ${gpt_partition_bootable} |
| 212 | 0 |
Joshua Watt | 446de7c | 2023-08-31 10:51:35 -0600 | [diff] [blame] | 213 | |
| 214 | Get the list of partition names on the disk:: |
| 215 | |
| 216 | => gpt enumerate |
Tom Fitzhenry | bc36455 | 2023-10-24 22:59:06 +1100 | [diff] [blame] | 217 | => echo ${gpt_partition_list} |
Joshua Watt | 446de7c | 2023-08-31 10:51:35 -0600 | [diff] [blame] | 218 | boot rootfs system-data [ext] user modules ramdisk |
| 219 | |
Joshua Watt | 446de7c | 2023-08-31 10:51:35 -0600 | [diff] [blame] | 220 | Get the GUID for a disk:: |
| 221 | |
| 222 | => gpt guid mmc 0 |
| 223 | bec9fc2a-86c1-483d-8a0e-0109732277d7 |
| 224 | => gpt guid mmc gpt_disk_uuid |
| 225 | => echo ${gpt_disk_uuid} |
| 226 | bec9fc2a-86c1-483d-8a0e-0109732277d7 |
Joshua Watt | 44d6233 | 2023-08-31 10:51:38 -0600 | [diff] [blame] | 227 | |
| 228 | Set the bootable flag for the 'boot' partition and clear it for all others:: |
| 229 | |
| 230 | => gpt set-bootable mmc 0 boot |
Joshua Watt | d88ba5f | 2023-08-31 10:51:41 -0600 | [diff] [blame] | 231 | |
| 232 | Swap the order of the 'boot' and 'rootfs' partition table entries:: |
Tom Fitzhenry | bc36455 | 2023-10-24 22:59:06 +1100 | [diff] [blame] | 233 | |
Joshua Watt | d88ba5f | 2023-08-31 10:51:41 -0600 | [diff] [blame] | 234 | => gpt setenv mmc 0 rootfs |
| 235 | => echo ${gpt_partition_entry} |
| 236 | 2 |
| 237 | => gpt setenv mmc 0 boot |
| 238 | => echo ${gpt_partition_entry} |
| 239 | 1 |
| 240 | |
| 241 | => gpt transpose mmc 0 1 2 |
| 242 | |
| 243 | => gpt setenv mmc 0 rootfs |
| 244 | => echo ${gpt_partition_entry} |
| 245 | 1 |
| 246 | => gpt setenv mmc 0 boot |
| 247 | => echo ${gpt_partition_entry} |
| 248 | 2 |
Patrick Delaunay | cccbaf4 | 2025-06-16 13:27:48 +0200 | [diff] [blame] | 249 | |
| 250 | Other example: a disk with known partition types:: |
| 251 | |
| 252 | => setenv gpt_parts 'name=u-boot,size=32M,type=data;\ |
| 253 | name=env,size=1M,type=u-boot-env; |
| 254 | name=ESP,size=128M,type=system; |
| 255 | name=rootfs,size=3072M,type=linux; |
| 256 | name=swap,size=100M,type=swap; |
| 257 | name=user,size=-,type=linux' |
| 258 | => gpt write mmc 0 $gpt_parts |
| 259 | |
| 260 | => part list mmc 0 |
| 261 | Partition Map for mmc device 0 -- Partition Type: EFI |
| 262 | Part Start LBA End LBA Name |
| 263 | Attributes |
| 264 | Type GUID |
| 265 | Partition GUID |
| 266 | 1 0x00000022 0x00010021 "u-boot" |
| 267 | attrs: 0x0000000000000000 |
| 268 | type: ebd0a0a2-b9e5-4433-87c0-68b6b72699c7 |
| 269 | (data) |
| 270 | guid: 502d48f6-81c0-488f-bdc0-ad602498f3ce |
| 271 | 2 0x00010022 0x00010821 "env" |
| 272 | attrs: 0x0000000000000000 |
| 273 | type: 3de21764-95bd-54bd-a5c3-4abe786f38a8 |
| 274 | (u-boot-env) |
| 275 | guid: 9dc62338-459a-485e-bd8f-b3fbf728d9c0 |
| 276 | 3 0x00010822 0x00050821 "ESP" |
| 277 | attrs: 0x0000000000000000 |
| 278 | type: c12a7328-f81f-11d2-ba4b-00a0c93ec93b |
| 279 | (EFI System Partition) |
| 280 | guid: 8a3a1168-6af8-4ba7-a95d-9cd0d14e1b3d |
| 281 | 4 0x00050822 0x00650821 "rootfs" |
| 282 | attrs: 0x0000000000000000 |
| 283 | type: 0fc63daf-8483-4772-8e79-3d69d8477de4 |
| 284 | (linux) |
| 285 | guid: 411ffebc-8a19-469d-99a9-0982409a6851 |
| 286 | 5 0x00650822 0x00682821 "swap" |
| 287 | attrs: 0x0000000000000000 |
| 288 | type: 0657fd6d-a4ab-43c4-84e5-0933c84b4f4f |
| 289 | (swap) |
| 290 | guid: f8ec0410-95ec-4e3e-8b98-fb8cf271a201 |
| 291 | 6 0x00682822 0x01dacbde "user" |
| 292 | attrs: 0x0000000000000000 |
| 293 | type: 0fc63daf-8483-4772-8e79-3d69d8477de4 |
| 294 | (linux) |
| 295 | guid: c5543e1c-566d-4502-99ad-20545007e673 |
| 296 | |
| 297 | Modifying GPT partition layout from U-Boot:: |
| 298 | |
| 299 | => gpt read mmc 0 current_partitions |
| 300 | => env edit current_partitions |
| 301 | edit: uuid_disk=[...];name=part1,start=0x4000,size=0x4000,uuid=[...]; |
| 302 | name=part2,start=0xc000,size=0xc000,uuid=[...];[ . . . ] |
| 303 | |
| 304 | => gpt write mmc 0 $current_partitions |
| 305 | => gpt verify mmc 0 $current_partitions |