| |

LFCS 76 🐧 Partitioning with parted

⏱️ Estimated read: 14 min | |

parted is the partition editor that LFCS candidates reach for when a disk exceeds the limits of MBR or when a script needs to create a layout without interactive prompts. Unlike fdisk, which stages changes until a final w commit, parted applies each command immediately, and that immediacy is both its convenience and its hazard. A mistyped rm is not undone by quitting without saving; it is done the moment the command executes.

This chapter covers parted as an LFCS storage-management tool: the partition-table decision that must precede any layout work, the commands that create and inspect partitions, and the flags that make a partition bootable or assign it a specific role. It then addresses the scripting model that distinguishes parted from its interactive counterparts, the kernel re-read step that many candidates forget, and the safety discipline required when a single command can destroy a disk’s layout.


Key point: parted writes immediately. There is no staged commit and no “quit without saving.” Every mkpart, rm, and mklabel takes effect the moment the command runs, and mklabel alone erases the entire existing table.


Why parted exists

The MBR ceiling. The traditional MS-DOS partition table, created by fdisk and written as msdos in parted, supports a maximum disk size of 2 TB and four primary partitions . On a disk larger than 2 TB, the space beyond the first 2 TB is simply unusable under MBR. parted supports GPT, which has no practical disk-size limit and defaults to 128 primary partitions . For any modern disk of substantial size, the table type decision precedes every other partitioning choice.

The immediate-commit model. fdisk and gdisk collect changes in memory and write them only when the user issues w. This is forgiving: a mistake can be abandoned by quitting without writing. parted has no such safety net. Each command is executed against the disk as it is entered, and the manual for parted warns explicitly that accidental deletion requires recovery tools rather than an undo . That model is deliberate: it makes parted suitable for one-line scripts like parted /dev/sdb mklabel gpt mkpart ..., where waiting for interactive confirmation would defeat the purpose .

The GPT and MBR dual support. Some tools are GPT-only (gdisk) or MBR-centric (fdisk in older versions). parted handles both table formats through a single interface, which makes it the practical choice when a candidate must work on either a legacy BIOS system with MBR or a UEFI system with GPT . The mklabel command selects the table type, and everything after that follows the rules of the chosen table.

The scripting requirement. LFCS storage tasks often take the form of “create a partition of size X with label Y.” parted accepts the entire operation as a sequence of arguments on one command line, with -s suppressing interactive prompts . This is the form that appears in automation, and it is the form that candidates should practice.

The safety cost. Because parted acts immediately and because mklabel destroys the existing table, the tool demands a verification step that interactive editors do not. The print command, or parted -l before any modification, is not optional courtesy; it is the step that confirms the target device and the existing layout before an irreversible command runs . Every parted session should begin with inspection and end with a kernel re-read.


a. Choosing the table type and creating a label

The first command on any blank or repurposed disk is mklabel, which creates a new partition table and discards whatever was there. The type argument is gpt for modern disks and msdos for MBR compatibility. The choice is constrained by the disk size and the boot firmware: a disk larger than 2 TB requires GPT, and a UEFI boot disk requires GPT because legacy BIOS firmware cannot read an MBR layout on a UEFI system .

# Inspect the disk before touching it.
# This confirms the device name, size, and any existing table.
sudo parted /dev/sdb print

# Create a GPT label. This ERASES the existing partition table.
# Only run this after confirming the device with `print`.
sudo parted /dev/sdb mklabel gpt

# For a legacy BIOS system on a small disk, MBR is the alternative.
# sudo parted /dev/sdb mklabel msdos

The mklabel command does not create partitions; it creates the container that partitions live in. On a fresh GPT disk, parted writes a protective MBR in the first sector for legacy compatibility, but the actual layout is GPT . After mklabel, parted print shows an empty table with the full disk as free space.

A subtlety for LFCS: mklabel is destructive and has no confirmation prompt in scripted mode. If the device path is wrong, the wrong disk loses its table. The print inspection before mklabel is the only protection, and it is why the command sequence in practice always begins with a read-only operation.


