blob: 8534f78cbac05bf04b9d1e2347dc16aa01d0e95c [file] [log] [blame]
Joshua Watt446de7c2023-08-31 10:51:35 -06001.. SPDX-License-Identifier: GPL-2.0+
2
Heinrich Schuchardt1b0c3162024-01-14 14:53:13 +01003.. index::
4 single: gpt (command)
5
Joshua Watt446de7c2023-08-31 10:51:35 -06006gpt command
7===========
8
9Synopsis
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 Watt44d62332023-08-31 10:51:38 -060019 gpt set-bootable <interface> <dev> <partition list>
Joshua Watt446de7c2023-08-31 10:51:35 -060020 gpt setenv <interface> <dev> <partition name>
21 gpt swap <interface> <dev> <name1> <name2>
Joshua Wattd88ba5f2023-08-31 10:51:41 -060022 gpt transpose <interface> <dev> <part1> <part2>
Joshua Watt446de7c2023-08-31 10:51:35 -060023 gpt verify <interface> <dev> [<partition string>]
24 gpt write <interface> <dev> <partition string>
25
26Description
27-----------
28
29The gpt command lets users read, create, modify, or verify the GPT (GUID
30Partition Table) partition layout.
31
32Common arguments:
33
34interface
35 interface for accessing the block device (mmc, sata, scsi, usb, ....)
36
37dev
38 device number
39
40partition 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
57 * size=<BYTES> - The partition size in bytes or "-" to expand it to the whole free area
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
66gpt enumerate
67~~~~~~~~~~~~~
68
69Sets the variable 'gpt_partition_list' to be a list of all the partition names
70on the device.
71
72gpt guid
73~~~~~~~~
74
75Report the GUID of a disk. If 'varname' is specified, the command will set the
76variable to the GUID, otherwise it will be printed out.
77
78gpt read
79~~~~~~~~
80
81Prints the current state of the GPT partition table. If 'varname' is specified,
82the variable will be filled with a partition string in the same format as a
83'<partition string>', suitable for passing to other 'gpt' commands. If the
84argument is omitted, a human readable description is printed out.
85CONFIG_CMD_GPT_RENAME=y is required.
86
87gpt rename
88~~~~~~~~~~
89
90Renames all partitions named 'part' to be 'name'. CONFIG_CMD_GPT_RENAME=y is
91required.
92
93gpt repair
94~~~~~~~~~~
95
96Repairs the GPT partition tables if it they become corrupted.
97
Joshua Watt44d62332023-08-31 10:51:38 -060098gpt set-bootable
99~~~~~~~~~~~~~~~~
100
101Sets the bootable flag for all partitions in the table. If the partition name
102is in 'partition list' (separated by ','), the bootable flag is set, otherwise
103it is cleared. CONFIG_CMD_GPT_RENAME=y is required.
104
Joshua Watt446de7c2023-08-31 10:51:35 -0600105gpt setenv
106~~~~~~~~~~
107
108The 'gpt setenv' command will set a series of environment variables with
109information about the partition named '<partition name>'. The variables are:
110
111gpt_partition_addr
112 the starting offset of the partition in blocks as a hexadecimal number
113
114gpt_partition_size
115 the size of the partition in blocks as a hexadecimal number
116
117gpt_partition_name
118 the name of the partition
119
120gpt_partition_entry
121 the partition number in the table, e.g. 1, 2, 3, etc.
122
Joshua Wattfd1134e2023-08-31 10:51:37 -0600123gpt_partition_bootable
124 1 if the partition is marked as bootable, 0 if not
125
Joshua Watt446de7c2023-08-31 10:51:35 -0600126gpt swap
127~~~~~~~~
128
129Changes the names of all partitions that are named 'name1' to be 'name2', and
130all partitions named 'name2' to be 'name1'. CONFIG_CMD_GPT_RENAME=y is
131required.
132
Joshua Wattd88ba5f2023-08-31 10:51:41 -0600133gpt transpose
134~~~~~~~~~~~~~
135
136Swaps the order of two partition table entries with indexes 'part1' and 'part2'
137in the partition table, but otherwise leaves the actual partition data
138untouched.
139
Joshua Watt446de7c2023-08-31 10:51:35 -0600140gpt verify
141~~~~~~~~~~
142
143Sets return value $? to 0 (true) if the partition layout on the
144specified disk matches the one in the provided partition string, and 1 (false)
145if it does not match. If no partition string is specified, the command will
146check if the disk is partitioned or not.
147
148gpt write
149~~~~~~~~~
150
151(Re)writes the partition table on the disk to match the provided
152partition string. It returns 0 on success or 1 on failure.
153
154Configuration
155-------------
156
157To use the 'gpt' command you must specify CONFIG_CMD_GPT=y. To enable 'gpt
158read', 'gpt swap' and 'gpt rename', you must specify CONFIG_CMD_GPT_RENAME=y.
159
160Examples
161~~~~~~~~
Tom Fitzhenrybc364552023-10-24 22:59:06 +1100162
Joshua Watt446de7c2023-08-31 10:51:35 -0600163Create 6 partitions on a disk::
164
165 => setenv gpt_parts 'uuid_disk=bec9fc2a-86c1-483d-8a0e-0109732277d7;
166 name=boot,start=4M,size=128M,bootable,type=ebd0a0a2-b9e5-4433-87c0-68b6b72699c7,
167 name=rootfs,size=3072M,type=0fc63daf-8483-4772-8e79-3d69d8477de4;
168 name=system-data,size=512M,type=0fc63daf-8483-4772-8e79-3d69d8477de4;
169 name=[ext],size=-,type=0fc63daf-8483-4772-8e79-3d69d8477de4;
170 name=user,size=-,type=0fc63daf-8483-4772-8e79-3d69d8477de4;
171 name=modules,size=100M,type=0fc63daf-8483-4772-8e79-3d69d8477de4;
172 name=ramdisk,size=8M,type=0fc63daf-8483-4772-8e79-3d69d8477de4
173 => gpt write mmc 0 $gpt_parts
174
175
176Verify that the device matches the partition layout described in the variable
177$gpt_parts::
178
179 => gpt verify mmc 0 $gpt_parts
180
181
182Get the information about the partition named 'rootfs'::
183
184 => gpt setenv mmc 0 rootfs
185 => echo ${gpt_partition_addr}
186 2000
187 => echo ${gpt_partition_size}
188 14a000
189 => echo ${gpt_partition_name}
190 rootfs
191 => echo ${gpt_partition_entry}
192 2
Joshua Wattfd1134e2023-08-31 10:51:37 -0600193 => echo ${gpt_partition_bootable}
194 0
Joshua Watt446de7c2023-08-31 10:51:35 -0600195
196Get the list of partition names on the disk::
197
198 => gpt enumerate
Tom Fitzhenrybc364552023-10-24 22:59:06 +1100199 => echo ${gpt_partition_list}
Joshua Watt446de7c2023-08-31 10:51:35 -0600200 boot rootfs system-data [ext] user modules ramdisk
201
Joshua Watt446de7c2023-08-31 10:51:35 -0600202Get the GUID for a disk::
203
204 => gpt guid mmc 0
205 bec9fc2a-86c1-483d-8a0e-0109732277d7
206 => gpt guid mmc gpt_disk_uuid
207 => echo ${gpt_disk_uuid}
208 bec9fc2a-86c1-483d-8a0e-0109732277d7
Joshua Watt44d62332023-08-31 10:51:38 -0600209
210Set the bootable flag for the 'boot' partition and clear it for all others::
211
212 => gpt set-bootable mmc 0 boot
Joshua Wattd88ba5f2023-08-31 10:51:41 -0600213
214Swap the order of the 'boot' and 'rootfs' partition table entries::
Tom Fitzhenrybc364552023-10-24 22:59:06 +1100215
Joshua Wattd88ba5f2023-08-31 10:51:41 -0600216 => gpt setenv mmc 0 rootfs
217 => echo ${gpt_partition_entry}
218 2
219 => gpt setenv mmc 0 boot
220 => echo ${gpt_partition_entry}
221 1
222
223 => gpt transpose mmc 0 1 2
224
225 => gpt setenv mmc 0 rootfs
226 => echo ${gpt_partition_entry}
227 1
228 => gpt setenv mmc 0 boot
229 => echo ${gpt_partition_entry}
230 2