Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Disk Partition Command: Tools and Usage Explained

· 5 min read · Home Tech

In this article
  1. Background: What Is Disk Partitioning?
  2. Common Disk Partition Commands by OS
  3. How Disk Partition Commands Work
  4. Choosing the Right Tool
  5. Common Problems and How to Avoid Them
  6. Safety and Best Practices
  7. Frequently Asked Questions

A disk partition command is a terminal or command-line instruction used to create, modify, delete, or manage disk partitions on a storage device. These commands interact with the partition table (such as MBR or GPT) to define how a disk is logically divided for use by an operating system.

Background: What Is Disk Partitioning?

Disk partitioning divides a physical storage drive into multiple logical sections, each functioning as an independent unit. This allows users to install multiple operating systems, separate data from the system, improve performance, or manage backups efficiently. Each partition can have its own file system (like NTFS, ext4, or APFS) and is assigned a drive letter or mount point.

Modern computers typically use one of two partitioning schemes:

  • MBR (Master Boot Record): Older standard, supports up to four primary partitions or three primary and one extended partition. Limited to 2 TB disk size.
  • GPT (GUID Partition Table): Modern standard, supports up to 128 partitions on Windows and more on Linux. Allows disks larger than 2 TB and includes redundancy for better data integrity.

Partitioning is essential during OS installation, system recovery, or when repurposing storage devices.

Common Disk Partition Commands by OS

Different operating systems provide built-in tools and commands for managing partitions. These are often command-line utilities that offer precise control over disk layout.

Windows: diskpart

The primary disk partition command in Windows is diskpart, a powerful command-line utility that replaces older tools like fdisk.

  1. Open Command Prompt as Administrator.
  2. Type diskpart and press Enter.
  3. Use commands like:
    • list disk – shows all connected disks
    • select disk 0 – selects the first disk
    • clean – removes all partitions
    • create partition primary size=10240 – creates a 10 GB primary partition
    • format fs=ntfs quick – formats with NTFS
    • assign letter=D – assigns drive letter D:

Caution: diskpart operations are irreversible without data recovery tools.

Linux: parted and fdisk

Linux offers several command-line tools:

  • fdisk: Best for MBR disks. Interactive tool for creating and deleting partitions.
  • parted: Supports both MBR and GPT. Can be used interactively or non-interactively.
  • gdisk: GPT equivalent of fdisk.

Example using parted:

  1. Run sudo parted /dev/sdb
  2. Type print to view current layout
  3. mklabel gpt – creates a new GPT table
  4. mkpart primary ext4 1MB 10GB – creates a partition
  5. quit – exits

After creating, format with mkfs.ext4 /dev/sdb1 and mount as needed.

macOS: diskutil

macOS uses diskutil, a command-line wrapper for disk management.

  • diskutil list – shows all disks and partitions
  • diskutil partitionDisk /dev/disk2 1 GPTFormat JHFS+ "Macintosh HD" 100% – erases and repartitions a disk with one volume
  • diskutil resizeVolume /dev/disk2s1 200G – resizes a partition

diskutil is safer than lower-level tools because it validates operations before execution.

How Disk Partition Commands Work

These commands interact directly with the disk's partition table, which resides in the first sector(s) of the drive. When you issue a command like create partition, the tool:

  1. Reads the current partition table.
  2. Calculates the start and end sectors for the new partition based on size and alignment rules.
  3. Updates the partition table in memory.
  4. Writes the modified table back to the disk.
  5. Notifies the OS kernel to rescan the disk for changes.

Modern tools align partitions to 1 MB boundaries to optimize performance on SSDs and advanced format drives. Misaligned partitions can cause slower read/write speeds.

Commands do not format or write data to the partition unless explicitly told (e.g., format or mkfs). They only define the logical boundaries.

Choosing the Right Tool

Selecting a partition command depends on your OS, disk type, and use case:

  • Windows users: Use diskpart for scripting or advanced control; otherwise, use Disk Management GUI.
  • Linux users: Prefer parted for GPT or large disks; use fdisk for simple MBR changes.
  • macOS users: diskutil is the standard; avoid direct use of gpt or dd unless experienced.
  • Cross-platform scripting: Consider using sgdisk (part of gptfdisk) for automated GPT operations.

Always verify the target disk before making changes. Accidentally selecting the wrong disk can result in permanent data loss.

Common Problems and How to Avoid Them

Using disk partition commands carries risk. Common issues include:

  • Data loss: Occurs when clean or mklabel is run on the wrong disk. Always double-check disk identifiers.
  • Boot failure: Deleting or modifying the system partition can prevent OS startup. Backup the partition table first.
  • Unallocated space not usable: After shrinking a partition, the free space may not be adjacent to an existing partition, making it hard to extend. Use tools like GParted to move partitions.
  • Partition not recognized: Some tools create partitions without assigning a drive letter or mount point. Use assign (Windows) or mount (Linux/macOS) to fix.

To reduce risk:

  • Backup critical data before partitioning.
  • Use list or print commands to confirm disk layout.
  • Test commands on virtual machines or spare drives.
  • Ensure sufficient power supply during operation (especially on laptops).

Safety and Best Practices

Safety is critical when running low-level disk commands:

  • Run tools with elevated privileges only when necessary.
  • Never run partition commands over remote sessions unless you have out-of-band access (e.g., IPMI).
  • Use read-only commands (list disk, print) to inspect before acting.
  • For system disks, schedule changes during maintenance windows.
  • Keep a record of original partition sizes and layouts.

Some tools support undo (like GParted Live), but most command-line utilities do not. Once written, changes are permanent.

Frequently Asked Questions

Can I recover a deleted partition?
Yes, in some cases. Tools like TestDisk, PhotoRec, or EaseUS Data Recovery can scan for lost partitions by reading file system signatures. Success depends on whether new data has overwritten the space.

Do I need to partition an SSD?
Yes, but differently than HDDs. SSDs benefit from proper alignment (usually automatic) and may reserve space for wear leveling. Avoid frequent repartitioning to reduce write cycles, though modern SSDs handle it well.

Why can’t I see my new partition in File Explorer?
The partition may not have a drive letter assigned. In diskpart, use assign letter=X. On Linux, manually mount it; on macOS, it should auto-mount unless the file system is unsupported.

Can I resize a partition without losing data?
Yes, if using supported tools like diskpart (shrink only), parted, or diskutil. Always backup first. Extending a partition requires adjacent free space.

What’s the difference between primary and logical partitions?
On MBR disks, you can have up to four primary partitions, or three primary and one extended, which can contain multiple logical partitions. GPT does not use this distinction—every partition is effectively primary.

Is it safe to use third-party partition tools?
Many are reliable (e.g., GParted, MiniTool Partition Wizard), but always use trusted sources. Read reviews and verify digital signatures. Avoid tools that promise “magic” recovery without technical basis.