How To Make A Sparse File On Android With Terminal

0

1

I'm trying to make a sparse file on android. For this I'm using Android Terminal Emulator. I have installed Busybox so I can use the dd command. Other commands like truncate aren't installed. My question: does anyone know how to make a sparse file with android terminal?

I've tried some commands I found on internet:

dd if=/dev/zero of=/sdcard/file.img bs=1 count=0 seek="wanted size"    

But no file would be made. I also tried:

dd if=/dev/zero of=/sdcard/file.img bs="wanted size" count=1.   

But I would get the following error:

dd "path of if" invalid argument    

Does anyone know how to get it right?

Jaïr Paalman

Posted 2015-07-14T10:45:06.040

Reputation: 201

Try to be more specific about "some kind of error". – cYrus – 2015-07-14T11:14:58.023

Answers

1

I've already found the answer myself.

dd if=/dev/zero of=/sdcard/file.img bs=1 count=0 seek="wanted size"    

Would not make a file since the size on the drive is determined by the block size and count. By setting the count to 0 the file would be 0 bytes and being so, it wouldn't exist.

dd if=/dev/zero of=/sdcard/file.img bs="wanted size" count=1    

Would give the following error:

dd "path of if" invalid argument    

The problem here is that there's a limit to the block size. It can't be set that big. I needed to calculate the count for the wanted block size. I chose 64k. This is the working command for making a 512 MB sparse file:

dd if=/dev/zero of=/sdcard/file.img bs=64k count=8192    

Using seek is optional.

Jaïr Paalman

Posted 2015-07-14T10:45:06.040

Reputation: 201

1Using seek is not optional. What you created is not a sparse file at all. – Daniel B – 2015-07-16T11:13:00.227