Updated to version 1.4. Please see Shrink-backup github for full information.
Release notes:
Autoexpansion added for rpiOS trixie
Fixed detection and autoexpansion for DietPi
Version included in logfile
"Confirmation window" updates:
Moved into a function
Inclusion of device paths
Countdown timer for `ctrl+c` if `-y` option is selected
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
shrink-backup is a bash script for backing up your SBC into a minimal img file with autoexpansion at boot for supported operating systems
Version 1.4
Info updated: 16 Oct, 2025.
Full information: shrink-backup
I made this script because I wanted a universal method of backing up my SBC:s into img files as fast as possible (with rsync), no matter what os is in use.
shrink-backup is a very fast utility for backing up your SBC:s into minimal bootable img files for easy restore with autoexpansion at boot.
Can backup any device with or without a boot partition as long as the filesystem is ext4, f2fs or btrfs (with subvolumes).
Supports backing up root & boot (if existing) partitions. Data from other partitions will be written to root if not excluded.
For btrfs, all existing top level 5 subvolumes in /etc/fstab will be created with new backups, nested subvolumes will be created and can also be removed/added in an update of the backup img.
Please read Info section for more information.
Autoexpansion tested & supported on following operating systems:
- Raspberry Pi OS (trixie and older)
- Armbian
- Manjaro-arm
- DietPi
- ArchLinux-arm
- Kali-arm
- Ubuntu-server-arm (Ubuntu autoexpands by default, but that can be disabled with -e option)
Autoexpansion does not work on f2fs due to filesystem limitations.
Other operating systems will most likely work too, but autoexpansion will not.
The script will report the operating system as "unknown" but that does not mean the script will fail.
Feel free to make a feature request if you use an operating system not on this list.
Full functionality for usage inside webmin (including "custom command" button).
Latest release: shrink-backup.v1.4
Testing branch if you want to have the absolute latest version. There might be bugs.
Very fast restore thanks to minimal size of img file.
Default device that will be backed up is determined by scanning what disk-device root resides on.
This means that if boot is a partition, that partition must be on the same device and before the root partition.
The script considers everything on the device before root as the bootsector.
Backing up/restoring, to/from: usb-stick /dev/sdX with Raspberry pi os has been tested and works. Ie, writing an sd-card img to a usb-stick and vice versa works.
Ultra-fast incremental backups to existing img files.
See wiki for information about installation methods, usage and examples.
Ideas and feedback is always appreciated, whether it's positive or negative. Please just keep it civil.
If you find a bug or think something is missing in the script, please file a bug report or feature request
To restore a backup, simply "burn" the img file to a device using your favorite method.
When booting a restored image with autoresize active, on some operating systems a reboot will occur after resizing is made (you will be informed at the end of the script if your operating system is affected by this), please wait until the the reboot sequence has occurred. The login prompt may very well become visible before the autoresize function has rebooted.
shrink-backup -h
Script for creating an .img file and subsequently keeing it updated (-U), autoexpansion is enabled by default
Directory where .img file is created is automatically excluded in backup
########################################################################
Usage: sudo shrink-backup [-Uatyelhz] [--fix] [--loop] [--f2fs] imagefile.img [extra space (MiB)]
------------------------------------------------------------------------------------------------------------------------------------------------
-U Update existing img file (rsync to existing img)
Optional [extra space] extends img size of root partition
-a Autoresize root partition, [extra space] is ignored.
When used in combination with -U:
Expand if partition is >=256MiB smaller than resize2fs recommended minimum
Shrink if partition is >=512MiB bigger than resize2fs recommended minimum
-t Use exclude.txt in same folder as script to set excluded directories
One directory per line: "/dir" or "/dir/*" to only exclude contents
-y Disable prompts in script (please use this option with care!)
-e Disable autoexpansion of root filesystem when image is booted
-l Write debug messages to logfile shrink-backup.log located in same directory as script
-z Make script zoom at light-speed, only question prompts might slow it down
Can be combined with -y for UNSAFE ultra mega superduper speed
-q --quiet Do not print rsync copy process
--no-color Run script without color formatted text
--fix Try to fix the img file if -a fails with a "broken pipe" error
Will activate rsync options --delete-before & --fsync
--rsync Define custom rsync line manually. Will print rsync line for user to edit
--loop [img] Loop img file and exit, works in combination with -l & -z
If optional [extra space] is defined, the img file will be extended with the amount before looping
NOTE that only the file gets truncated, no partitions
Useful if you for example want to manually manage the partitions
--chroot [img] Use systemd-nspawn. Loop img file, mount to temp directory, enter chroot environment and drop to shell
This will let you make changes in a chroot environment directly on the img file
For example update with package manager or rebuild initramfs
The script will keep running in the background
--f2fs Convert root filesystem on img from ext4 to f2fs
Only works on new img file, not in combination with -U
Will make backups of fstab & cmdline.txt to: fstab.shrink-backup.bak & cmdline.txt.shrink-backup.bak
Then change ext4 to f2fs in both files and add discard to options on root partition in fstab
--version Print version and exit
-h --help Show this help snippet
########################################################################
Examples:
sudo shrink-backup -a /path/to/backup.img (create img, resize2fs calcualtes size)
sudo shrink-backup -e -y /path/to/backup.img 1024 (create img, ignore prompts, do not autoexpand, add 1024MiB extra space)
sudo shrink-backup -Utl /path/to/backup.img (update img backup, use exclude.txt and write log to shrink-backup.log)
sudo shrink-backup -U /path/to/backup.img 1024 (update img backup, expand img size/root partition with 1024MiB)
sudo shrink-backup -Ua /path/to/backup.img (update img backup, resize2fs calculates and resizes img file if needed)
sudo shrink-backup -Ua --fix /path/to/backup.img 1024 (update img backup, automatically resizes img file if needed, fix img free space)
sudo shrink-backup -l --loop /path/to/backup.img 1024 (write to log file, expand IMG FILE (not partition) by 1024MiB and loop)
Thank you for using shrink-backup ❤️❤️
A backup is not really a backup until you have restored from it.
Yes, I am working on that.
Whiptail is what I am educating me in closer right now.
But it will most likely be it's own script. Trying to implement the script straight up I think would become messy pretty fast, and I don't think anybody is interested in that.
But yes, it is happening, sometime.. xD
I was honestly hoping it would already be a reality, but my health keeps putting up roadblocks for me.
However, there is one mistake. Instead of the last line
~ $ bash pack/usr/lib/u-boot/platform_install.sh pack/usr/lib/linux-u-boot-nanopineo2-current /dev/XXX # replace XXX with the actual device
you need to run
~ $ source pack/usr/lib/u-boot/platform_install.sh
~ $ write_uboot_platform pack/usr/lib/linux-u-boot-nanopineo2-current /dev/XXX # replace XXX with the actual device /dev/sdb
In addition it is important to start the partition at block 8192 (at least for my odroid HC2, may be a differnet number on other devices).
This way you can easily write your backups to an sd.
GPT is something the Armbian build framwork supports, not currently the default, but here is a list of boards that use it:
grep -i gpt *
armsom-sige7.csc:IMAGE_PARTITION_TABLE="gpt"
armsom-w3.csc:IMAGE_PARTITION_TABLE="gpt"
bananapir2pro.csc:IMAGE_PARTITION_TABLE="gpt"
fxblox-rk1.wip:IMAGE_PARTITION_TABLE="gpt"
hinlink-h28k.csc:IMAGE_PARTITION_TABLE="gpt"
hinlink-h88k.csc:IMAGE_PARTITION_TABLE="gpt"
hinlink-ht2.csc:IMAGE_PARTITION_TABLE="gpt"
indiedroid-nova.csc:declare -g IMAGE_PARTITION_TABLE="gpt"
jp-tvbox-3566.tvb:IMAGE_PARTITION_TABLE="gpt"
khadas-edge2.conf:declare -g IMAGE_PARTITION_TABLE="gpt"
mangopi-m28k.csc:IMAGE_PARTITION_TABLE="gpt"
mixtile-blade3.wip:declare -g IMAGE_PARTITION_TABLE="gpt"
nanopct6.wip:IMAGE_PARTITION_TABLE="gpt"
nanopi-r5c.csc:IMAGE_PARTITION_TABLE="gpt"
nanopi-r5s.wip:IMAGE_PARTITION_TABLE="gpt"
nanopi-r6s.conf:IMAGE_PARTITION_TABLE="gpt"
odroidm1.conf:IMAGE_PARTITION_TABLE="gpt"
orangepi3b.csc:IMAGE_PARTITION_TABLE="gpt"
orangepi5.conf:IMAGE_PARTITION_TABLE="gpt"
orangepi5-plus.conf:IMAGE_PARTITION_TABLE="gpt"
panther-x2.csc:IMAGE_PARTITION_TABLE="gpt"
quartz64a.csc:IMAGE_PARTITION_TABLE="gpt"
quartz64b.csc:IMAGE_PARTITION_TABLE="gpt"
radxa-e25.wip:IMAGE_PARTITION_TABLE="gpt"
rock-3a.conf:IMAGE_PARTITION_TABLE="gpt"
rock-5a.wip:IMAGE_PARTITION_TABLE="gpt"
rock-5b.conf:IMAGE_PARTITION_TABLE="gpt"
rock-5-cmio.csc:IMAGE_PARTITION_TABLE="gpt"
station-m2.csc:IMAGE_PARTITION_TABLE="gpt"
station-m3.csc:IMAGE_PARTITION_TABLE="gpt"
station-p2.csc:IMAGE_PARTITION_TABLE="gpt"
xiaomi-elish.conf:IMAGE_PARTITION_TABLE="gpt"