b. Creating partitions with mkpart

mkpart creates a partition within the table. Its arguments are the partition name (GPT only), an optional filesystem type hint, and the start and end positions . The positions can be expressed in bytes, sectors, or percentages, and the unit command changes the default display and input unit. Percentages are useful for even splits; explicit sizes are necessary when the layout must match a specification.

# Create a boot partition of 512 MiB at the start of the disk.
# The name "boot" is stored in the GPT table (ignored on MBR).
sudo parted /dev/sdb mkpart boot fat32 1MiB 513MiB

# Create a root partition spanning the rest of the disk.
sudo parted /dev/sdb mkpart root ext4 513MiB 100%

# Create a swap partition of 4 GiB in the middle.
sudo parted /dev/sdb mkpart swap linux-swap 513MiB 4609MiB

The filesystem type in mkpart is a hint, not a formatting operation. parted records the expected filesystem in the partition table so that tools like lsblk and blkid can report it, but it does not run mkfs. The actual formatting is a separate step with mkfs.ext4, mkfs.xfs, or mkswap, and that separation matters for LFCS: a partition with type ext4 in the table is not yet an ext4 filesystem.

On a GPT disk, the partition name is arbitrary and useful for identification. On an MBR disk, the name argument is accepted but not stored in the same way, and MBR partitions are identified by number rather than name . The mkpart command does not require a name in interactive mode on MBR, but scripted invocations typically supply a placeholder to keep the argument positions consistent.

The start position of the first partition should not be 0. GPT stores its header and partition array at the beginning of the disk, and starting at 1 MiB leaves room for that metadata and for alignment. Many parted examples use 1MiB as the first start position for this reason .


c. Flags, names, and post-creation configuration

A partition created with mkpart has a position and a size, but it may need a flag before firmware or the kernel will treat it correctly. The set command toggles flags such as boot, esp, raid, and lvm . The boot flag on a GPT disk marks the partition as bootable for legacy compatibility, while the esp flag marks an EFI System Partition for UEFI firmware.

# Mark the first partition as bootable.
# On GPT, `boot` sets the legacy BIOS bootable attribute.
sudo parted /dev/sdb set 1 boot on

# For a UEFI system, the ESP partition needs the esp flag.
# sudo parted /dev/sdb set 1 esp on

# Rename a GPT partition for clarity. Names are not available on MBR.
sudo parted /dev/sdb name 2 rootfs

The set command is where table-type differences surface. On MBR, set 1 boot on sets the active partition flag, which legacy BIOS uses to find the bootloader. On GPT, the boot flag is a legacy BIOS bootable attribute, and the esp flag is the UEFI equivalent. A candidate who marks a UEFI ESP with only boot and not esp may find that firmware does not recognize it.

After any partition-table modification, the kernel’s in-memory view of the disk is stale. partprobe /dev/sdb re-reads the table and informs the kernel of the new layout without a reboot . Without this step, mkfs on a newly created partition may fail with “no such device” because /dev/sdb1 does not yet exist in the kernel’s device list. partprobe is not part of parted itself; it is the companion command that makes parted‘s immediate writes visible to the running system.


Complete Example Session

# ============================================
# PART 1: INSPECTION BEFORE MODIFICATION
# ============================================
# Never run mklabel without confirming the device.
# `print` is read-only and shows existing partitions.

sudo parted /dev/sdb print
# Output: disk size, table type, existing partitions, free space.

# List all attached block devices and their partition tables.
sudo parted -l

# ============================================
# PART 2: CREATING THE TABLE
# ============================================
# GPT for a modern disk. This destroys the existing table.

sudo parted /dev/sdb mklabel gpt

# Verify the empty table.
sudo parted /dev/sdb print

# ============================================
# PART 3: THE BOOT PARTITION
# ============================================
# 512 MiB FAT32 partition at the start, named "boot".
# The 1MiB start leaves room for GPT metadata and alignment.

sudo parted /dev/sdb mkpart boot fat32 1MiB 513MiB

