How to unzip and dd a disk image to an SD Card with a single command?

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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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

Method 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

Method 3

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) ^_^


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x