partx
Add or remove partitions from the kernel
TLDR
List the partitions on a block device or disk image
Add all the partitions found in a given block device to the kernel
Delete all the partitions found from the kernel (does not alter partitions on disk)
SYNOPSIS
partx [options]
[<device> [<partition>...]]
PARAMETERS
<device>
The block device (e.g., /dev/sda or /dev/nvme0n1) whose partition table should be rescanned or queried.
<partition>...
Optional: Specific partition numbers to add or delete. If omitted with -a or -d, all partitions are considered.
-a
Add the specified partitions (or all found partitions) to the kernel's partition table.
-d
Delete the specified partitions (or all found partitions) from the kernel's partition table.
-u
Update the kernel's view of the partitions on the specified device. This is the most common use case, forcing a re-read of the partition table.
--nr <N>
Specify a partition number or range (e.g., --nr 1-5) for actions like add or delete.
-t <TYPE>
Specify the partition table type (e.g., dos, gpt). Useful when auto-detection fails.
--show
List the partitions on the specified device in a human-readable format. Similar to fdisk -l output.
--bytes
When used with --show, print sizes in bytes instead of human-readable units.
--json
When used with --show, output partition information in JSON format.
--pairs
When used with --show, output partition information in key="value" pairs.
--raw
When used with --show, output partition information in raw, column-based format suitable for scripting.
DESCRIPTION
The partx command is a utility used to inform the Linux kernel about changes made to a disk's partition table without requiring a system reboot. When you modify partitions using tools like fdisk, parted, or gdisk, the kernel doesn't automatically detect these changes. partx forces the kernel to re-read the partition table of a specified disk device, making the new or modified partitions visible and usable by the system. This is crucial for managing storage on a running system, especially in server environments where reboots are undesirable. It's important to note that partx does not modify the partition table itself; it only tells the kernel to rescan it. If partitions are in use (e.g., mounted or used for swap), partx might fail, and those resources may need to be unmounted or deactivated first.
CAVEATS
partx requires root privileges to operate. It does not create or destroy partitions; it merely informs the kernel about existing changes. If a partition is currently in use (e.g., mounted or part of a LVM volume group), partx might fail to update its status in the kernel. For complex scenarios involving device-mapper (like LVM or software RAID), kpartx may be a more appropriate tool to manage device-mapper entries.
COMMON USAGE EXAMPLE
After creating a new partition (e.g., /dev/sdb1) on /dev/sdb using fdisk, you would typically run:
sudo partx -u /dev/sdb
This command ensures the kernel sees the new /dev/sdb1, allowing you to format and mount it.
To simply list partitions on a device:
sudo partx --show /dev/sda
HISTORY
partx is part of the util-linux project, a collection of essential utilities for Linux systems. Its development has focused on providing a robust and reliable way to manage kernel-level visibility of disk partitions, becoming a standard tool in system administration for live partition adjustments without the need for disruptive reboots. It evolved from simpler utilities to integrate more advanced features like various output formats and support for different partition table types.