blob: 6387c8116fe5d60e65fe4147207bf69780c34097 [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
111gpt swap
112~~~~~~~~
113
114Changes the names of all partitions that are named 'name1' to be 'name2', and
115all partitions named 'name2' to be 'name1'. CONFIG_CMD_GPT_RENAME=y is
116required.
117
118gpt verify
119~~~~~~~~~~
120
121Sets return value $? to 0 (true) if the partition layout on the
122specified disk matches the one in the provided partition string, and 1 (false)
123if it does not match. If no partition string is specified, the command will
124check if the disk is partitioned or not.
125
126gpt write
127~~~~~~~~~
128
129(Re)writes the partition table on the disk to match the provided
130partition string. It returns 0 on success or 1 on failure.
131
132Configuration
133-------------
134
135To use the 'gpt' command you must specify CONFIG_CMD_GPT=y. To enable 'gpt
136read', 'gpt swap' and 'gpt rename', you must specify CONFIG_CMD_GPT_RENAME=y.
137
138Examples
139~~~~~~~~
140Create 6 partitions on a disk::
141
142 => setenv gpt_parts 'uuid_disk=bec9fc2a-86c1-483d-8a0e-0109732277d7;
143 name=boot,start=4M,size=128M,bootable,type=ebd0a0a2-b9e5-4433-87c0-68b6b72699c7,
144 name=rootfs,size=3072M,type=0fc63daf-8483-4772-8e79-3d69d8477de4;
145 name=system-data,size=512M,type=0fc63daf-8483-4772-8e79-3d69d8477de4;
146 name=[ext],size=-,type=0fc63daf-8483-4772-8e79-3d69d8477de4;
147 name=user,size=-,type=0fc63daf-8483-4772-8e79-3d69d8477de4;
148 name=modules,size=100M,type=0fc63daf-8483-4772-8e79-3d69d8477de4;
149 name=ramdisk,size=8M,type=0fc63daf-8483-4772-8e79-3d69d8477de4
150 => gpt write mmc 0 $gpt_parts
151
152
153Verify that the device matches the partition layout described in the variable
154$gpt_parts::
155
156 => gpt verify mmc 0 $gpt_parts
157
158
159Get the information about the partition named 'rootfs'::
160
161 => gpt setenv mmc 0 rootfs
162 => echo ${gpt_partition_addr}
163 2000
164 => echo ${gpt_partition_size}
165 14a000
166 => echo ${gpt_partition_name}
167 rootfs
168 => echo ${gpt_partition_entry}
169 2
170
171Get the list of partition names on the disk::
172
173 => gpt enumerate
174 => echo gpt_partition_list
175 boot rootfs system-data [ext] user modules ramdisk
176
177
178Get the GUID for a disk::
179
180 => gpt guid mmc 0
181 bec9fc2a-86c1-483d-8a0e-0109732277d7
182 => gpt guid mmc gpt_disk_uuid
183 => echo ${gpt_disk_uuid}
184 bec9fc2a-86c1-483d-8a0e-0109732277d7