6

I've backed up a partition using sudo dd bs=8M if=/dev/sda2 | gzip > /someFolderOnSDB/sda2.img.gz.

The image is stored on a separate disk sdb. When restoring it using gunzip -k /mnt/bkp/sda2.img.gz | sudo dd of=/dev/sda2, I noticed that the image is being unzipped into the folder someFolderOnSDB where the gz file is, and I think is simultaneously being written with dd to sda2.

I don't want that. I want the unzipping to happen in memory, rather than on sdb and the portions being unzipped get directly written to sda with dd.

The unzipped image is 300GB in size. I considered using tee or/and the redirect operator >, but am unsure how.

1 Answer 1

6

You can do this by instructing gunzip to write the decompressed data to its standard output:

gunzip -c /mnt/bkp/sda2.img.gz | sudo dd of=/dev/sda2 
2
  • Worked! Thanks. I assumed writing to standard output was to show output on the terminal. During the write, around 700MB of memory slowly shifted from RAM to swap space. Total RAM occupied was eventually just 245MB. Wonder why it happened. I guess I should've used bs=8M. Commented Feb 3, 2021 at 7:24
  • For efficiency you'd probably want dd iflag=fullblock bs=8M or cat Commented Jul 30, 2023 at 21:17

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.