blob: b505b159d0afc76ae539946db571b8ae388d9e08 [file] [log] [blame]
Joshua Watt446de7c2023-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>
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
21Description
22-----------
23
24The gpt command lets users read, create, modify, or verify the GPT (GUID
25Partition Table) partition layout.
26
27Common arguments:
28
29interface
30 interface for accessing the block device (mmc, sata, scsi, usb, ....)
31
32dev
33 device number
34
35partition 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
61gpt enumerate
62~~~~~~~~~~~~~
63
64Sets the variable 'gpt_partition_list' to be a list of all the partition names
65on the device.
66
67gpt guid
68~~~~~~~~
69
70Report the GUID of a disk. If 'varname' is specified, the command will set the
71variable to the GUID, otherwise it will be printed out.
72
73gpt read
74~~~~~~~~
75
76Prints the current state of the GPT partition table. If 'varname' is specified,
77the 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
79argument is omitted, a human readable description is printed out.
80CONFIG_CMD_GPT_RENAME=y is required.
81
82gpt rename
83~~~~~~~~~~
84
85Renames all partitions named 'part' to be 'name'. CONFIG_CMD_GPT_RENAME=y is
86required.
87
88gpt repair
89~~~~~~~~~~
90
91Repairs the GPT partition tables if it they become corrupted.
92
93gpt setenv
94~~~~~~~~~~
95
96The 'gpt setenv' command will set a series of environment variables with
97information about the partition named '<partition name>'. The variables are:
98
99gpt_partition_addr
100 the starting offset of the partition in blocks as a hexadecimal number
101
102gpt_partition_size
103 the size of the partition in blocks as a hexadecimal number
104
105gpt_partition_name
106 the name of the partition
107
108gpt_partition_entry
109 the partition number in the table, e.g. 1, 2, 3, etc.
110
Joshua Wattfd1134e2023-08-31 10:51:37 -0600111gpt_partition_bootable
112 1 if the partition is marked as bootable, 0 if not
113
Joshua Watt446de7c2023-08-31 10:51:35 -0600114gpt swap
115~~~~~~~~
116
117Changes the names of all partitions that are named 'name1' to be 'name2', and
118all partitions named 'name2' to be 'name1'. CONFIG_CMD_GPT_RENAME=y is
119required.
120
121gpt verify
122~~~~~~~~~~
123
124Sets return value $? to 0 (true) if the partition layout on the
125specified disk matches the one in the provided partition string, and 1 (false)
126if it does not match. If no partition string is specified, the command will
127check if the disk is partitioned or not.
128
129gpt write
130~~~~~~~~~
131
132(Re)writes the partition table on the disk to match the provided
133partition string. It returns 0 on success or 1 on failure.
134
135Configuration
136-------------
137
138To use the 'gpt' command you must specify CONFIG_CMD_GPT=y. To enable 'gpt
139read', 'gpt swap' and 'gpt rename', you must specify CONFIG_CMD_GPT_RENAME=y.
140
141Examples
142~~~~~~~~
143Create 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
156Verify that the device matches the partition layout described in the variable
157$gpt_parts::
158
159 => gpt verify mmc 0 $gpt_parts
160
161
162Get 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 Wattfd1134e2023-08-31 10:51:37 -0600173 => echo ${gpt_partition_bootable}
174 0
Joshua Watt446de7c2023-08-31 10:51:35 -0600175
176Get 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
183Get 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