
partx: Parse and update the kernel partition table
partx is a small, focused tool that reads a partition table and tells the kernel about it. It’s handy after creating, resizing, or attaching disk images or devices, but remember: it only affects the kernel’s view, not the disk contents.
Quick start
- List partitions on a device or image:
sudo partx -l /dev/sdX
- If you’re using a disk image, the path might be something like:
sudo partx -l /path/to/disk-image.img
- Add all partitions found in a device to the kernel (with optional verbose output):
sudo partx -a -v /dev/sdX
- For a disk image:
sudo partx -a -v /path/to/disk-image.img
- Delete all partitions from the kernel view (does not modify the disk):
sudo partx -d /dev/sdX
- For a disk image:
sudo partx -d /path/to/disk-image.img
Note: The -l/—list, -a/—add, and -d/—delete options can be combined with host paths that point to either a block device or a disk image.
When to use partx
- After creating or resizing partitions on a device or disk image, to refresh the kernel’s partition table without rebooting.
- When using loop devices or virtualization where partitions appear or disappear at runtime.
Common workflows
- Attach a disk image and import partitions:
# Create or attach the image, then
sudo partx -l /path/to/disk-image.img # inspect current partitions
sudo partx -a /path/to/disk-image.img # expose partitions to the kernel
- Work with a real disk after partitioning (e.g., with fdisk or parted):
sudo partx -l /dev/sdb
# make changes with your partitioning tool, then
sudo partx -a /dev/sdb # or -d if you removed partitions
- Mounting and usage:
lsblk
# if new partitions don’t show up, run partx to refresh
sudo partx -a -v /dev/sdb
Safety and pitfalls
- Do not run partx on a mounted root partition or while filesystems are mounted and in active use. Unmount first when possible.
- partx only updates the kernel’s view. It does not modify on-disk partition tables. For a real partition table change, use a partitioning tool (fdisk/parted) and then refresh with partx.
- If you’re using loop devices or complex storage setups, verify the correct device path before adding or deleting partitions to avoid accidental data exposure or damage.
- After resizing or deleting partitions, you may need to run a filesystem check or resize2fs/xfs_growfs on the mounted filesystem, if applicable.
Troubleshooting tips
- Partitions don’t appear after a change? Try listing first, then re-running add:
sudo partx -l /dev/sdX
sudo partx -a /dev/sdX
- If a disk image is not showing expected partitions, ensure the image contains a partition table and that you’re pointing to the correct file path.
- Kernel caching can be stubborn on some systems. A reboot is a last resort if you suspect an obscure issue, but usually a re-run of partx suffices.
Quick reference
- List: partx -l /path/to/device_or_disk_image
- Add: partx -a /path/to/device_or_disk_image
- Add verbose: partx -a -v /path/to/device_or_disk_image
- Delete: partx -d /path/to/device_or_disk_image
Remember: partx is a low-level utility for synchronizing the kernel with partition tables. Use it carefully, and prefer unmounting when dealing with mounted filesystems.
See Also
- How Does the ifup Command Enhance Network Management?
- How to Use the Shutdown Command in Linux Effectively
- How to Manage LXC Containers with the pct Command in Proxmox
- How to Use the alias Command in Linux?
- How Can You Master Clipboard Management with xsel?
- How to Use the fdisk Command for Effective Disk Management