# ============================================
# PART 4: THE ROOT PARTITION
# ============================================
# Remaining space, ext4 hint, named "root".

sudo parted /dev/sdb mkpart root ext4 513MiB 100%

# ============================================
# PART 5: THE SWAP PARTITION
# ============================================
# A separate swap partition. The hint is linux-swap.
# In practice, size this before root and adjust root's start.

sudo parted /dev/sdb mkpart swap linux-swap 513MiB 4609MiB
sudo parted /dev/sdb mkpart root ext4 4609MiB 100%

# ============================================
# PART 6: THE BOOT FLAG
# ============================================
# Legacy BIOS bootable attribute on partition 1.

sudo parted /dev/sdb set 1 boot on

# ============================================
# PART 7: THE UEFI ALTERNATIVE
# ============================================
# On a UEFI system, the ESP flag is required instead of boot.
# Do not apply both flags to the same partition by accident.

# sudo parted /dev/sdb set 1 esp on

# ============================================
# PART 8: THE NAME (GPT ONLY)
# ============================================
# GPT partitions carry a human-readable name.
# MBR partitions do not; this command would have no effect.

sudo parted /dev/sdb name 2 rootfs

# ============================================
# PART 9: KERNEL RE-READ
# ============================================
# Inform the kernel of the new partitions before formatting.

sudo partprobe /dev/sdb

# ============================================
# PART 10: VERIFICATION
# ============================================
# Confirm the layout and the device nodes.

sudo parted /dev/sdb print
lsblk /dev/sdb

# The partitions now exist as /dev/sdb1, /dev/sdb2, /dev/sdb3.
# Formatting is a separate step: mkfs.ext4, mkfs.fat, mkswap.

The ten parts walk through a complete GPT layout: inspect, label, create boot and root (and optionally swap), set the boot flag, name a partition, re-read the kernel table, and verify. The sequence is the same for MBR except for the mklabel msdos choice and the absence of GPT names; the flag semantics also differ. The critical discipline is that parted is the layout tool only: formatting and mounting are separate operations, and partprobe bridges the gap between the on-disk table and the running kernel.


Quick Reference

Core parted Commands

CommandPurposeDestructive?
printShow table and partitionsNo
mklabel TYPECreate new table (gpt or msdos)Yes, erases table
mkpart NAME FS START ENDCreate a partitionWrites to disk
rm NUMBERDelete partition by numberYes
set NUMBER FLAG on/offToggle partition flagWrites to disk
name NUMBER NAMESet GPT partition nameGPT only
unit UNITChange display/input unitNo
resizepart NUMBER ENDChange partition endYes

Table Type Decision

ConditionTable
Disk > 2 TBGPT
UEFI boot diskGPT
Legacy BIOS, disk ≤ 2 TBMBR (msdos)
More than 4 primary partitions neededGPT

Flags by Table Type

FlagMBR MeaningGPT Meaning
bootActive partitionLegacy BIOS bootable
espNot applicableEFI System Partition
lvmLVM physical volumeLVM physical volume
raidRAID memberRAID member

Post-Partitioning Steps

StepCommandPurpose
Re-read kernel tablepartprobe /dev/sdXCreates device nodes
Verify layoutparted /dev/sdX printConfirm partitions
Verify nodeslsblk /dev/sdXConfirm kernel sees them
Format filesystemmkfs.ext4 /dev/sdX1Separate from parted

Best Practices

✅ Do This:

# Inspect before modifying.
sudo parted /dev/sdb print                                           # ✅

# Use GPT for disks larger than 2 TB.
sudo parted /dev/sdb mklabel gpt                                     # ✅

# Start the first partition at 1MiB, not 0.
sudo parted /dev/sdb mkpart boot fat32 1MiB 513MiB                  # ✅

# Set the correct flag for the firmware.
sudo parted /dev/sdb set 1 esp on   # UEFI                           # ✅

# Re-read the table after modifications.
sudo partprobe /dev/sdb                                              # ✅

