Full system backup with SquashFS

From ArchWiki

This article or section needs language, wiki syntax or style improvements. See Help:Style for reference.

Reason: Too specifically geared towards one specific sort of backup (using an entire device as the destination), reads like a blog post, content organization is unclear. (Discuss in Talk:Full system backup with SquashFS)

Compressed backup archives of whole filesystems can be made in the SquashFS format. Backup and retrieval takes relatively less time with its random access capability, but any kind of modification other than appending is not yet possible.

Device File Description
/dev/sdB Backup Drive
/dev/sdL Live Medium
/dev/sdSRC Drive to Be Backed Up

Pros and cons


  • No partitioning, no guessing how much size is required
  • SquashFS should be supported by most rescue disks
  • Random access[citation needed], with a plain mount
  • Duplicate files are removed by default (unless -no-duplicates flag is on)


  • Access Control Lists are not yet supported, and therefore not backed up
  • Not accessible from Windows1
  • Appendable but impossible to remove things from it
  • To use the disk for some other purposes, you have to destroy the backup2
  1. squashfs-tools-ng may support SquashFS image files but Windows itself does not support partitionless drives at all.
  2. Do not grab the lifebuoy when you need a swim ring. File sharing and backup should be in separate disks. Please buy adequate backup hardware.

Prepare the backup drive

  • All data on the backup drive will be lost.
  • All data on machine may be lost if an incorrect device file is specified.
  1. Wipe out all partitions /dev/sdBN, then the partition table /dev/sdB, with wipefs.
  2. Synchronize all write caches # sync
  3. Inform the OS of partition table changes # partprobe
  4. Check for bad blocks:

Prepare a live medium

Installation guide#Prepare an installation medium or archiso to /dev/sdL

Note: Creating SquashFS filesystem requires squashfs-tools, which is included in the official Arch Linux installation image.

Back up

Installation guide#Boot the live environment

Tip: If you do not have enough USB ports for both the backup drive and live medium:
  1. Boot the live medium
  2. When the boot loader menu appears, press 'e'
  3. Append copytoram to kernel parameters
  4. # udisksctl power-off -b /dev/sdL (requires archiso releng with udisks2 in packages.x86_64)
  5. Make sure the live medium stops spinning and disconnect it

Mount filesystems you would like to backup. (e.g. /dev/sdSRC to /mnt)

# fsck /dev/sdSRC
# mount -o ro /dev/sdSRC /mnt

Back up (example script)

  • All data on the backup drive will be lost.
  • All data on machine may be lost if an incorrect device file is specified.
# mksquashfs /mnt /dev/sdB \
  -not-reproducible \
  -xattrs \
  -wildcards \
  -noappend \
  -progress \
  -mem 5G \
  -e \
    var/cache/pacman/pkg \
    var/lib/pacman/sync \
    var/log/journal \
    efi \
    boot/grub \
    boot/initramfs-linux"*".img \
Slightly increase backup speed
RAM granted to mksquashfs
List of exclude dirs/files

(Optional) Test backup in QEMU

Grant permission

$ sudo chown $USER:$USER /dev/sdB

Launch QEMU

Note: Kernel and initramfs from the host machine are used.
$ qemu-system-x86_64 \
  -kernel /boot/vmlinuz-linux \
  -append "root=/dev/sdB ro loglevel=3 init=/usr/lib/systemd/systemd" \
  -initrd /boot/initramfs-linux-fallback.img \
  -drive file=/dev/sdB,index=0,media=disk,format=raw \
  -m virtual_machine_ram_in_MiB \
  --enable-kvm \
  -cpu host

(Optional) Inspect backup

Get backup date

# date --date=@"$(unsquashfs -mkfs-time /dev/sdB)"

More superblock information

# unsquashfs -stat /dev/sdB


The factual accuracy of this article or section is disputed.

Reason: unsquashfs -stat and df gives different sizes (Discuss in Talk:Full system backup with SquashFS)
# COUNT="$(unsquashfs -stat /dev/sdB | grep -F 'Filesystem size' | cut -d' ' -f3)"
# echo "$COUNT Byte"
# numfmt --to=iec-i "$COUNT"
# head -c "$COUNT" /dev/sdB | sha1sum | tee -a sha1sum.txt

Retrieve file from backup

# mount /dev/sdB /mnt
# cp /mnt/path/to/file /path/to/destination

Restore backup

This article or section needs expansion.

Reason: Add unsquashfs oneliner (Discuss in Talk:Full system backup with SquashFS)

To make system bootable after restore: