How to Use the Command 'partprobe' (with Examples)
- Linux
- December 17, 2024
The partprobe
command is a utility from the GNU Parted project, specifically designed to inform the operating system kernel about changes made to the partition table of hard disks. This is particularly useful when modifications to the partition layout are performed outside regular system tools, which may not automatically notify the kernel about these changes. By using partprobe
, users ensure that the kernel acknowledges these alterations, preventing potential data inconsistencies or access issues.
Use case 1: Notify the Operating System Kernel of Partition Table Changes
Code:
sudo partprobe
Motivation: When you change the partitions on a hard drive (for example, when resizing a partition, creating a new one, or deleting an existing one), the kernel needs to be updated with this new information to ensure that all subsequent file operations are aware of the current disk layout. Without notifying the kernel, there may be risks of data corruption or system errors due to the kernel working with outdated partition information.
Explanation:
sudo
: This command is run with superuser privileges because modifying the system’s partition table information requires administrative access. This is necessary to ensure the command has sufficient permission to interact with the kernel.partprobe
: This is the command that requests the kernel to re-read the partition tables on all available disks. By executing it, you are actively updating the kernel’s understanding of the disk configuration.
Example Output: The output may not be verbose unless errors occur. If successful, the command will complete without any explicit confirmation. However, you may receive messages about devices whose partition tables cannot be read or processed.
[sudo] password for user:
Use case 2: Notify the Kernel of Partition Table Changes and Show a Summary of Devices and Their Partitions
Code:
sudo partprobe --summary
Motivation: This use case is helpful if you want to verify that the kernel has been updated without needing to check each device separately. By receiving a summary, you can quickly verify which storage devices have registered their partition table changes and react accordingly if there are discrepancies.
Explanation:
sudo
: Required for the same reasons as the previous example, ensuring that the command has the necessary permissions to modify kernel data.partprobe
: This command informs the kernel about any changes in the partition tables.--summary
: This option tellspartprobe
to not only update the kernel but also provide a summary of the devices and their recognized partitions. It offers a real-time overview of the partition status across all storage devices, enabling efficient verification.
Example Output:
Output from the --summary
option will list all recognized storage devices and their partitions, making it easier to see each device’s status at a glance.
/dev/sda: msdos partitions 1 2 3
/dev/sdb: gpt partitions 1 2
Use case 3: Show a Summary of Devices and Their Partitions but Don’t Notify the Kernel
Code:
sudo partprobe --summary --dry-run
Motivation:
In scenarios where you need to analyze the proposed changes without actually notifying the kernel, the --dry-run
option is invaluable. It lets you view what the summary would display post-update, without committing any changes to the system. This is especially useful in planning or troubleshooting stages, where understanding potential outcomes without executing them is beneficial.
Explanation:
sudo
: Ensures the command is executed with the necessary privileges.partprobe
: Conveys the intent to modify kernel perception of partition change, albeit not actually doing so due to the dry-run mode.--summary
: Requests a listing of current device partitions as perceived by the command.--dry-run
: This option simulates the command run without making any changes. It safely outputs the results without notifying the kernel of any changes, allowing for assessment and planning before actual execution.
Example Output:
Given its simulation nature, the output resembles what --summary
would provide, except no changes are made, nor is there any kernel notification.
/dev/sda: msdos partitions 1 2 3
/dev/sdb: gpt partitions 1 2
Conclusion:
By utilizing the partprobe
command, users can effectively manage and ensure that the kernel is up-to-date with any partition table changes. Whether you need immediate updates, a thorough overview, or a simulation, partprobe
provides appropriate options for maintaining system stability and data integrity following partition alterations.