Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got a bootable flash memory card with an Ubuntu operating system on it along with other programs, ie. a fully functioning system I use on a single-board computer. I'd like to back it up on my PC's (also running Ubuntu) hard disk, but without wasting space as the dd command would do (because it also backs up free space). The flash drive is 32GB big and only 10% full. It doesn't have any partitions on it.

What are the options?

EDIT the flash drive is formatted as ext4, so partimage doesn't apply.

share|improve this question

migrated from Dec 6 '11 at 17:22

This question came from our site for professional and enthusiast programmers.

up vote 4 down vote accepted

If you want to use dd because with it you can cook very quickly other flash memory:

  • set to zero all free space: dd if=/dev/zero of=/media/usb_device_dir/ZEROFILL ; rm /media/usb_device_dir/ZEROFILL this creates a big file filled with zero and then removes it.

  • dd if=/dev/usb_device | bzip2 > os_image.bz2

Or make a tar of your operating system:

cd /media/usb_device_dir
tar jcpvf /home/foo/os_image.tar.bz2 . 

But before extracting this to a clean flash card, you have to

  • format

  • add bootable flag

  • install a bootloader

share|improve this answer
Hi Alessandro. Could you please explain how the first statement creates a "big file"? What is it's size? Should I replace /dev/zero with anything, or is it a special command to dd? – mmm Dec 6 '11 at 16:45
And another thing: shouldn't be rm /media/usb_device_dir/*ZEROFILL* ? – mmm Dec 6 '11 at 17:21
Yes, you are right, it is /media/usb_device_dir/ZEROFILL just a copy-paste error. It writes zero to that file until there's no space available. – Alessandro Pezzato Dec 6 '11 at 17:57
Just a note / adding parameter bs=10M to the dd command speeds up the progress dramatically on my PC – Kamil Šrot Aug 8 '14 at 15:24

dd if=/dev/your_usb | lzma -9c > usb_image.bin.lzma shouldn't waste any space.

share|improve this answer
Thanks Let_Me_Be, is there a way to make this particular dd command execute a bit faster? Eg. less compression? Is there a way for the dd command to output any progress indication? And last but not least, what is the command to uncompress the image to your_usb afterwards? – mmm Dec 6 '11 at 16:47
@mmm lzcat usb_image.bin.lzma | dd of=/dev/your_usb – Let_Me_Be Dec 6 '11 at 17:10
pv /dev/your_usb | lzma -9c > usb_image.bin.lzma wil show progress (requires package pv installed). – eldering Dec 6 '11 at 17:39

If you can assume that empty areas on the filesystem are filled with zeros Let_Me_Be's answer applies.

Otherwise have a look at Partimage

share|improve this answer
Is it likely that ext3/ext4 will fill empty space with zeroes? I have a feeling that it is not so, but have nothing to back it up but performance considerations. – user49531 Dec 6 '11 at 16:02
Thanks halo, I edited my question, partimage doesn't support ext4, unfortunately. – mmm Dec 6 '11 at 16:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .