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