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
- Don't prefix
fdisk
withsudo
(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. - After each
fdisk
, runpartprobe
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.