NAME
gpt —
GUID partition table maintenance
utility
SYNOPSIS
gpt |
[-nrqv] [-m
mediasize] [-s
sectorsize] [-T
timestamp] command
[command_options] device |
gpt |
set -l |
gpt |
unset -l |
gpt |
type -l |
DESCRIPTION
Thegpt utility provides the necessary functionality to
manipulate GUID partition tables (GPTs), but see
BUGS below for how and where functionality is
missing. The basic usage model of the gpt tool follows
that of the cvs(1) tool. The general options are described in the following
paragraph. The remaining paragraphs describe the individual commands with
their options. Here we conclude by mentioning that a
device is either a special file corresponding to a
disk-like device or a regular file. The command is applied to each
device listed on the command line.
General Options
The general options allow the user to change default settings or otherwise change the behaviour that is applicable to all commands. Not all commands use all default settings, so some general options may not have an effect on all commands.
-mmediasize- Override the default media size for the device (obtained from the kernel if possible) or defaulting to the file size for plain files.
-n- Do not update the wedge information that
gptchanged. You need to use the dkctl(8) command manually update the device's wedge configuration if you do that. -r- Open the device for reading only.
gptCurrently this option is primarily useful for theshowcommand, but the intent is to use it to implement dry-run behaviour. -q- Do not print error messages. This is not implemented completely yet.
-ssectorsize- Override the default sector size for the device (obtained from the kernel
if possible) or
512for plain files. -Ttimestamp- Specify a timestamp to be used for uuid generation so that uuids are not random and can be consistent for reproducible builds. The timestamp can be a pathname, where the timestamps are derived from that file, a parseable date for parsedate(3) (this option is not yet available in the tools build), or an integer value interpreted as the number of seconds from the Epoch.
-v- Controls the verbosity level. The level increases with every occurrence of this option. There is no formalized definition of the different levels yet.
Commands
gptadd[-aalignment] [-bblocknr] [-iindex] [-llabel] [-ssize] [-ttype]- The
addcommand allows the user to add a new partition to an existing table. By default, it will create a UFS partition covering the first available block of an unused disk space. The command-specific options can be used to control this behaviour.The
-aalignment option allows the user to specify an alignment for the start and size. The alignment is given in bytes and may have a suffix to indicate its magnitude.gptwill attempt to align the partition.The
-bblocknr option allows the user to specify the starting (beginning) sector number of the partition. The minimum sector number is 1, but has to fall inside an unused region of disk space that is covered by the GPT.The
-iindex option allows the user to specify which (free) entry in the GPT table is to be used for the new partition. By default, the first free entry is selected.The
-llabel option allows the user to specify a label for the partition.The
-ssize option allows the user to specify the size of the partition. If there is no suffix, or the suffix is ‘s’ or ‘S’ then size is in sectors, otherwise size is in bytes which must be a multiple of the device's sector size. Accepted suffix units are ‘b’ to denote bytes, ‘k’ to denote kilobytes, ‘m’ to denote megabytes and ‘g’ to denote gigabytes. The minimum size is 1 sector.The
-ttype option allows the user to specify the partition type. The type is given as an UUID, butgptacceptsas aliases for the most commonly used partition types.apple- Apple HFS
apple-ufs- Apple UFS
bios- BIOS Boot
efi- EFI System
fbsd-legacy- FreeBSD legacy
fbsd-swap- FreeBSD swap
fbsd-ufs- FreeBSD UFS/UFS2
fbsd-vinum- FreeBSD vinum
fbsd-zfs- FreeBSD ZFS
linux-data- Linux data
linux-raid- Linux RAID
linux-swap- Linux swap
linux-lvm- Linux LVM
windows- Windows basic data
windows-reserved- Windows reserved
ccd- NetBSD ccd component
cgd- NetBSD Cryptographic Disk
ffs- NetBSD FFSv1/FFSv2
lfs- NetBSD LFS
raid- NetBSD RAIDFrame component
swap- NetBSD swap
gptbackup[-ooutfile]- The
backupcommand dumps the MBR or (PMBR) and GPT partition tables to standard output or to a file specified by the outfile argument in a format to be used by therestorecommand. The format is a plist. It should not be modified. gptbiosboot[-A] [-cbootcode] [-bstartsec] [-iindex] [-Llabel]- The
biosbootcommand allows the user to configure the partition that contains the primary bootstrap program, used during boot(8).The
-Aoptions sets the PMBR partition active.The
-coption allows the user to specify the filename thatgptshould read the bootcode from. The default is to read from /usr/mdec/gptmbr.bin.The
-ioption selects the partition that should contain the primary bootstrap code, as installed via installboot(8). The-Loption selects the partition by label. If there are multiple partitions with the same label, the first one found will be used. The-boptions selects the partition by start block. gptcreate[-AfP] [-ppartitions]- The
createcommand allows the user to create a new (empty) GPT. By default, one cannot create a GPT when the device contains a MBR, however this can be overridden with the-foption. If the-foption is specified, an existing MBR is destroyed and any partitions described by the MBR are lost.The
-Aoptions sets the PMBR partition active.The
-Poption tellsgptto create only the primary table and not the backup table. This option is only useful for debugging and should not be used otherwise.The
-poption changes the default number of partitions the GPT can accommodate. This is used whenever a new GPT is created. By default, thegptutility will create space for 128 partitions (or 32 sectors of 512 bytes). gptdestroy[-r]- The
destroycommand allows the user to destroy an existing, possibly not empty GPT.The
-roption instructsgptto destroy the table in a way that it can be recovered. gptheader- The
headercommand displays size information about the media and information from the GPT header if it exists. gptlabel[-a] ⟨-ffile |-llabel⟩gptlabel[-bblocknr] [-iindex] [-Llabel] [-ssectors] [-ttype] ⟨-ffile |-llabel⟩- The
labelcommand allows the user to label any partitions that match the selection. At least one of the following selection options must be specified.The
-aoption specifies that all partitions should be labeled. It is mutually exclusive with all other selection options.The
-bblocknr option selects the partition that starts at the given block number.The
-iindex option selects the partition with the given partition number.The
-Llabel option selects all partitions that have the given label. This can cause multiple partitions to be relabeled.The
-ssectors option selects all partitions that have the given size. This can cause multiple partitions to be labeled.The
-ttype option selects all partitions that have the given type. The type is given as an UUID or by the aliases that theaddcommand accepts. This can cause multiple partitions to be labeled.The
-ffile or-llabel options specify the new label to be assigned to the selected partitions. The-ffile option is used to read the label from the specified file. Only the first line is read from the file and the trailing newline character is stripped. If the file name is the dash or minus sign (-), the label is read from the standard input. The-llabel option is used to specify the label in the command line. The label is assumed to be encoded in UTF-8. gptmigrate[-Afs] [-ppartitions]- The
migratecommand allows the user to migrate an MBR-based disk partitioning into a GPT-based partitioning. By default, the MBR is not migrated when it contains partitions of an unknown type. This can be overridden with the-foption. Specifying the-foption will cause unknown partitions to be ignored and any data in it to be lost.The
-Aoptions sets the PMBR partition active.The
-soption prevents migrating BSD disk labels into GPT partitions by creating the GPT equivalent of a slice. Note that the-soption is not applicable to NetBSD partitions.The
-poption changes the default number of partitions the GPT can accommodate. This is used whenever a new GPT is created. By default, thegptutility will create space for 128 partitions (or 32 sectors of 512 bytes).The
migratecommand requires space at the beginning and the end of the device outside any partitions to store the GPTs. Space is required for the GPT header (which takes one sector) and the GPT partition table. See the-poption for the size of the GPT partition table. By default, just about all devices have a minimum of 62 sectors free at the beginning of the device, but do not have any free space at the end. For the default GPT partition table size on a 512 byte sector size device, 33 sectors at the end of the device would need to be freed. gptrecover- The
recovercommand tries to restore the GPT partition label from the backup near the end of the disk. It is very useful in case the primary label was deleted. gptremove[-a]gptremove[-bblocknr] [-iindex] [-Llabel] [-ssectors] [-ttype]- The
removecommand allows the user to remove any and all partitions that match the selection. It uses the same selection options as thelabelcommand. See above for a description of these options. Partitions are removed by clearing the partition type. No other information is changed. gptresize[-iindex] [-bstartsec] [-aalignment] [-ssize]- The
resizecommand allows the user to resize a partition. The partition may be shrunk and if there is sufficient free space immediately after it then it may be expanded. The-soption allows the new size to be specified, otherwise the partition will be increased to the maximum available size. If there is no suffix, or the suffix is ‘s’ or ‘S’ then size is in sectors, otherwise size is in bytes which must be a multiple of the device's sector size. Accepted suffix units are ‘b’ to denote bytes, ‘k’ to denote kilobytes, ‘m’ to denote megabytes and ‘g’ to denote gigabytes. The minimum size is 1 sector. If the-aoption is specified then the size will be adjusted to be a multiple of alignment if possible. gptresizedisk[-ssize]- The
resizediskcommand allows the user to resize a disk. With GPTs, a backup copy is stored at the end of the disk. If the underlying medium changes size (or is going to change size), then the backup copy needs to be moved to the new end of the disk, and the last sector available for data storage needs to be adjusted. This command does that. If the backup copy no longer exists due to the medium shrinking, then a new backup copy will be created using the primary copy.The
-soption allows the new size to be specified, otherwise the backup copy will automatically be placed at the current end of the disk. If there is no suffix, or the suffix is ‘s’ or ‘S’ then size is in sectors, otherwise size is in bytes which must be a multiple of the device's sector size. Accepted suffix units are ‘b’ to denote bytes, ‘k’ to denote kilobytes, ‘m’ to denote megabytes and ‘g’ to denote gigabytes. Using the-soption allows you to move the backup copy prior to resizing the medium. This is primarily useful when shrinking the medium. gptrestore[-F] [-iinfile]- The
restorecommand restores a partition table that was previously saved using thebackupcommand. The partition table is read from standard input or a file specified in the infile argument and is expected to be in the format of a plist. It assumes an empty disk. The-Foption can be used to blank the disk. The new disk does not have to be the same size as the old disk as long as all the partitions fit, asrestorewill automatically adjust. However, the new disk must use the same sector size as the old disk. gptset[-aattribute] [-N] [-iindex] [-bstartsec]gptset-l- The
setcommand sets various partition attributes. The-lflag lists all available attributes. The-aoption specifies which attributes to set and may be specified more than once, or the attributes can be comma-separated. If the-Noption and no-aoption are specified, all attributes are removed. The-ior the-boption specify which entry to update. The possible attributes are “biosboot”, “bootme”, “bootonce”, “bootfailed”, “noblockio”, and “required”. The biosboot flag is used to indicate which partition should be booted by legacy BIOS boot code. See thebiosbootcommand for more information. The bootme flag is used to indicate which partition should be booted by UEFI boot code. The other attributes are for compatibility with FreeBSD and are not currently used by NetBSD. They may be used by NetBSD in the future. gptshow[-aglu] [-iindex] [-bstartsec]- The
showcommand displays the current partitioning on the listed devices and gives an overall view of the disk contents. With the-goption the GPT partition GUID will be displayed instead of the GPT partition type. With the-loption the GPT partition label will be displayed instead of the GPT partition type. With the-uoption the GPT partition type is displayed as an UUID instead of in a user friendly form. With the-ior the-boption, all the details of a particular GPT partition will be displayed. The format of this display is subject to change. With the-aoption, all information for all GPT partitions (just like with-iindex) will be printed. None of the options have any effect on non-GPT partitions. The order of precedence for the options are:-a,-i,-l,-g,-u. gpttype[-a]-Tnewtypegpttype[-bblocknr] [-iindex] [-Llabel] [-ssectors] [-ttype]-Tnewtypegpttype-l- The
typecommand allows the user to change the type of any and all partitions that match the selection. It uses the same selection options as thelabelcommand. See above for a description of these options. The-lflag lists available types. gptunset-aattribute [-iindex] [-bstartsec]gptunset-l- The
unsetcommand unsets various partition attributes. The-lflag lists all available attributes. The-aoption specifies which attributes to unset and may be specified more than once. Alternatively a comma separated list of attributes can be used. The-ior the-boption specifies which entry to update. The possible attributes are “biosboot”, “bootme”, “bootonce”, “bootfailed”, “noblockio”, and “required”. The biosboot flag is used to indicate which partition should be booted by legacy BIOS boot code. See thebiosbootcommand for more information. The other attributes are for compatibility with FreeBSD and are not currently used by any NetBSD code. They may be used by NetBSD code in the future. gptuuid[-a]gptuuid[-bblocknr] [-iindex] [-Llabel] [-ssectors] [-ttype]- The
uuidcommand allows the user to change the UUID of any and all partitions that match the selection. It uses the same selection options as thelabelcommand. See above for a description of these options. If-ais used, then the header UUID is changed as well.The primary purpose of this command is for use after cloning a disk to prevent collisions when both disks are used in the same system.
EXIT STATUS
The gpt command exits with a failure
status (1) when the header command is used and no GPT header is found. This
can be used to check for the existence of a GPT in shell scripts.
EXAMPLES
nas# gpt show wd3
start size index contents
0 1 PMBR
1 3907029167
nas# gpt create wd3
nas# gpt show wd3
start size index contents
0 1 PMBR
1 1 Pri GPT header
2 32 Pri GPT table
34 3907029101
3907029135 32 Sec GPT table
3907029167 1 Sec GPT header
nas# gpt add -s 10486224 -t swap -i 1 wd3
nas# gpt label -i 1 -l swap_1 wd3
partition 1 on rwd3d labeled swap_1
nas# gpt show wd3
start size index contents
0 1 PMBR
1 1 Pri GPT header
2 32 Pri GPT table
34 10486224 1 GPT part - NetBSD swap
10486258 3896542877
3907029135 32 Sec GPT table
3907029167 1 Sec GPT header
nas# gpt show -l wd3
start size index contents
0 1 PMBR
1 1 Pri GPT header
2 32 Pri GPT table
34 10486224 1 GPT part - "swap_1"
10486258 3896542877
3907029135 32 Sec GPT table
3907029167 1 Sec GPT header
nas#
Booting from GPT on a BIOS system: this creates a bootable partition.
xotica# gpt create wd1 xotica# gpt add -b 1024 -l bootroot -t ffs -s 1g wd1 /dev/rwd1: Partition 1 added: 49f48d5a-b10e-11dc-b99b-0019d1879648 1024 2097152 xotica ~# dmesg | tail -2 wd1: GPT GUID: 660e0630-0a3f-47c0-bc52-c88bcec79392 dk0 at wd1: "bootroot", 2097152 blocks at 1024, type: ffs xotica# gpt biosboot -L bootroot wd1 xotica# newfs dk0 xotica# installboot /dev/rdk0 /usr/mdec/bootxx_ffsv1 xotica# mount /dev/dk0 /mnt xotica# cp /usr/mdec/boot /mnt
Note that biosboot is not needed for UEFI
systems.
SEE ALSO
boot(8), dkctl(8), fdisk(8), installboot(8), mount(8), newfs(8), swapctl(8)
HISTORY
The gpt utility appeared in
FreeBSD 5.0 for ia64. gpt
utility first appeared in NetBSD 5.0.
BUGS
The development of the gpt utility is
still work in progress. Many necessary features are missing or partially
implemented. In practice this means that the manual page, supposed to
describe these features, is farther removed from being complete or useful.
As such, missing functionality is not even documented as missing. However,
it is believed that the currently present functionality is reliable and
stable enough that this tool can be used without bullet-proof footware if
one thinks one does not make mistakes.
It is expected that the basic usage model does not change, but it is possible that future versions will not be compatible in the strictest sense of the word. Also, options primarily intended for diagnostic or debug purposes may be removed in future versions.
Another possibility is that the current usage model is accompanied by other interfaces to make the tool usable as a back-end. This all depends on demand and thus feedback.