Apparently, as of squashfs tools 4.0, mksquashfs supports pseudo-files.
As a result, incredibly, the following does actually work:

Originally Posted by
http://unix.stackexchange.com/a/75590
Streaming Compression
To avoid making a separate temporary file the full size of the disk, you can stream into a squashfs image.
Code:
mkdir empty-dir
mksquashfs empty-dir squash.img -p 'sda_backup.img f 444 root root dd if=/dev/sda bs=4M'
The pseudo-files option of mksquashfs is explained here: http://sourceforge.net/p/squashfs/ma...sage/22031858/
And this link has a few examples: https://tjaldur.nl:8443/repos/gpltoo...o-file.example
But basically:
empty-dir - "source" dir. Basically in our case, just an empty dir to satisfy mksquashfs' input arg format
squash.img - the destination and filename of the output squashfs file
sda_backup.img - the name of the dd backup INSIDE the squashfs file
f - specifies that sda_backup.img is a regular file (as opposed to a directory, block device, or char device)
444 - permissions of the sda_backup.img file inside the squashfs image
root root - UID and GID for the sda_backup.img file inside the squashfs image. Can be specified by decimal numbers, or by name
dd if=/dev/sda bs=4M - the dd command used to read the device we want backed up
Note: Unfortunately, squashfs filesystems are read only (unless you do some trickery with Unionfs), so keep that in mind.
GETTING ACCESS TO YOUR DD IMAGE:
To access your dd image (sda_backup.img), mount the squashfs image (squash.img):
Code:
sudo mount squash.img /mnt
now you have your read-only dd image at /mnt/sda_backup.img, which you can do with what you normally would with a dd image:
DD image is of a partition
Either do a full recovery:
Code:
# WARNING: Don't run this dd command unless you know exactly what it's doing
sudo dd if=/mnt/sda_backup.img of=/dev/sdaX bs=4M
Or mount it
Code:
sudo mount /mnt/sda_backup.img /some/mount/point
now you have access to your files at /some/mount/point.
At this point, you can either browse to /some/mount/point to find/recover files individually, or use rsync to do a fast recovery:
Code:
sudo rsync -n -aAXSH -hv --delete --progress --stats /some/mount/point/ /path/to/mounted/original/fs --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*",/lost+found}
The "-n" will make sure that the only thing that happens on the first run is rsync telling you what it will do. Remove "-n" when satisfied that it'll do what you expect.
DD image is of a full drive
Either do a full recovery:
Code:
# WARNING: Don't run this dd command unless you know exactly what it's doing
sudo dd if=/mnt/sda_backup.img of=/dev/sda bs=4M
OR attach your dd image to the first available loop device:
Code:
sudo losetup -f /mnt/sda_backup.img
See which loop device it attached to:
Tell the kernel to scan the loop device for partitions:
Code:
sudo kpartx -a /dev/loopX
OR
sudo partprobe /dev/loopX
Now you have access to those partitions under /dev/mapper/loop...
You can mount them to gain access to the files:
Code:
sudo mount /dev/mapper/loopXpY /partition/mount/point
If one of those partitions has LVM, it will either automatically show up under /dev/mapper/, or you must do:
Code:
sudo vgscan
sudo vgchange -ay
to have it show up.