Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a QEMU image myserver.img that is about 20GiB. The file serves as a "virtual" hard disk for the server. Now the first 512 bytes contain the MBR, and I am trying to overwrite those bytes with zeroes. On a normal disks, this one would work:

dd if=/dev/zero of=/dev/sda bs=512 count=1

But when I try that on the image file, the file gets overwritten and is only 512 bytes in size (instead of 20GiB). Is there a way to change only the first 512 bytes, preferably with dd?

share|improve this question
add comment

2 Answers

up vote 6 down vote accepted

Add conv=notrunc:

dd if=/dev/zero of=YOUR_IMAGE_FILE bs=512 count=1 conv=notrunc
share|improve this answer
add comment

Try using dd with conv=notrunc

dd if=/dev/zero of=myserver.img bs=512 count=1 conv=notrunc

From the dd man page

   notrunc
          do not truncate the output file

e.g.

ls -l myserver.img
-rw-r--r-- 1 iain users 1536 Mar 27 12:31 myserver.img

dd if=/dev/zero of=myserver.img bs=512 count=1 conv=notrunc

ls -l myserver.img
-rw-r--r-- 1 iain users 1536 Mar 27 12:32 myserver.img
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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