Skip to content
Search

DiskPartitioning:Example:UEFI with GPT

lastmod 2020-07-14created 2020-07-049 edits

How to partition for UEFI with GPT using fdisk.

Layout overview

Mount point

Partition

Partition type

Suggested size

/mnt/boot or /mnt/efi

/dev/sdX1

EFI system partition

260–512 MiB

/mnt

/dev/sdX2

Linux x86-64 root (/)

Remainder of the device

[SWAP]

/dev/sdX3

Linux swap

More than 512 MiB

Step by Step

Proceed as follows using fdisk.

Check partitions

$ sudo fdisk -l

Run

$ sudo fdisk /dev/sda
Command (m for help): m

Help:

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table
Command (m for help): p

Disk /dev/sda: 233.8 GiB, 251000193024 bytes, 490234752 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 26186DBA-706B-4B55-8F8D-A04D98C4762A

Device       Start       End   Sectors   Size Type
/dev/sda1     2048   1050623   1048576   512M EFI System
/dev/sda2  1050624 490233855 489183232 233.3G Linux filesystem

Delete partitions

Repeat to delete all existing partitions:

Command (m for help): d
Partition number (1,2, default 2): 2

Partition 2 has been deleted.

Command (m for help): d
Selected partition 1
Partition 1 has been deleted.

Command (m for help): p
Disk /dev/sda: 233.8 GiB, 251000193024 bytes, 490234752 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 26186DBA-706B-4B55-8F8D-A04D98C4762A

Create an empty GPT partition

Command (m for help): g
Created a new GPT disklabel (GUID: 8C8A1B68-71C1-AE46-9161-8884F72BE345).

Command (m for help): p
Disk /dev/sda: 233.8 GiB, 251000193024 bytes, 490234752 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 8C8A1B68-71C1-AE46-9161-8884F72BE345

Create the first partition

Command (m for help): n
Partition number (1-128, default 1): 1
First sector (2048-490234718, default 2048): 2048
Last sector, +sectors or +size{K,M,G,T,P} (2048-490234718, default 490234718): +512M

Created a new partition 1 of type 'Linux filesystem' and of size 512 MiB.
Partition #1 contains a vfat signature.

Do you want to remove the signature? [Y]es/[N]o: Y

The signature will be removed by a write command.

Command (m for help): p
Disk /dev/sda: 233.8 GiB, 251000193024 bytes, 490234752 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 8C8A1B68-71C1-AE46-9161-8884F72BE345

Device     Start     End Sectors  Size Type
/dev/sda1   2048 1050623 1048576  512M Linux filesystem

Filesystem/RAID signature on partition 1 will be wiped.

Command (m for help): t
Selected partition 1
Partition type (type L to list all types): L
  1 EFI System                     C12A7328-F81F-11D2-BA4B-00A0C93EC93B
  2 MBR partition scheme           024DEE41-33E7-11D3-9D69-0008C781F39F
  3 Intel Fast Flash               D3BFE2DE-3DAF-11DF-BA40-E3A556D89593
  4 BIOS boot                      21686148-6449-6E6F-744E-656564454649
  5 Sony boot partition            F4019732-066E-4E12-8273-346C5641494F
  6 Lenovo boot partition          BFBFAFE7-A34F-448A-9A5B-6213EB736C22
  7 PowerPC PReP boot              9E1A2D38-C612-4316-AA26-8B49521E5A8B
  8 ONIE boot                      7412F7D5-A156-4B13-81DC-867174929325
  9 ONIE config                    D4E6E2CD-4469-46F3-B5CB-1BFF57AFC149
 10 Microsoft reserved             E3C9E316-0B5C-4DB8-817D-F92DF00215AE
 11 Microsoft basic data           EBD0A0A2-B9E5-4433-87C0-68B6B72699C7
 12 Microsoft LDM metadata         5808C8AA-7E8F-42E0-85D2-E1E90434CFB3
 13 Microsoft LDM data             AF9B60A0-1431-4F62-BC68-3311714A69AD
 14 Windows recovery environment   DE94BBA4-06D1-4D40-A16A-BFD50179D6AC
 15 IBM General Parallel Fs        37AFFC90-EF7D-4E96-91C3-2D7AE055B174
 16 Microsoft Storage Spaces       E75CAF8F-F680-4CEE-AFA3-B001E56EFC2D
 17 HP-UX data                     75894C1E-3AEB-11D3-B7C1-7B03A0000000
 18 HP-UX service                  E2A1E728-32E3-11D6-A682-7B03A0000000
 19 Linux swap                     0657FD6D-A4AB-43C4-84E5-0933C84B4F4F
 20 Linux filesystem               0FC63DAF-8483-4772-8E79-3D69D8477DE4
 21 Linux server data              3B8F8425-20E0-4F3B-907F-1A25A76F98E8
 22 Linux root (x86)               44479540-F297-41B2-9AF7-D131D5F0458A
 23 Linux root (ARM)               69DAD710-2CE4-4E3C-B16C-21A1D49ABED3
 24 Linux root (x86-64)            4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709
 25 Linux root (ARM-64)            B921B045-1DF0-41C3-AF44-4C6F280D3FAE
 26 Linux root  (IA-64)             993D8D3D-F80E-4225-855A-9DAF8ED7EA97
 27 Linux reserved                 8DA63339-0007-60C0-C436-083AC8230908
 28 Linux home                     933AC7E1-2EB4-4F13-B844-0E14E2AEF915
 29 Linux RAID                     A19D880F-05FC-4D3B-A006-743F0F84911E
 30 Linux extended boot            BC13C2FF-59E6-4262-A352-B275FD6F7172
 31 Linux LVM                      E6D6D379-F507-44C2-A23C-238F2A3DF928
...

Partition type (type L to list all types): 1
Changed type of partition 'Linux filesystem' to 'EFI System'.

Command (m for help): p
Disk /dev/sda: 233.8 GiB, 251000193024 bytes, 490234752 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 8C8A1B68-71C1-AE46-9161-8884F72BE345

Device     Start     End Sectors  Size Type
/dev/sda1   2048 1050623 1048576  512M EFI System

Filesystem/RAID signature on partition 1 will be wiped.

Create the second partition

When calculating the last sector of the second partition, if the prompt looks like this

Last sector, +-sectors or +-size{K,M,G,T,P} (1050624-490234718, default 490234718):

entering -512M sets up the partition leaving at least the last 512MByte. (Sectors are aligned automatically.)

If the - option cannot be entered

If the - option cannot be entered, the prompt looks like this.

Last sector, +sectors or +size{K,M,G,T,P} (1050624-490234718, default 490234718):

You have to calculate the last sector position yourself. One sector is calculated as the size of a Logical Sector. The formula is as follows.

{마지막 섹터 위치} - {원하는 남은 공간 (섹터 크기)}

Here we want to reserve 512MByte, and one sector is 512Byte, so

(512*1024*1024) / 512 = 1048576

{원하는 남은 공간 (섹터 크기)} is 1048576.

The last sector position of the disk is 490234718. Therefore

490234718 - 1048576 = 489186142

489186142 should be the last sector position.

However, for performance optimization, partition alignment must be considered. The start sector position of the swap partition must be aligned. If 1MByte is chosen as the alignment size, it must be a multiple of 2048Sector (1MByte/512Byte).

The start sector of the third partition, which will become the swap partition, is the last sector of the second partition +1.

(489186142+1) % 2048 = 863

Since the swap partition must be larger than 512MByte, subtract 863Sector.

(489186142+1) - 863 = 489185280

This gives the following result.

  • Last sector of the second partition: 489185280 - 1 = 489185279
  • Start sector of the third partition: 489185280
  • Last sector of the third partition: 490234718
  • Size of the third partition: 512MByte + 863Sector = (51210241024)Byte + (863*512)Byte = 536870912Byte + 441856Byte = 537312768
Command (m for help): n
Partition number (2-128, default 2): 2
First sector (1050624-490234718, default 1050624): 1050624
Last sector, +sectors or +size{K,M,G,T,P} (1050624-490234718, default 490234718): 489185279

Created a new partition 2 of type 'Linux filesystem' and of size 232.8 GiB.
Partition #2 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: Y

The signature will be removed by a write command.

Command (m for help): t
Partition number (1,2, default 2): 2
Partition type (type L to list all types): 24

Changed type of partition 'Linux filesystem' to 'Linux root (x86-64)'.

Command (m for help): p
Disk /dev/sda: 233.8 GiB, 251000193024 bytes, 490234752 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 8C8A1B68-71C1-AE46-9161-8884F72BE345

Device       Start       End   Sectors   Size Type
/dev/sda1     2048   1050623   1048576   512M EFI System
/dev/sda2  1050624 489185279 488134656 232.8G Linux root (x86-64)

Filesystem/RAID signature on partition 1 will be wiped.
Filesystem/RAID signature on partition 2 will be wiped.

Create the third partition

Command (m for help): n
Partition number (3-128, default 3): 
First sector (489185280-490234718, default 489185280): 489185280
Last sector, +sectors or +size{K,M,G,T,P} (489185280-490234718, default 490234718): 490234718

Created a new partition 3 of type 'Linux filesystem' and of size 512.4 MiB.

Command (m for help): t
Partition number (1-3, default 3): 3
Partition type (type L to list all types): 19

Changed type of partition 'Linux filesystem' to 'Linux swap'.

Command (m for help): p
Disk /dev/sda: 233.8 GiB, 251000193024 bytes, 490234752 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 8C8A1B68-71C1-AE46-9161-8884F72BE345

Device         Start       End   Sectors   Size Type
/dev/sda1       2048   1050623   1048576   512M EFI System
/dev/sda2    1050624 489185279 488134656 232.8G Linux root (x86-64)
/dev/sda3  489185280 490234718   1049439 512.4M Linux swap

Filesystem/RAID signature on partition 1 will be wiped.
Filesystem/RAID signature on partition 2 will be wiped.

Save the changed partition settings

Command (m for help): w

See also

author Zer0 sitemap