blob: f6115ecb0ee99af5f717674c1643d6e1ec350f30 [file] [log] [blame]
Joshua Watt44c5d772023-08-31 10:51:35 -06001.. SPDX-License-Identifier: GPL-2.0+
2
3gpt command
4===========
5
6Synopsis
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 Watta1e793a2023-08-31 10:51:38 -060016 gpt set-bootable <interface> <dev> <partition list>
Joshua Watt44c5d772023-08-31 10:51:35 -060017 gpt setenv <interface> <dev> <partition name>
18 gpt swap <interface> <dev> <name1> <name2>
Joshua Watt7cc1d872023-08-31 10:51:41 -060019 gpt transpose <interface> <dev> <part1> <part2>
Joshua Watt44c5d772023-08-31 10:51:35 -060020 gpt verify <interface> <dev> [<partition string>]
21 gpt write <interface> <dev> <partition string>
22
23Description
24-----------
25
26The gpt command lets users read, create, modify, or verify the GPT (GUID
27Partition Table) partition layout.
28
29Common arguments:
30
31interface
32 interface for accessing the block device (mmc, sata, scsi, usb, ....)
33
34dev
35 device number
36
37partition 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
63gpt enumerate
64~~~~~~~~~~~~~
65
66Sets the variable 'gpt_partition_list' to be a list of all the partition names
67on the device.
68
69gpt guid
70~~~~~~~~
71
72Report the GUID of a disk. If 'varname' is specified, the command will set the
73variable to the GUID, otherwise it will be printed out.
74
75gpt read
76~~~~~~~~
77
78Prints the current state of the GPT partition table. If 'varname' is specified,
79the 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
81argument is omitted, a human readable description is printed out.
82CONFIG_CMD_GPT_RENAME=y is required.
83
84gpt rename
85~~~~~~~~~~
86
87Renames all partitions named 'part' to be 'name'. CONFIG_CMD_GPT_RENAME=y is
88required.
89
90gpt repair
91~~~~~~~~~~
92
93Repairs the GPT partition tables if it they become corrupted.
94
Joshua Watta1e793a2023-08-31 10:51:38 -060095gpt set-bootable
96~~~~~~~~~~~~~~~~
97
98Sets the bootable flag for all partitions in the table. If the partition name
99is in 'partition list' (separated by ','), the bootable flag is set, otherwise
100it is cleared. CONFIG_CMD_GPT_RENAME=y is required.
101
Joshua Watt44c5d772023-08-31 10:51:35 -0600102gpt setenv
103~~~~~~~~~~
104
105The 'gpt setenv' command will set a series of environment variables with
106information about the partition named '<partition name>'. The variables are:
107
108gpt_partition_addr
109 the starting offset of the partition in blocks as a hexadecimal number
110
111gpt_partition_size
112 the size of the partition in blocks as a hexadecimal number
113
114gpt_partition_name
115 the name of the partition
116
117gpt_partition_entry
118 the partition number in the table, e.g. 1, 2, 3, etc.
119
Joshua Wattb1433af2023-08-31 10:51:37 -0600120gpt_partition_bootable
121 1 if the partition is marked as bootable, 0 if not
122
Joshua Watt44c5d772023-08-31 10:51:35 -0600123gpt swap
124~~~~~~~~
125
126Changes the names of all partitions that are named 'name1' to be 'name2', and
127all partitions named 'name2' to be 'name1'. CONFIG_CMD_GPT_RENAME=y is
128required.
129
Joshua Watt7cc1d872023-08-31 10:51:41 -0600130gpt transpose
131~~~~~~~~~~~~~
132
133Swaps the order of two partition table entries with indexes 'part1' and 'part2'
134in the partition table, but otherwise leaves the actual partition data
135untouched.
136
Joshua Watt44c5d772023-08-31 10:51:35 -0600137gpt verify
138~~~~~~~~~~
139
140Sets return value $? to 0 (true) if the partition layout on the
141specified disk matches the one in the provided partition string, and 1 (false)
142if it does not match. If no partition string is specified, the command will
143check if the disk is partitioned or not.
144
145gpt write
146~~~~~~~~~
147
148(Re)writes the partition table on the disk to match the provided
149partition string. It returns 0 on success or 1 on failure.
150
151Configuration
152-------------
153
154To use the 'gpt' command you must specify CONFIG_CMD_GPT=y. To enable 'gpt
155read', 'gpt swap' and 'gpt rename', you must specify CONFIG_CMD_GPT_RENAME=y.
156
157Examples
158~~~~~~~~
159Create 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
172Verify that the device matches the partition layout described in the variable
173$gpt_parts::
174
175 => gpt verify mmc 0 $gpt_parts
176
177
178Get 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 Wattb1433af2023-08-31 10:51:37 -0600189 => echo ${gpt_partition_bootable}
190 0
Joshua Watt44c5d772023-08-31 10:51:35 -0600191
192Get 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
199Get 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 Watta1e793a2023-08-31 10:51:38 -0600206
207Set the bootable flag for the 'boot' partition and clear it for all others::
208
209 => gpt set-bootable mmc 0 boot
Joshua Watt7cc1d872023-08-31 10:51:41 -0600210
211Swap 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