# Use -s for scripted, non-interactive operation.
sudo parted -s /dev/sdb mklabel gpt mkpart root ext4 1MiB 100%      # ✅

❌ Don’t Do This:

# Don't run mklabel without checking the device.
sudo parted /dev/sda mklabel gpt   # wrong disk = data loss         # ❌

# Don't use MBR on a disk larger than 2 TB.
sudo parted /dev/sdb mklabel msdos                                   # ❌

# Don't expect parted to format the filesystem.
sudo parted /dev/sdb mkpart root ext4 1MiB 100%  # no mkfs yet      # ❌

# Don't skip partprobe after creating partitions.
# mkfs may fail because /dev/sdb1 does not exist yet.                # ❌

# Don't use the boot flag for a UEFI ESP.
sudo parted /dev/sdb set 1 boot on   # UEFI needs esp, not boot      # ❌

# Don't assume changes are staged like fdisk.
sudo parted /dev/sdb rm 1   # this is immediate, not pending         # ❌

Common Pitfalls

PitfallWhy It HappensFix
Partition not found after mkpartKernel table not re-readRun partprobe /dev/sdX
UEFI system does not bootESP lacks esp flagparted set N esp on
Disk shows only 2 TBMBR tableReformat with mklabel gpt
mkfs says “no such device”Partition node not createdpartprobe then retry
Wrong disk erasedNo print before mklabelAlways inspect first
Partition name missing on MBRMBR has no name fieldUse GPT or ignore
parted refuses to create partitionOverlapping ranges or no free spaceprint free to see gaps

Real-World Examples

1. Inspect All Disks

sudo parted -l

2. Create GPT Label

sudo parted /dev/sdb mklabel gpt

3. Create a Single Full-Disk Partition

sudo parted /dev/sdb mkpart primary ext4 1MiB 100%

4. Set Boot Flag (Legacy)

sudo parted /dev/sdb set 1 boot on

5. Set ESP Flag (UEFI)

sudo parted /dev/sdb set 1 esp on

6. Name a GPT Partition

sudo parted /dev/sdb name 2 rootfs

7. Remove a Partition

sudo parted /dev/sdb rm 2

8. Scripted One-Line Layout

sudo parted -s /dev/sdb mklabel gpt mkpart boot fat32 1MiB 513MiB

9. Re-read the Kernel Table

sudo partprobe /dev/sdb

10. Print Free Space

sudo parted /dev/sdb print free

Visual

The Immediate-Commit Model

┌─────────────────────────────────────────────────────────┐
│  fdisk / gdisk                    parted                │
│                                                         │
│  Command → staged                 Command → written     │
│  Command → staged                 Command → written     │
│  w → all written                  (no w needed)         │
│                                                         │
│  Quit without w = no change       Quit = changes remain │
│                                                         │
│  Forgiving for exploration        Requiring inspection  │
│  Slower for scripting             Suitable for -s       │
└─────────────────────────────────────────────────────────┘

Table Type Decision

┌─────────────────────────────────────────────────────────┐
│  Disk size > 2 TB?                                      │
│         │                                               │
│    YES  │  NO                                           │
│         ▼   ▼                                           │
│  ┌──────────┐    Is the boot disk UEFI?                 │
│  │   GPT    │           │                               │
│  └──────────┘      YES  │  NO                           │
│                    ▼    ▼                               │
│              ┌──────────┐  ┌──────────┐                 │
│              │   GPT    │  │ MBR ok   │                 │
│              └──────────┘  └──────────┘                 │
│                                                         │
│  MBR on > 2 TB wastes space beyond 2 TB.                │
│  UEFI cannot boot from MBR.                             │
└─────────────────────────────────────────────────────────┘

The partprobe Gap

