I am under the following restrictions:

  • I have a 1.0 GB .zip file on my computer which contains one file, a disk image of raspbian. When uncompressed, this file is 3.2 GB large and named 2015-11-21-raspbian-jessie.img.
  • After having downloaded the zip file, I have just under 1.0 GB of storage space on my computer, not enough space to extract the image to my computer.
  • This file needs to be uncompressed and written to an SD card using plain old dd.

Is it possible for me to write the image to the SD card under these restrictions?

I know it's possible to pipe data through tar and then pipe that data elsewhere, however, will this still work for the zip file format, or does the entire archive need to be uncompressed before any files are accessible?

  • I realize I could just extract the zip file to an external flash drive, but this is more fun. I want to pull this off for the challenge (and learning experience) of it! – IQAndreas Aug 29 '15 at 5:14
  • 3
    If your SD card is device /dev/sdh, then run unzip -p file.zip >/dev/sdh. (I know that the use of dd is traditional but it is not necessary.) – John1024 Aug 29 '15 at 5:24
  • Huh. Would that work without dd? I figured the Block Size parameter would be needed. – CRThaze Aug 29 '15 at 6:46
  • 2
    Yes, it works without dd. In the past, block size was very important when writing to tapes. For disks, it doesn't matter. – John1024 Aug 29 '15 at 7:38
  • 1
    @TheCzar Aside from tapes, the block size parameter to dd can only lose data or slow things down (or in rare case speed things up a little, if large enough). Forget about dd, it's very rarely useful. – Gilles 'SO- stop being evil' Aug 29 '15 at 16:25

Use unzip -p:

unzip -p 2015-11-21-raspbian-jessie.zip 2015-11-21-raspbian-jessie.img | dd of=/dev/sdb bs=1M
  • The code is running, and neither my harddrive space nor my RAM is running out. All good so far. – IQAndreas Aug 29 '15 at 5:35
  • 5
    Or simply unzip -p … >/dev/sdb. – Gilles 'SO- stop being evil' Aug 29 '15 at 16:25
  • 1
    @Gilles besides the downside, dd is sometimes useful with sudo: unzip -p ... | sudo dd of=/dev/sdb bs=1M – yaegashi Aug 29 '15 at 17:17
  • 5
    @yaegashi unzip -p … | sudo 'cat >/dev/sdb' But I prefer sudo chown $USER /dev/sdb which gives me an extra opportunity to check that I'm writing to the right device. – Gilles 'SO- stop being evil' Aug 29 '15 at 17:26
  • It worked beautifully! Mind if I edit in the exact file name in case anyone just wants to copy and paste the command? – IQAndreas Sep 8 '15 at 15:53

After a bit of struggling with the former solution:

 unzip -p ~/Downloads/2020-02-05-raspbian-buster-lite.zip | sudo dd of=/dev/disk2 bs=1m

or, if you want to see the progress and you have installed pv:

 unzip -p ~/Downloads/2020-02-05-raspbian-buster-lite.zip | pv | sudo dd of=/dev/disk2 bs=1m
  • note that some versions of dd will require a capital M instead of a lowercase for the bs= option. – Ian Hunter Aug 6 '20 at 0:39

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.