gpt.rst 5.4 KB

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