28

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?

5
  • 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
  • 6
    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
  • 4
    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. Aug 29 '15 at 16:25
36

Use unzip -p:

unzip -p 2015-11-21-raspbian-jessie.zip 2015-11-21-raspbian-jessie.img | dd of=/dev/sdb bs=1M

-p extracts files to stdout

8
  • 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
  • 7
    Or simply unzip -p … >/dev/sdb. Aug 29 '15 at 16:25
  • 2
    @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
  • 7
    @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. Aug 29 '15 at 17:26
  • 1
    @G-ManSays'ReinstateMonica' No, that should have been sudo -s 'cat >/dev/sdb' May 4 '21 at 18:17
2

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
3
  • 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
  • or use the dd with the status=progress option of your version of dd supports it
    – CervEd
    May 4 '21 at 18:40
  • 1
    note that this answer presumes the zip file only contains the image file. Use unzip -l to check
    – CervEd
    May 4 '21 at 18:42
0

I typically use unzip -p 2015-11-21-raspbian-jessie.zip >/dev/sdb or zcat 2015-11-21-raspbian-jessie.gz >/dev/sdb for convenience. This is because when doing large data transfer, we expect the operating system to automatically adjust block size (according to source block size, target block size, memory availability, etc.) for optimal performance, and it turns out they work faster than dd if= of= bs= (maybe because I did not by-brute-force try out all possible choices of blocksizes for dd) ^_^

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.