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 | ~~~~~~~~ |
| 159 | Create 6 partitions on a disk:: |
| 160 | |
| 161 | => setenv gpt_parts 'uuid_disk=bec9fc2a-86c1-483d-8a0e-0109732277d7; |
| 162 | name=boot,start=4M,size=128M,bootable,type=ebd0a0a2-b9e5-4433-87c0-68b6b72699c7, |
| 163 | name=rootfs,size=3072M,type=0fc63daf-8483-4772-8e79-3d69d8477de4; |
| 164 | name=system-data,size=512M,type=0fc63daf-8483-4772-8e79-3d69d8477de4; |
| 165 | name=[ext],size=-,type=0fc63daf-8483-4772-8e79-3d69d8477de4; |
| 166 | name=user,size=-,type=0fc63daf-8483-4772-8e79-3d69d8477de4; |
| 167 | name=modules,size=100M,type=0fc63daf-8483-4772-8e79-3d69d8477de4; |
| 168 | name=ramdisk,size=8M,type=0fc63daf-8483-4772-8e79-3d69d8477de4 |
| 169 | => gpt write mmc 0 $gpt_parts |
| 170 | |
| 171 | |
| 172 | Verify that the device matches the partition layout described in the variable |
| 173 | $gpt_parts:: |
| 174 | |
| 175 | => gpt verify mmc 0 $gpt_parts |
| 176 | |
| 177 | |
| 178 | Get the information about the partition named 'rootfs':: |
| 179 | |
| 180 | => gpt setenv mmc 0 rootfs |
| 181 | => echo ${gpt_partition_addr} |
| 182 | 2000 |
| 183 | => echo ${gpt_partition_size} |
| 184 | 14a000 |
| 185 | => echo ${gpt_partition_name} |
| 186 | rootfs |
| 187 | => echo ${gpt_partition_entry} |
| 188 | 2 |
Joshua Watt | b1433af | 2023-08-31 10:51:37 -0600 | [diff] [blame] | 189 | => echo ${gpt_partition_bootable} |
| 190 | 0 |
Joshua Watt | 44c5d77 | 2023-08-31 10:51:35 -0600 | [diff] [blame] | 191 | |
| 192 | Get the list of partition names on the disk:: |
| 193 | |
| 194 | => gpt enumerate |
| 195 | => echo gpt_partition_list |
| 196 | boot rootfs system-data [ext] user modules ramdisk |
| 197 | |
| 198 | |
| 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:: |
| 212 | => gpt setenv mmc 0 rootfs |
| 213 | => echo ${gpt_partition_entry} |
| 214 | 2 |
| 215 | => gpt setenv mmc 0 boot |
| 216 | => echo ${gpt_partition_entry} |
| 217 | 1 |
| 218 | |
| 219 | => gpt transpose mmc 0 1 2 |
| 220 | |
| 221 | => gpt setenv mmc 0 rootfs |
| 222 | => echo ${gpt_partition_entry} |
| 223 | 1 |
| 224 | => gpt setenv mmc 0 boot |
| 225 | => echo ${gpt_partition_entry} |
| 226 | 2 |