Re-reading the partition table failed with error 16: Device or resource busy

Looks like this device is mounted. Run umount /dev/sdb1 and try again.


Assuming that you're getting this as a result of automating (e.g., using expect) the fdisk operation (and that the partition isn't actually mounted), try adding a few seconds of delay after modifying the partition and before writing the partition able.

I got the same error when I was trying to automate a call to fdisk on Centos 7.6 a la:

# (echo "d"; echo "";
        echo "n"; echo ""; echo 3; echo 2001954; echo "";
        echo "w") | fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): Partition number (1-3, default 3): Partition 3 is deleted

Command (m for help): Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): Using default response p
Partition number (3,4, default 3): First sector (2001954-31116287, default 2002944): Last sector, +sectors or +size{K,M,G} (2001954-31116287, default 31116287): Using default value 31116287
Partition 3 of type Linux and of size 13.9 GiB is set

Command (m for help): The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 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)
Syncing disks.


My suspicion was that my piped-in command stream was surfacing a timing issue in fdisk (that wouldn't be triggered by slower/manual input) so I started sprinkling sleep commands to delay various inputs until the error went away. The problem in my case was that the w was happening too soon after the new partition was defined.

A sleep 5 before the w results in consistent success:

# (echo "d"; echo "";
        echo "n"; echo ""; echo 3; echo 2001954; echo "";
        sleep 5; echo "w") | fdisk /dev/sdb