┌─────────────────────────────────────────────────────────┐
│  parted writes to disk                                  │
│         │                                               │
│         ▼                                               │
│  ┌───────────────────────────────────────────────────┐  │
│  │  ON-DISK TABLE: /dev/sdb1, /dev/sdb2               │  │
│  │  (written immediately by parted)                   │  │
│  └───────────────────────────────────────────────────┘  │
│                                                         │
│  ┌───────────────────────────────────────────────────┐  │
│  │  KERNEL VIEW: still the old table                  │  │
│  │  /dev/sdb1 does not exist yet                      │  │
│  └───────────────────────────────────────────────────┘  │
│         │                                               │
│         ▼  partprobe /dev/sdb                           │
│  ┌───────────────────────────────────────────────────┐  │
│  │  KERNEL VIEW: updated                              │  │
│  │  /dev/sdb1, /dev/sdb2 now exist                    │  │
│  └───────────────────────────────────────────────────┘  │
│         │                                               │
│         ▼                                               │
│  mkfs.ext4 /dev/sdb1 now succeeds                       │
└─────────────────────────────────────────────────────────┘

Flag Semantics by Table

┌─────────────────────────────────────────────────────────┐
│  MBR: set 1 boot on                                     │
│         │                                               │
│         ▼                                               │
│  Active partition flag in the MBR.                      │
│  Legacy BIOS reads this to find the bootloader.         │
│                                                         │
│  GPT: set 1 boot on                                     │
│         │                                               │
│         ▼                                               │
│  Legacy BIOS bootable attribute.                        │
│  Not the same as the ESP flag.                          │
│                                                         │
│  GPT: set 1 esp on                                      │
│         │                                               │
│         ▼                                               │
│  EFI System Partition type.                             │
│  UEFI firmware looks for this.                          │
│  A UEFI boot partition needs `esp`, not `boot`.         │
└─────────────────────────────────────────────────────────┘

Summary

ItemValue
Primary useCreate and modify MBR/GPT partition tables
Commit modelImmediate; no w to save
Table selectionmklabel gpt or mklabel msdos
Max MBR disk2 TB
Max GPT partitions128 default
First partition start1MiB (leaves room for GPT metadata)
Boot flagset N boot on (legacy BIOS)
ESP flagset N esp on (UEFI)
Kernel re-readpartprobe /dev/sdX
Scriptingparted -s /dev/sdX command...

Key takeaways:

  • parted commits immediately. There is no staged write and no undo. Verify with print before any destructive command.
  • mklabel erases the table. It is the first command on a new disk and the most dangerous. Inspect the device first.
  • GPT is required for disks over 2 TB and for UEFI boot. MBR caps at 2 TB and cannot boot a UEFI system .
  • mkpart does not format. It records a filesystem hint in the table. mkfs and mkswap are separate steps.
  • The boot flag differs by table type. On MBR it is the active partition; on GPT it is a legacy BIOS attribute. UEFI needs esp.
  • partprobe closes the gap. Without it, the kernel does not know about the new partitions, and mkfs fails.
  • Start the first partition at 1MiB. Starting at 0 collides with GPT metadata and breaks alignment.
  • -s is for scripts. It suppresses prompts and makes the command sequence suitable for automation and LFCS one-liners.
  • Inspect with print free. It shows gaps and confirms available space before mkpart.
  • Formatting, mounting, and /etc/fstab are separate topics. parted produces the layout; the rest of the storage workflow consumes it.

Remember: parted is the LFCS tool for creating the partition layout that the rest of the storage stack depends on. Its immediate-commit model is faster for scripting and less forgiving for exploration. The safe sequence is always inspect, label, create, flag, re-read, verify. The table-type decision—GPT for large disks and UEFI, MBR for legacy small disks—must be made before mklabel because changing it later destroys the layout. And the filesystem hint in mkpart is not a format: mkfs remains a separate, mandatory step.


Was this helpful?


Stop using slow, ad-bloated tool sites! 🤮

🔎 Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
✅ Finance (Mortgage, Interest, Inflation)
✅ Tech (Base64, JSON, Dev Suite, IP)
✅ Health (BMI, BMR, TDEE)
✅ Productivity (Timer, Workspace, QR)

⚡️ Fast & Private
🔒 No data leaves your device
💎 100% Free

🔗 Use it now: https://tools.kandz.me
🔖 Bookmark it—you’ll need it later!