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>
PARAMETERS
-a
Add the specified partitions or all partitions if none are specified.
-d
Delete the specified partitions or all partitions if none are specified.
-u
Try to update an existing partition (rather than deleting and adding).
-r
Read the partition table.
-n
Do not make changes to the device. Display what would be done.
-o OFFSET
Specify the output columns. Common columns include START, END, SIZE, NAME, UUID, TYPE
-g
Force reread of partition table.
<device>
The device name (e.g., /dev/sda).
[partition_number ...]
Specific partition numbers to operate on. If omitted, all partitions are affected.
DESCRIPTION
partx is a Linux command-line utility used to inform the kernel of partition table changes, specifically after you've modified a partition table without rebooting. It can be used to add, delete, or update partitions on a device, like a hard drive or SSD, directly from the command line.
It is particularly useful in scenarios where the kernel's in-memory representation of the partition table becomes out of sync with the actual on-disk partition table. partx reads partition tables from the specified device and tells the kernel about their existence.
partx primarily focuses on adding and removing partitions dynamically. It reads and interprets partition tables, communicating any changes to the operating system kernel to maintain consistency.
Without running partx, the system may not recognize changes made to the partition table, leading to issues like inaccessible data or incorrect device mappings.
CAVEATS
partx might not work correctly on stacked devices or when LVM or MD RAID uses the whole disk without any partitions.
EXIT CODES
partx returns 0 on success, and a non-zero value on failure. Inspecting the exit code can be useful for scripting.
COMMON USAGE EXAMPLES
- To add partitions: partx -a /dev/sda
- To delete partitions: partx -d /dev/sda
- To refresh partition table: partx -v -u /dev/sda
HISTORY
partx has been a part of the util-linux package for many years.
It originated to provide a way to update the kernel's view of partition tables without needing a reboot, a crucial capability for system administrators and advanced users managing storage.