LFCS 76 🐧 Partitioning with parted
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
| Command | Purpose | Destructive? |
|---|---|---|
print | Show table and partitions | No |
mklabel TYPE | Create new table (gpt or msdos) | Yes, erases table |
mkpart NAME FS START END | Create a partition | Writes to disk |
rm NUMBER | Delete partition by number | Yes |
set NUMBER FLAG on/off | Toggle partition flag | Writes to disk |
name NUMBER NAME | Set GPT partition name | GPT only |
unit UNIT | Change display/input unit | No |
resizepart NUMBER END | Change partition end | Yes |
Table Type Decision
| Condition | Table |
|---|---|
| Disk > 2 TB | GPT |
| UEFI boot disk | GPT |
| Legacy BIOS, disk ≤ 2 TB | MBR (msdos) |
| More than 4 primary partitions needed | GPT |
Flags by Table Type
| Flag | MBR Meaning | GPT Meaning |
|---|---|---|
boot | Active partition | Legacy BIOS bootable |
esp | Not applicable | EFI System Partition |
lvm | LVM physical volume | LVM physical volume |
raid | RAID member | RAID member |
Post-Partitioning Steps
| Step | Command | Purpose |
|---|---|---|
| Re-read kernel table | partprobe /dev/sdX | Creates device nodes |
| Verify layout | parted /dev/sdX print | Confirm partitions |
| Verify nodes | lsblk /dev/sdX | Confirm kernel sees them |
| Format filesystem | mkfs.ext4 /dev/sdX1 | Separate 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
| Pitfall | Why It Happens | Fix |
|---|---|---|
Partition not found after mkpart | Kernel table not re-read | Run partprobe /dev/sdX |
| UEFI system does not boot | ESP lacks esp flag | parted set N esp on |
| Disk shows only 2 TB | MBR table | Reformat with mklabel gpt |
mkfs says “no such device” | Partition node not created | partprobe then retry |
| Wrong disk erased | No print before mklabel | Always inspect first |
| Partition name missing on MBR | MBR has no name field | Use GPT or ignore |
parted refuses to create partition | Overlapping ranges or no free space | print 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
| Item | Value |
|---|---|
| Primary use | Create and modify MBR/GPT partition tables |
| Commit model | Immediate; no w to save |
| Table selection | mklabel gpt or mklabel msdos |
| Max MBR disk | 2 TB |
| Max GPT partitions | 128 default |
| First partition start | 1MiB (leaves room for GPT metadata) |
| Boot flag | set N boot on (legacy BIOS) |
| ESP flag | set N esp on (UEFI) |
| Kernel re-read | partprobe /dev/sdX |
| Scripting | parted -s /dev/sdX command... |
Key takeaways:
partedcommits immediately. There is no staged write and no undo. Verify withprintbefore any destructive command.mklabelerases 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 .
mkpartdoes not format. It records a filesystem hint in the table.mkfsandmkswapare 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. partprobecloses the gap. Without it, the kernel does not know about the new partitions, andmkfsfails.- Start the first partition at
1MiB. Starting at 0 collides with GPT metadata and breaks alignment. -sis 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 beforemkpart. - Formatting, mounting, and
/etc/fstabare separate topics.partedproduces 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.
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!