I have hdd.img file, which I user as HDD for my virtual machine, but it's size is too small, how can I enlarge it?

There is one method, something like:

dd if=/dev/zero ds=10GB count=8 >> hdd.img

but it takes a lot of time :(

  • The command you wrote will completely overwrite the original content. Is that what you want? – eppesuig Jan 11 '13 at 11:14
  • Sorry, fixed :) – atomAltera Jan 11 '13 at 11:31

Something like that:

dd if=/dev/zero bs=1 seek=new_filesize count=0 of=your_file

For example this:

dd if=/dev/zero bs=1G seek=1000 count=0 of=test

will enlarge file test to 1000G

  • Try it on a test file. It works! All space after old file's content will be filled with "virtual" zeros (sparse file). – Eddy_Em Jan 11 '13 at 11:51
  • Why doesn't it overwrite the original contents? – Ivan Perez Dec 18 '20 at 15:28
  • @IvanPerez, because it creates a sparse file: dd actually writes nothing to original file, just setting seek position to given point. – Eddy_Em Dec 21 '20 at 12:42

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.