创建分区表和分区

The first step to partitioning a disk is making a partition table. After that, the actual partitions are created according to the desired partition scheme.

Before beginning, you may wish to backup[broken link: invalid section] your current partition table and scheme.

The following shows how to use gdisk to perform both the creation of a partition table and the creation of the actual partitions. Alternatively, you may use the curses-based version called cgdisk; however, the following instructions do not apply to it. See cgdisk(8) for its usage.

performs partition alignment automatically on a 2048 512-byte sector (1 MiB) block size base which should be compatible with all Advanced Format HDDs and the vast majority of SSDs if not all.

分区编号

A partition number is the number assigned to a partition, e.g. a partition with number 1 on a disk /dev/sda would be /dev/sda1. Partition numbers may not always match the order of partitions on disk, in which case they can be sorted.

It is advised to choose the default number suggested by gdisk.

First and last sector

The first and last sectors of the partition can be specified in sector numbers or as positions measured in kibibytes (K), mebibytes (M), gibibytes (G), tebibytes (T), or pebibytes (P);

The position can be specified in:

absolute terms from the star of the disk. E.g. 40M as a first sector specifies a position 40 MiB from the start of the disk.

relative terms by preceding the size with +size or -size. E.g. +2G to specify a point 2 GiB after the default start sector, or -200M to specify a point 200 MiB before the last available sector.

Pressing the Enter key with no input specifies the default value, which is the start of the largest available block for the first sector and the end of the same block for the last sector.

Tip: When partitioning it is always a good idea to specify partition sizes using relative terms with the +size{M,G,T,P} notation and not use sizes smaller than 1 MiB. Such partitions will always be aligned according to the device properties.

Partition type

Select the partition's type by entering gdisk's internal type code or specifying the manually. The default, Linux filesystem (GUID 0FC63DAF-8483-4772-8E79-3D69D8477DE4, gdisk's internal code 8300), should be fine for most use cases.

Sort partitions

This applies for when a new partition is created in the space between two partitions or a partition is deleted. /dev/sda is used in this example.

# sgdisk -s /dev/sda

After sorting the partitions if you are not using Persistent block device naming, it might be required to adjust the /etc/fstab and/or the /etc/crypttab configuration files.

Note: The kernel must read the new partition table for the partitions (e.g. /dev/sda1) to be usable. Reboot the system or tell the kernel to reread the partition table.

Recover GPT header

In case main GPT header or backup GPT header gets damaged, you can recover one from the other with gdisk. /dev/sda is used in this example.

# gdisk /dev/sda

choose r for recovery and transformation options (experts only). From there choose either

b: use backup GPT header (rebuilding main)

d: use main GPT header (rebuilding backup)

When done write the table to disk and exit via the w command.

Expand a GPT disk

After enlarging a disk (e.g. in hardware RAID or a virtual machine disk) the newly added free space will not be immediately usable since GPT keeps data at the end of the disk. You must relocate the backup GPT header to the new end of the disk.

Prevent GPT partition automounting

The automounting can be disabled by setting the partition attribute63 "do not automount" on the partition.

Start gdisk, e.g.:

# gdisk /dev/sda

Press p to print the partition table and take note of the partition number(s) of the for which you want to disable automounting.

Press xextra functionality (experts only).

Press aset attributes. Input the partition number and set the attribute 63. Under Set fields are: it should now show 63 (do not automount). Press Enter to end attribute changing. Repeat this for all partitions you want to prevent from automounting.

When done write the table to disk and exit via the w command.

Alternatively using sgdisk, the attribute can be set using the -A/--attributes= option; see sgdisk(8) for usage. For example, to set partition attribute 63 "do not automount" on /dev/sda2 run: