KB
Storage & Filesystems

Creating Partition in GPT

4 min read862 words15 code blocks

At a glance#

  • Purpose: Initialise a new disk with a GPT partition table and create a single full-disk partition.
  • Applies to: Any Linux distribution with parted installed.
  • Risk: High — writing a new partition table destroys any existing data on the target disk.
  • Time: About 15 minutes.

Overview#

GPT (GUID Partition Table) is the modern replacement for the older MBR scheme. Use it for any new disk:

MBRGPT
Maximum disk size2 TB8 ZB (effectively unlimited)
Primary partitions4128
RedundancySingle tableBackup table at end of disk
FirmwareBIOSUEFI (and BIOS with a boot partition)

This article covers preparing a fresh data disk: label it GPT, create one partition spanning the whole disk, then hand it to LVM or format it directly.

Warning: mklabel gpt writes a new, empty partition table. Every existing partition on that disk becomes unreachable immediately. There is no confirmation prompt beyond parted's own warning, and no undo. Confirm the device path twice before running it.

Before you start#

  • Root access.
  • The new disk attached and visible to the OS.
  • Certainty about which device is the new one.

Identify the target disk#

bash
lsblk

The new disk is the one with no partitions and no mount points:

text
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   50G  0 disk
├─sda1   8:1    0    1G  0 part /boot
└─sda2   8:2    0   49G  0 part /
sdb      8:16   0  100G  0 disk          <-- new, unpartitioned

Cross-check before proceeding:

bash
sudo fdisk -l /dev/sdb
sudo blkid /dev/sdb

If blkid returns nothing, the disk holds no recognised filesystem — a good sign it is genuinely blank. If it returns a filesystem or partition signature, stop and confirm the disk is safe to erase.

Note: If the disk was only just attached and does not appear, rescan the SCSI bus: ``bash echo "- - -" | sudo tee /sys/class/scsi_host/host0/scan ``

Procedure#

1. Open the disk in parted#

bash
sudo parted /dev/sdb

The prompt changes to (parted). Everything until quit happens inside this shell.

2. Create the GPT label#

text
(parted) mklabel gpt

parted warns that existing data will be lost. Confirm only if you are certain of the device.

3. Create a partition spanning the whole disk#

text
(parted) mkpart primary 0% 100%

Using 0% and 100% rather than explicit sector numbers lets parted align the partition correctly to the underlying storage. Misaligned partitions carry a measurable performance penalty on SSDs and SAN LUNs.

4. Optionally flag it for LVM#

If this disk will become an LVM physical volume, set the flag so its purpose is obvious to anyone reading the table later:

text
(parted) set 1 lvm on

5. Review and exit#

text
(parted) print
(parted) quit

print should show a gpt partition table with one partition covering the full disk.

6. Refresh the kernel's view of the partition table#

bash
sudo partprobe /dev/sdb
lsblk

/dev/sdb1 should now be listed.

Next steps#

The new partition is empty. Choose one of the following.

Gives you the ability to resize later without repartitioning:

bash
sudo pvcreate /dev/sdb1
sudo vgcreate vgdata /dev/sdb1
sudo lvcreate -n lvdata -l 100%FREE vgdata
sudo mkfs.xfs /dev/vgdata/lvdata

Full detail is in Creating new LVM Partition Linux.

Option B — Format the partition directly#

Simpler, but far harder to grow later:

bash
sudo mkfs.xfs /dev/sdb1        # or mkfs.ext4
FilesystemChoose when
xfsGeneral purpose, large files, heavy writes. Can grow but cannot shrink.
ext4You may need to shrink the filesystem later.

Mount it and make it persistent#

bash
sudo mkdir -p /data
sudo blkid /dev/sdb1

Copy the UUID from the output, then add it to /etc/fstab:

text
UUID=xxxx-xxxx-xxxx  /data  xfs  defaults  0  2
Warning: Always use the UUID, never /dev/sdb1. Device names can change order between reboots, and an fstab entry pointing at the wrong disk will fail the boot.

Test the entry before rebooting:

bash
sudo mount -a
df -hT /data

If mount -a returns no errors, the entry is valid.

Verification#

bash
sudo parted /dev/sdb print
lsblk -f
df -hT /data

Confirm the partition table reads gpt, the filesystem is present, and the mount point shows the expected capacity. Then reboot and confirm it comes back automatically.

Troubleshooting#

SymptomCause and fix
Error: Partition(s) on /dev/sdb are being usedThe disk is mounted or in use by LVM. Unmount it and check with lsof /dev/sdb.
/dev/sdb1 not appearing after mkpartKernel has not reread the table. Run sudo partprobe /dev/sdb, or reboot if it is still missing.
unrecognised disk label from printmklabel was not run, or was run on a different device.
Alignment warning from partedPercentage boundaries were not used. Recreate with 0% / 100%.
System fails to boot after editing fstabA bad entry. Boot to rescue, comment out the line, and test with mount -a before rebooting.