How to make an image of a bootable flash drive without wasting space (as with dd) on Ubuntu
Solution 1
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
Solution 2
dd if=/dev/your_usb | lzma -9c > usb_image.bin.lzma
shouldn't waste any space.
Solution 3
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
Related videos on Youtube
mmm
Updated on September 18, 2022Comments
-
mmm almost 2 years
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
, sopartimage
doesn't apply. -
Michael O'Connor over 12 yearsIs 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.
-
Michael O'Connor over 12 yearsThanks halo, I edited my question, partimage doesn't support ext4, unfortunately.
-
Admin over 12 yearsHi 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 todd
? -
Gaurav over 12 yearsThanks 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 thedd
command to output any progress indication? And last but not least, what is the command to uncompress the image toyour_usb
afterwards? -
Šimon Tóth over 12 years@mmm
lzcat usb_image.bin.lzma | dd of=/dev/your_usb
-
Admin over 12 yearsAnd another thing: shouldn't be
rm /media/usb_device_dir/
*ZEROFILL* ? -
Jaap Eldering over 12 years
pv /dev/your_usb | lzma -9c > usb_image.bin.lzma
wil show progress (requires packagepv
installed). -
Alessandro Pezzato over 12 yearsYes, 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. -
Kamil Šrot almost 10 yearsJust a note / adding parameter
bs=10M
to thedd
command speeds up the progress dramatically on my PC