Joshua Watt | 44c5d77 | 2023-08-31 10:51:35 -0600 | [diff] [blame] | 1 | .. SPDX-License-Identifier: GPL-2.0+ |
| 2 | |
| 3 | gpt command |
| 4 | =========== |
| 5 | |
| 6 | Synopsis |
| 7 | -------- |
| 8 | |
| 9 | :: |
| 10 | |
| 11 | gpt enumerate <interface> <dev> |
| 12 | gpt guid <interface> <dev> [<varname>] |
| 13 | gpt read <interface> <dev> [<varname>] |
| 14 | gpt rename <interface> <dev> <part> <name> |
| 15 | gpt repair <interface> <dev> |
Joshua Watt | a1e793a | 2023-08-31 10:51:38 -0600 | [diff] [blame] | 16 | gpt set-bootable <interface> <dev> <partition list> |
Joshua Watt | 44c5d77 | 2023-08-31 10:51:35 -0600 | [diff] [blame] | 17 | gpt setenv <interface> <dev> <partition name> |
| 18 | gpt swap <interface> <dev> <name1> <name2> |
Joshua Watt | 7cc1d87 | 2023-08-31 10:51:41 -0600 | [diff] [blame] | 19 | gpt transpose <interface> <dev> <part1> <part2> |
Joshua Watt | 44c5d77 | 2023-08-31 10:51:35 -0600 | [diff] [blame] | 20 | gpt verify <interface> <dev> [<partition string>] |
| 21 | gpt write <interface> <dev> <partition string> |
| 22 | |
| 23 | Description |
| 24 | ----------- |
| 25 | |
| 26 | The gpt command lets users read, create, modify, or verify the GPT (GUID |
| 27 | Partition Table) partition layout. |
| 28 | |
| 29 | Common arguments: |
| 30 | |
| 31 | interface |
| 32 | interface for accessing the block device (mmc, sata, scsi, usb, ....) |
| 33 | |
| 34 | dev |
| 35 | device number |
| 36 | |
| 37 | partition string |
| 38 | Describes the GPT partition layout for a disk. The syntax is similar to |
| 39 | the one used by the :doc:`mbr command <mbr>` command. The string contains |
| 40 | one or more partition descriptors, each separated by a ";". Each descriptor |
| 41 | contains one or more fields, with each field separated by a ",". Fields are |
| 42 | either of the form "key=value" to set a specific value, or simple "flag" to |
| 43 | set a boolean flag |
| 44 | |
| 45 | The first descriptor can optionally be used to describe parameters for the |
| 46 | whole disk with the following fields: |
| 47 | |
| 48 | * uuid_disk=UUID - Set the UUID for the disk |
| 49 | |
| 50 | Partition descriptors can have the following fields: |
| 51 | |
| 52 | * name=<NAME> - The partition name, required |
| 53 | * start=<BYTES> - The partition start offset in bytes, required |
| 54 | * size=<BYTES> - The partition size in bytes or "-" to expand it to the whole free area |
| 55 | * bootable - Set the legacy bootable flag |
| 56 | * uuid=<UUID> - The partition UUID, optional if CONFIG_RANDOM_UUID=y is enabled |
| 57 | * type=<UUID> - The partition type GUID, requires CONFIG_PARTITION_TYPE_GUID=y |
| 58 | |
| 59 | |
| 60 | If 'uuid' is not specified, but CONFIG_RANDOM_UUID is enabled, a random UUID |
| 61 | will be generated for the partition |
| 62 | |
| 63 | gpt enumerate |
| 64 | ~~~~~~~~~~~~~ |
| 65 | |
| 66 | Sets the variable 'gpt_partition_list' to be a list of all the partition names |
| 67 | on the device. |
| 68 | |
| 69 | gpt guid |
| 70 | ~~~~~~~~ |
| 71 | |
| 72 | Report the GUID of a disk. If 'varname' is specified, the command will set the |
| 73 | variable to the GUID, otherwise it will be printed out. |
| 74 | |
| 75 | gpt read |
| 76 | ~~~~~~~~ |
| 77 | |
| 78 | Prints the current state of the GPT partition table. If 'varname' is specified, |
| 79 | the variable will be filled with a partition string in the same format as a |
| 80 | '<partition string>', suitable for passing to other 'gpt' commands. If the |
| 81 | argument is omitted, a human readable description is printed out. |
| 82 | CONFIG_CMD_GPT_RENAME=y is required. |
| 83 | |
| 84 | gpt rename |
| 85 | ~~~~~~~~~~ |
| 86 | |
| 87 | Renames all partitions named 'part' to be 'name'. CONFIG_CMD_GPT_RENAME=y is |
| 88 | required. |
| 89 | |
| 90 | gpt repair |
| 91 | ~~~~~~~~~~ |
| 92 | |
| 93 | Repairs the GPT partition tables if it they become corrupted. |
| 94 | |
Joshua Watt | a1e793a | 2023-08-31 10:51:38 -0600 | [diff] [blame] | 95 | gpt set-bootable |
| 96 | ~~~~~~~~~~~~~~~~ |
| 97 | |
| 98 | Sets the bootable flag for all partitions in the table. If the partition name |
| 99 | is in 'partition list' (separated by ','), the bootable flag is set, otherwise |
| 100 | it is cleared. CONFIG_CMD_GPT_RENAME=y is required. |
| 101 | |
Joshua Watt | 44c5d77 | 2023-08-31 10:51:35 -0600 | [diff] [blame] | 102 | gpt setenv |
| 103 | ~~~~~~~~~~ |
| 104 | |
| 105 | The 'gpt setenv' command will set a series of environment variables with |
| 106 | information about the partition named '<partition name>'. The variables are: |
| 107 | |
| 108 | gpt_partition_addr |
| 109 | the starting offset of the partition in blocks as a hexadecimal number |
| 110 | |
| 111 | gpt_partition_size |
| 112 | the size of the partition in blocks as a hexadecimal number |
| 113 | |
| 114 | gpt_partition_name |
| 115 | the name of the partition |
| 116 | |
| 117 | gpt_partition_entry |
| 118 | the partition number in the table, e.g. 1, 2, 3, etc. |
| 119 | |
Joshua Watt | b1433af | 2023-08-31 10:51:37 -0600 | [diff] [blame] | 120 | gpt_partition_bootable |
| 121 | 1 if the partition is marked as bootable, 0 if not |
| 122 | |
Joshua Watt | 44c5d77 | 2023-08-31 10:51:35 -0600 | [diff] [blame] | 123 | gpt swap |
| 124 | ~~~~~~~~ |
| 125 | |
| 126 | Changes the names of all partitions that are named 'name1' to be 'name2', and |
| 127 | all partitions named 'name2' to be 'name1'. CONFIG_CMD_GPT_RENAME=y is |
| 128 | required. |
| 129 | |
Joshua Watt | 7cc1d87 | 2023-08-31 10:51:41 -0600 | [diff] [blame] | 130 | gpt transpose |
| 131 | ~~~~~~~~~~~~~ |
| 132 | |
| 133 | Swaps the order of two partition table entries with indexes 'part1' and 'part2' |
| 134 | in the partition table, but otherwise leaves the actual partition data |
| 135 | untouched. |
| 136 | |
Joshua Watt | 44c5d77 | 2023-08-31 10:51:35 -0600 | [diff] [blame] | 137 | gpt verify |
| 138 | ~~~~~~~~~~ |
| 139 | |
| 140 | Sets return value $? to 0 (true) if the partition layout on the |
| 141 | specified disk matches the one in the provided partition string, and 1 (false) |
| 142 | if it does not match. If no partition string is specified, the command will |
| 143 | check if the disk is partitioned or not. |
| 144 | |
| 145 | gpt write |
| 146 | ~~~~~~~~~ |
| 147 | |
| 148 | (Re)writes the partition table on the disk to match the provided |
| 149 | partition string. It returns 0 on success or 1 on failure. |
| 150 | |
| 151 | Configuration |
| 152 | ------------- |
| 153 | |
| 154 | To use the 'gpt' command you must specify CONFIG_CMD_GPT=y. To enable 'gpt |
| 155 | read', 'gpt swap' and 'gpt rename', you must specify CONFIG_CMD_GPT_RENAME=y. |
| 156 | |
| 157 | Examples |
| 158 | ~~~~~~~~ |
Tom Fitzhenry | 4416a9c | 2023-10-24 22:59:06 +1100 | [diff] [blame^] | 159 | |
Joshua Watt | 44c5d77 | 2023-08-31 10:51:35 -0600 | [diff] [blame] | 160 | Create 6 partitions on a disk:: |
| 161 | |
| 162 | => setenv gpt_parts 'uuid_disk=bec9fc2a-86c1-483d-8a0e-0109732277d7; |
| 163 | name=boot,start=4M,size=128M,bootable,type=ebd0a0a2-b9e5-4433-87c0-68b6b72699c7, |
| 164 | name=rootfs,size=3072M,type=0fc63daf-8483-4772-8e79-3d69d8477de4; |
| 165 | name=system-data,size=512M,type=0fc63daf-8483-4772-8e79-3d69d8477de4; |
| 166 | name=[ext],size=-,type=0fc63daf-8483-4772-8e79-3d69d8477de4; |
| 167 | name=user,size=-,type=0fc63daf-8483-4772-8e79-3d69d8477de4; |
| 168 | name=modules,size=100M,type=0fc63daf-8483-4772-8e79-3d69d8477de4; |
| 169 | name=ramdisk,size=8M,type=0fc63daf-8483-4772-8e79-3d69d8477de4 |
| 170 | => gpt write mmc 0 $gpt_parts |
| 171 | |
| 172 | |
| 173 | Verify that the device matches the partition layout described in the variable |
| 174 | $gpt_parts:: |
| 175 | |
| 176 | => gpt verify mmc 0 $gpt_parts |
| 177 | |
| 178 | |
| 179 | Get the information about the partition named 'rootfs':: |
| 180 | |
| 181 | => gpt setenv mmc 0 rootfs |
| 182 | => echo ${gpt_partition_addr} |
| 183 | 2000 |
| 184 | => echo ${gpt_partition_size} |
| 185 | 14a000 |
| 186 | => echo ${gpt_partition_name} |
| 187 | rootfs |
| 188 | => echo ${gpt_partition_entry} |
| 189 | 2 |
Joshua Watt | b1433af | 2023-08-31 10:51:37 -0600 | [diff] [blame] | 190 | => echo ${gpt_partition_bootable} |
| 191 | 0 |
Joshua Watt | 44c5d77 | 2023-08-31 10:51:35 -0600 | [diff] [blame] | 192 | |
| 193 | Get the list of partition names on the disk:: |
| 194 | |
| 195 | => gpt enumerate |
Tom Fitzhenry | 4416a9c | 2023-10-24 22:59:06 +1100 | [diff] [blame^] | 196 | => echo ${gpt_partition_list} |
Joshua Watt | 44c5d77 | 2023-08-31 10:51:35 -0600 | [diff] [blame] | 197 | boot rootfs system-data [ext] user modules ramdisk |
| 198 | |
Joshua Watt | 44c5d77 | 2023-08-31 10:51:35 -0600 | [diff] [blame] | 199 | Get the GUID for a disk:: |
| 200 | |
| 201 | => gpt guid mmc 0 |
| 202 | bec9fc2a-86c1-483d-8a0e-0109732277d7 |
| 203 | => gpt guid mmc gpt_disk_uuid |
| 204 | => echo ${gpt_disk_uuid} |
| 205 | bec9fc2a-86c1-483d-8a0e-0109732277d7 |
Joshua Watt | a1e793a | 2023-08-31 10:51:38 -0600 | [diff] [blame] | 206 | |
| 207 | Set the bootable flag for the 'boot' partition and clear it for all others:: |
| 208 | |
| 209 | => gpt set-bootable mmc 0 boot |
Joshua Watt | 7cc1d87 | 2023-08-31 10:51:41 -0600 | [diff] [blame] | 210 | |
| 211 | Swap the order of the 'boot' and 'rootfs' partition table entries:: |
Tom Fitzhenry | 4416a9c | 2023-10-24 22:59:06 +1100 | [diff] [blame^] | 212 | |
Joshua Watt | 7cc1d87 | 2023-08-31 10:51:41 -0600 | [diff] [blame] | 213 | => gpt setenv mmc 0 rootfs |
| 214 | => echo ${gpt_partition_entry} |
| 215 | 2 |
| 216 | => gpt setenv mmc 0 boot |
| 217 | => echo ${gpt_partition_entry} |
| 218 | 1 |
| 219 | |
| 220 | => gpt transpose mmc 0 1 2 |
| 221 | |
| 222 | => gpt setenv mmc 0 rootfs |
| 223 | => echo ${gpt_partition_entry} |
| 224 | 1 |
| 225 | => gpt setenv mmc 0 boot |
| 226 | => echo ${gpt_partition_entry} |
| 227 | 2 |