Reread partition table without rebooting

By xngo on February 21, 2019

Symptom

After you executed multiple fdisk commands, you get the following error message:

Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Device or resource busy
 
The kernel still uses the old table. The new table will be used at the next reboot 
or after you run partprobe(8) or kpartx(8).

Solution

  1. Don't prefix fdisk with sudo (e.g. (echo m; ...; echo w) | sudo fdisk /dev/sdX). Otherwise, the re-reading of the partition table will fail. I don't know why.
  2. After each fdisk, run partprobe to re-read the partition table. partprobe is part of the GNU Parted package.

NOTE: It is not 100% reliable if you create extended partition and logical partitions on USB stick.

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.