repart

storageLinux
The repart command is one of the most frequently used commands in Linux/Unix-like operating systems. repart Repartition a disk or update partition tables

Quick Reference

Command Name:

repart

Category:

storage

Platform:

Linux

Basic Usage:

repart [options] [arguments]

Common Use Cases

    Syntax

    repart [options] device

    Options

    Option Description
    --dry-run Don't make any changes, just show what would be done
    --empty=mode Specify handling of existing partitions (refuse, allow, require, force, create)
    --discard=mode Control TRIM/UNMAP operations (disabled, passive, active, or force)
    --size=size Specify size of operation (auto, min, max, or size)
    --factory-reset=bool Whether to apply factory reset partitions
    --can-factory-reset Test if factory reset is defined
    --root=path Operate relative to specified root directory
    --image=path Operate on specified disk image instead of the local machine
    --definitions=path Find partition definitions in specified directory
    --key-file=path Key to use for LUKS encryption
    --tpm2-device=path TPM2 device to use for LUKS encryption
    --tpm2-pcrs=list TPM2 PCR indexes to use for LUKS encryption
    --seed=UUID 128-bit seed UUID for partition UUIDs
    --pretty=bool Show pretty-printed partition diagram
    --json=mode Generate JSON output (pretty, short, off)
    --no-pager Do not pipe output into a pager
    --no-legend Do not show the legend
    --help Show help message
    --version Show version information

    Examples

    How to Use These Examples

    The examples below show common ways to use the repart command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    Basic Examples:

    sudo systemd-repart
    Run repart to apply partition configuration from /etc/repart.d.
    sudo systemd-repart --dry-run
    Show what changes would be made without actually applying them.

    Advanced Examples:

    sudo systemd-repart --dry-run --json=pretty
    Show planned changes in JSON format for better readability.
    sudo systemd-repart /dev/sda Apply partition configurations to a specific device. sudo systemd-repart --definitions=/path/to/definitions Use partition definitions from a specific directory. sudo systemd-repart --size=auto Automatically determine partition sizes based on available space. sudo systemd-repart --empty=force Force creation of empty partitions even if already exist. sudo systemd-repart --sector-size=4096 Specify a non-default sector size. sudo systemd-repart --copy-from=/dev/sdb Copy partition table from another device. sudo systemd-repart --factory-reset=yes Reset partitions to factory defaults defined in configuration.

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    The `repart` command, often accessed as `systemd-repart`, is a modern disk partitioning tool that is part of the systemd suite. It's designed to safely and declaratively manipulate partition tables on disk images or block devices according to pre-defined partition definitions. Unlike traditional partitioning tools like `fdisk` or `parted` that require interactive input or complex command-line parameters, `repart` uses declarative configuration files to define the desired partition layout. This approach is particularly well-suited for automated system provisioning, factory resets, and ensuring consistent partitioning across multiple systems. Key features of the `repart` command include: 1. Declarative Configuration: Partition layouts are defined in simple text files with a clear syntax, making them easy to version control and audit. 2. Safety-Focused: The tool is designed to be safe, only creating or growing partitions without deleting or shrinking existing ones unless explicitly configured to do so. 3. GPT Support: Works with modern GPT (GUID Partition Table) partition tables. 4. Integration with systemd: Can leverage systemd's ecosystem for features like encryption and device management. 5. Automatic Sizing: Can automatically calculate partition sizes based on available disk space and relative weights. 6. Factory Reset: Supports defining partitions that only activate during a factory reset operation. 7. Encryption Support: Built-in support for LUKS encryption, including TPM2 integration for secure key storage. The configuration files for `repart` are typically stored in `/etc/repart.d/` with a `.conf` extension. Each file defines a single partition with attributes like type, size, label, and various flags. Common use cases for `repart` include: - Initial partitioning of operating system images - Expanding partitions to use available space after image deployment - Implementing factory reset functionality in embedded or IoT devices - Creating standardized partition layouts across fleets of systems - Automating disk layout as part of system provisioning While `repart` is a powerful tool for automated and declarative partitioning, it's important to note that it's relatively new compared to traditional tools like `fdisk`, `parted`, or `gparted`. It's primarily designed for systems using systemd and modern partition tables, and may not be suitable for all partitioning needs, especially on older systems or for complex partitioning scenarios that require interactive decision-making.

    Related Commands

    These commands are frequently used alongside repart or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the repart command works in different scenarios.

    $ repart
    View All Commands