Linux partprobe Command

Linux 命令大全Linux Command Encyclopedia


partprobe is a utility in Linux systems used to notify the operating system to re-read the partition table. When you modify the disk partition table without restarting the system, partprobe helps the kernel recognize these changes.


Why do you need partprobe

In Linux systems, when you use tools such as fdisk or parted to modify disk partitions, these changes are not immediately recognized by the kernel. The traditional approach is to restart the system, but this is often not feasible in production environments. partprobe provides a way to have the kernel re-read the partition table without restarting.


Command Syntax

partprobe [选项] [设备...]

Common Options

Option Description
-d Do not update the kernel
-s Display summary information
-h Display help information
-v Display version information

Usage Examples

Basic Usage

Re-read the partition table of the specified disk:

sudo partprobe /dev/sda

Display summary information

sudo partprobe -s

Output example:

/dev/sda: msdos partitions 1 2 3

Re-read the partition tables of all disks

sudo partprobe

How it works

partprobe triggers a partition table re-read by sending a BLKRRPART ioctl request to the kernel. This process involves the following steps:

Example

sequenceDiagram
User ->> partprobe: Execute command
partprobe ->> Kernel: Send BLKRRPART request
Kernel ->> Disk driver: Re-read partition table
Disk driver -->> Kernel: Return new partition information
Kernel -->> partprobe: Operation result
partprobe -->> User: Display result or error

Notes

  1. Permission requirements: partprobe usually requires root privileges
  2. Usage scenarios: Mainly used after modifying the partition table with partition tools
  3. Alternatives: You can also useblockdev --rereadptcommand
  4. Risk warning: Improper use may cause system instability

FAQ

Q: What is the difference between partprobe and partx?

A: partprobe notifies the kernel to re-read the entire partition table, while partx allows more fine-grained control over adding or removing specific partitions.

Q: Why are my partitions still not visible after running partprobe?

A: Possible reasons include:

  1. The partition table changes were not correctly written to the disk
  2. The device is occupied by another process
  3. The kernel does not support the new partition type

Practical Application Scenarios

Scenario 1: Extending an LVM physical volume

Example

# 1. Use fdisk to delete the old partition and create a larger new partition
sudo fdisk /dev/sdb

# 2. Let the kernel recognize the new partition table
sudo partprobe /dev/sdb

# 3. Extend the physical volume
sudo pvresize /dev/sdb1

Scenario 2: Handling after adding a new partition

Example

# 1. Use parted to create a new partition
sudo parted /dev/sdc mkpart primary ext4 1GB 5GB

# 2. Notify the kernel
sudo partprobe /dev/sdc

# 3. Format the new partition
sudo mkfs.ext4 /dev/sdc1

Best Practices

  1. Back up important data before performing partition operations
  2. Uselsblkorfdisk -lto verify partition changes
  3. In production environments, first validate the partitioning scheme on a test system
  4. Consider using the-soption to view summary information first

Summary

partprobe is an important tool for Linux system administrators to maintain disk partitions. It solves the problem of needing to restart the system after modifying the partition table. Mastering the use of partprobe can significantly improve disk management efficiency, especially in environments where partitions need to be adjusted frequently.


Linux 命令大全Linux Command Encyclopedia

Other Extensions