Creating Partition in GPT
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
partedinstalled. - 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:
| MBR | GPT | |
|---|---|---|
| Maximum disk size | 2 TB | 8 ZB (effectively unlimited) |
| Primary partitions | 4 | 128 |
| Redundancy | Single table | Backup table at end of disk |
| Firmware | BIOS | UEFI (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#
lsblkThe new disk is the one with no partitions and no mount points:
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, unpartitionedCross-check before proceeding:
sudo fdisk -l /dev/sdb
sudo blkid /dev/sdbIf 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#
sudo parted /dev/sdbThe prompt changes to (parted). Everything until quit happens inside this shell.
2. Create the GPT label#
(parted) mklabel gptparted warns that existing data will be lost. Confirm only if you are certain of the device.
3. Create a partition spanning the whole disk#
(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:
(parted) set 1 lvm on5. Review and exit#
(parted) print
(parted) quitprint should show a gpt partition table with one partition covering the full disk.
6. Refresh the kernel's view of the partition table#
sudo partprobe /dev/sdb
lsblk/dev/sdb1 should now be listed.
Next steps#
The new partition is empty. Choose one of the following.
Option A — Add it to LVM (recommended)#
Gives you the ability to resize later without repartitioning:
sudo pvcreate /dev/sdb1
sudo vgcreate vgdata /dev/sdb1
sudo lvcreate -n lvdata -l 100%FREE vgdata
sudo mkfs.xfs /dev/vgdata/lvdataFull detail is in Creating new LVM Partition Linux.
Option B — Format the partition directly#
Simpler, but far harder to grow later:
sudo mkfs.xfs /dev/sdb1 # or mkfs.ext4| Filesystem | Choose when |
|---|---|
xfs | General purpose, large files, heavy writes. Can grow but cannot shrink. |
ext4 | You may need to shrink the filesystem later. |
Mount it and make it persistent#
sudo mkdir -p /data
sudo blkid /dev/sdb1Copy the UUID from the output, then add it to /etc/fstab:
UUID=xxxx-xxxx-xxxx /data xfs defaults 0 2Warning: 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:
sudo mount -a
df -hT /dataIf mount -a returns no errors, the entry is valid.
Verification#
sudo parted /dev/sdb print
lsblk -f
df -hT /dataConfirm 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#
| Symptom | Cause and fix |
|---|---|
Error: Partition(s) on /dev/sdb are being used | The disk is mounted or in use by LVM. Unmount it and check with lsof /dev/sdb. |
/dev/sdb1 not appearing after mkpart | Kernel has not reread the table. Run sudo partprobe /dev/sdb, or reboot if it is still missing. |
unrecognised disk label from print | mklabel was not run, or was run on a different device. |
| Alignment warning from parted | Percentage boundaries were not used. Recreate with 0% / 100%. |
| System fails to boot after editing fstab | A bad entry. Boot to rescue, comment out the line, and test with mount -a before rebooting. |