SquashFS Sparse IMG

Secure USB sticks efficiently and space-saving, can be easily realized with SquashFS or Sparse Image. I would like to briefly describe the routes and outline the necessary steps.

Basically, the path looks similar on both paths:

  • Read data stream
  • Fill with zeros
  • Compress

Two questions remain. 1. I go the detour via an image and 2. I choose SquashFS or IMG. It should be considered here, that SquashFS can only be read into the file system.

I would first like to describe the way through an image, since the web is the same for both formats and finally, there is the one-liner, which reads directly from a device and processes the data.

dd if=/dev/some_device of=/home/backup.img
mount /home/backup.img /mnt
dd if=/dev/zero of=/mnt/zero_file.tmp
WAIT UNTIL DISK IS FULL AND KILL DD
rm /mnt/zero_file.tmp
umount /mnt

# FOR GZIP IMG
gzip -c backup.img > backup.img.gz

# FOR SQUASHFS
mkdir empty-dir
mksquashfs empty-dir OUTPUT.img -comp gzip -Xcompression-level 9 -xattrs -wildcards -p 'md00_squash1.img f 444 root 0 dd if=/home/backup.img bs=64K'

# FULL DISK MOUNT IMG LINUX
kpartx -as backup.img
mount /dev/mapper
unmount /dev/mapper
kpartx -ds

# FULL DISK MOUNT IMG FREEBSD
mdconfig -a -t vnode -f backup.img -o noreadonly -u 0 
mount /dev/md0
umount /dev/md0
mdconfig -d -u 0 -f backup.img

As you can see beautifully, the path is very similar. The one-liner is already included. In line 13 for the dd part you simply specify the device as the source.

The image size can be further reduced using different archive formats and compression levels. The block size used has another effect when reading in with dd.

I still have a few links somewhere, who deal with the topic. I'll hand them in on the occasion.

Compression Comparison

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.