I'm using fdisk to resize the partitions on a raw QEMU image. When I write the new partition table, it hangs at "Syncing disks."

Note that I'm running fdisk as non-root since I don't need root to edit the image file.

What would cause "Syncing disks" to hang like this?

  • Run strace -o fdisk.strace fdisk to see what it's hanging on. – Gilles Feb 28 '12 at 23:54
  • It's dead now... I tried strace -p to attach to the process, but it hung, and I couldn't kill it either! – Lorin Hochstein Feb 29 '12 at 3:55

After printing the "Syncing disk" message, fdisk calls sync(2) syscall, which causes all buffered modifications to file metadata and data to be written to the underlying file systems. It is expected that this operation can take some time, but it shouldn't hang forever. If it does, you might see in which function in the kernel it hangs in /proc/FDISK_PID/stack.

The question is why fdisk calls sync() while working with the image file (not real device). It should not be needed IMHO.


Possible workaround:
I had the same problem, and the way around it was to use sfdisk instead of fdisk. You will find that you can do anything with sfdisk fdisk can do.

For example, instead of doing:

  fdisk $image <<FDISK

I did:

echo ",+," | sfdisk -N2 $image

Suddenly no sync problems.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.