“partx” is a Linux command line tool used for adding and deleting partition information from the Linux kernel’s representation of a block device (such as a hard drive). The tool reads partition table information from a block device and informs the kernel of the partitions that exist on the device, allowing the kernel to access and use the partitions.
When a partition is created or deleted, the kernel’s representation of the block device is not immediately updated. The “partx” tool must be run to notify the kernel of the change. This is important because the kernel is responsible for accessing the block device and its partitions, and if it is not aware of the partitions, they will not be accessible to the system.
“partx” can be used with a variety of different partition table formats, including the traditional Master Boot Record (MBR) format and the newer GUID Partition Table (GPT) format. The tool can be used to add and remove partitions one by one, or it can be used to update the kernel’s representation of an entire block device, which is useful when working with devices that have multiple partitions.
If you encounter the below error while running the command partx:
partx: command not found
you may try installing the below package as per your choice of distribution:
Distribution | Command |
---|---|
Debian | apt-get install util-linux |
Ubuntu | apt-get install util-linux |
Alpine | apk add util-linux |
Arch Linux | pacman -S util-linux |
Kali Linux | apt-get install util-linux |
CentOS | yum install util-linux |
Fedora | dnf install util-linux |
OS X | brew install util-linux |
Raspbian | apt-get install util-linux |
partx Command Examples
1. List the partitions on a block device or disk image:
# sudo partx --list path/to/device_or_disk_image
2. Add all the partitions found in a given block device to the kernel:
# sudo partx --add --verbose path/to/device_or_disk_image
3. Delete all the partitions found from the kernel (does not alter partitions on disk):
# sudo partx --delete path/to/device_or_disk_image