find out what the drive you want to backup is called, in this case it’s an USB Stick /dev/sdb

you could use gparted which gives you a nice graphical view of where is what.

or you use:

lsblk 

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 111.8G  0 disk 
|-sda1   8:1    0 107.2G  0 part /
`-sda5   8:5    0   4.6G  0 part [SWAP]
sdb      8:16   1   7.3G  0 disk 
`-sdb1   8:17   1   7.3G  0 part /media/usb0

or:

mount | grep usb

/dev/sdb1 on /media/usb0 type vfat (rw,nosuid,nodev,noexec,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=utf8,shortname=mixed,errors=remount-ro,user)

fill the device with zeros

should result in much smaler filesize of the backup (gzip compressed)

cd /media/usb0; # change to the dir your usb stick is mounted
cat /dev/zero > bigfile.txt; # if it does not stop by itself "device full" then cancel it with Ctrl+C
rm -rf bigfile.txt; # remove the big junk file again

monitor progress:

dd does not do this automatically if you want to monitor the progress use pv

apt-get install pv; # install pv

basic operation:

dd if=SOURCE of=TARGET

dd with gzip: TESTED and Worked!

!!! BE CAREFUL YOU DON’T WANT TO OVERWRITE ANY INTERNAL HARDDISK HERE!!!

this method was successfully tested in backing up and restoring an usb stick.

backup:

umount /dev/sdb; # umount the usb stick
dd if=/dev/sdb | pv | gzip -c  > /where/compressed/image/is/stored/USBStickImage.img.gz; # backup content of usb stick (inkluding boot sector) to a file

now unplug your current usb stick and insert new one…

restore:

gunzip -c /where/compressed/image/is/stored/USBStickImage.img.gz | pv | dd of=/dev/sdb; # restore content and boot sector to a different usb stick

example:

dd if=/dev/sdb | pv | gzip -c > /mnt/DATA/SOFTWARE/ACRONIS/Acronis2015.bootstick.img.gz; # backup a 8GB Stick (resulted in 7.5GByte FILE!!! ARGH)
gunzip -c /mnt/DATA/SOFTWARE/ACRONIS/Acronis2015.bootstick.img.gz | pv | dd of=/dev/sdb; # restore it to a 32GByte stick (takes a while)

i actually cacneled after 1.2GBytes…. Strg+C but the stick works! 😀

untested: dd with pigz (compression using multiple cores)

using multiple cores for compression speeds up image creation.

default block size to bs=1M is used for faster operation.

apt-get install pigz; # install pigz

create compressed backup file from whole disk with pigz

dd bs=1M if=/dev/sdX | pigz -c0 > /path/backup_of_sdX.img.gz

restore compressed whole disk backup from file:

this will erase all the content of sdX

pigz -dc /path/backup_of_sdX.img.gz | dd bs=1M of=/dev/sdX

Mount image

Look at partitions inside a raw image, find sector start and sector size:

fdisk -lu /path/backup_of_sdX.img.gz

Mount from image with sector start and sector size:

mount -o loop,offset=$((137216 * 512)) backup01.img /media/bkp1/

creditz thanks and src: https://designdesk.org/linux/dd-command-copy-whole-volumes

admin