How to Create a Bootable System Backup in Linux Using `rsync`

How to create a complete bootable backup of your Linux system using rsync - safer and more flexible than dd for running systems.
How to Create a Bootable System Backup in Linux Using rsync
If you need to create a backup of your running Linux system, rsync is often a better choice than dd. Unlike dd, which copies every byte including empty space, rsync intelligently copies only your actual files and handles running systems gracefully. In this guide, we'll show you how to create a complete bootable backup that you can boot from if your main system fails.
Why Choose rsync Over dd?
Advantages of rsync:
- Handles Running Systems: Works perfectly while your system is running
- Skips Empty Space: Only copies actual files, not unused disk blocks
- Preserves Everything: Maintains permissions, timestamps, symlinks, and attributes
- Faster: No need to copy empty space
- Incremental Updates: Can update an existing backup quickly
- Human-Readable: Creates normal files you can browse and restore individually
When to use dd instead:
- Forensic disk imaging
- Need exact bit-for-bit copy
- Cloning to identical hardware
Prerequisites
Before proceeding, ensure you have:
- Root Access: You'll need
sudoprivileges - Target Drive: An external drive or partition large enough for your used space (not total disk size)
- rsync Installed: Usually pre-installed on most Linux distributions
- Backup Critical Data: Always have a secondary backup of irreplaceable files
Check your system size:
# See how much space is actually used
df -h /
# Example output:
# Filesystem Size Used Avail Use% Mounted on
# /dev/mapper/ubuntu--vg-ubuntu--lv 936G 133G 764G 15% /In this example, you need at least 133GB on your target drive, not 936GB.
Option 1: Create a Bootable Backup to External Drive
This method creates a complete bootable clone on an external drive (e.g., USB drive or external SSD).
Step 1: Prepare the Target Drive
First, identify your target drive:
# List all drives
lsblk
# Example output:
# sda 953.9G disk (your main system)
# sdb 1.8T disk (your external drive)
# └─sdb1 1.8T part⚠️ WARNING: The following steps will ERASE all data on the target drive!
Unmount the target drive if mounted:
sudo umount /dev/sdb*Step 2: Partition the Target Drive
Create a GPT partition table with EFI and root partitions:
# Create partition table
sudo parted /dev/sdb mklabel gpt
# Create EFI partition (512MB)
sudo parted /dev/sdb mkpart primary fat32 1MiB 513MiB
sudo parted /dev/sdb set 1 boot on
sudo parted /dev/sdb set 1 esp on
# Create root partition (remaining space)
sudo parted /dev/sdb mkpart primary ext4 513MiB 100%Wait a moment for the kernel to recognize the partitions:
sleep 2Step 3: Format the Partitions
# Format EFI partition
sudo mkfs.vfat -F32 /dev/sdb1
# Format root partition
sudo mkfs.ext4 -F /dev/sdb2Step 4: Mount the Target Partitions
# Create mount point
sudo mkdir -p /mnt/backup
# Mount root partition
sudo mount /dev/sdb2 /mnt/backup
# Create and mount EFI directory
sudo mkdir -p /mnt/backup/boot/efi
sudo mount /dev/sdb1 /mnt/backup/boot/efiStep 5: Copy Your System with rsync
This is where the magic happens. The rsync command copies all your files while preserving permissions and attributes:
sudo rsync -aAXHv --sparse --info=progress2 \
--exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} \
/ /mnt/backup/Command breakdown:
-a: Archive mode (preserves permissions, timestamps, symlinks, etc.)-A: Preserve ACLs (Access Control Lists)-X: Preserve extended attributes-H: Preserve hard links-v: Verbose output--sparse: Handle sparse files efficiently--info=progress2: Show overall progress--exclude: Skip virtual filesystems and temporary directories
This will take 30-90 minutes depending on your system size and drive speed.
Step 6: Update fstab on the Backup
The backup needs its own UUID references:
# Get the UUIDs of your new partitions
BOOT_UUID=$(sudo blkid -s UUID -o value /dev/sdb1)
ROOT_UUID=$(sudo blkid -s UUID -o value /dev/sdb2)
# Create new fstab
sudo bash -c "cat > /mnt/backup/etc/fstab <<EOF
# Backup system fstab
UUID=$ROOT_UUID / ext4 defaults 0 1
UUID=$BOOT_UUID /boot/efi vfat umask=0077 0 1
EOF"Step 7: Install the Bootloader
Make the backup bootable by installing GRUB:
# Bind necessary directories
sudo mount --bind /dev /mnt/backup/dev
sudo mount --bind /proc /mnt/backup/proc
sudo mount --bind /sys /mnt/backup/sys
# Install GRUB
sudo chroot /mnt/backup grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ubuntu --recheck
# Update GRUB configuration
sudo chroot /mnt/backup update-grub
# Clean up
sudo umount /mnt/backup/dev
sudo umount /mnt/backup/proc
sudo umount /mnt/backup/sysStep 8: Unmount and Finish
sudo umount /mnt/backup/boot/efi
sudo umount /mnt/backup
sudo syncDone! Your external drive is now bootable. You can boot from it by selecting it in your BIOS/UEFI boot menu.
Option 2: Incremental Backup (Update Existing Backup)
If you already have a backup and want to update it with changes:
# Mount the existing backup
sudo mount /dev/sdb2 /mnt/backup
sudo mount /dev/sdb1 /mnt/backup/boot/efi
# Update with rsync (much faster - only copies changes)
sudo rsync -aAXHv --sparse --info=progress2 --delete \
--exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} \
/ /mnt/backup/
# Unmount
sudo umount /mnt/backup/boot/efi
sudo umount /mnt/backupThe --delete flag removes files from the backup that no longer exist on the source.
Option 3: Backup to Image File (Non-Bootable)
If you just want to save your files without making it bootable:
# Mount your target partition
sudo mount /dev/sdb1 /mnt
# Create backup directory
sudo mkdir -p /mnt/system-backup
# Rsync to directory
sudo rsync -aAXHv --sparse --info=progress2 \
--exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} \
/ /mnt/system-backup/
# Unmount
sudo umount /mntThis creates a directory with all your files that you can restore selectively.
Restoring from Backup
Full System Restore
If your main drive fails, you can either:
- Boot from the backup drive (if you used Option 1)
- Restore to a new drive:
# Mount new drive partitions
sudo mount /dev/sda2 /mnt/restore
sudo mount /dev/sda1 /mnt/restore/boot/efi
# Mount backup drive
sudo mount /dev/sdb2 /mnt/backup
sudo mount /dev/sdb1 /mnt/backup/boot/efi
# Restore
sudo rsync -aAXHv --info=progress2 \
/mnt/backup/ /mnt/restore/
# Reinstall bootloader on new drive
sudo mount --bind /dev /mnt/restore/dev
sudo mount --bind /proc /mnt/restore/proc
sudo mount --bind /sys /mnt/restore/sys
sudo chroot /mnt/restore grub-install /dev/sda
sudo chroot /mnt/restore update-grub
# Clean up
sudo umount /mnt/restore/dev
sudo umount /mnt/restore/proc
sudo umount /mnt/restore/sys
sudo umount /mnt/restore/boot/efi
sudo umount /mnt/restore
sudo umount /mnt/backup/boot/efi
sudo umount /mnt/backupRestore Individual Files
One advantage of rsync backups is you can restore individual files:
# Mount backup
sudo mount /dev/sdb2 /mnt/backup
# Browse and copy what you need
sudo cp /mnt/backup/home/user/important.txt /home/user/
# Unmount
sudo umount /mnt/backupAutomating Backups with a Script
Save this script as /usr/local/bin/backup-system:
#!/bin/bash
# Configuration
BACKUP_DEVICE="/dev/sdb2"
BACKUP_MOUNT="/mnt/backup"
LOG_FILE="/var/log/system-backup.log"
# Function to log messages
log() {
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOG_FILE"
}
# Check if running as root
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit 1
fi
log "Starting system backup..."
# Mount backup drive
mount "$BACKUP_DEVICE" "$BACKUP_MOUNT" || {
log "ERROR: Failed to mount backup drive"
exit 1
}
# Perform backup
rsync -aAXHv --sparse --info=progress2 --delete \
--exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} \
/ "$BACKUP_MOUNT/" 2>&1 | tee -a "$LOG_FILE"
# Check if backup succeeded
if [ ${PIPESTATUS[0]} -eq 0 ]; then
log "Backup completed successfully"
else
log "ERROR: Backup failed"
exit 1
fi
# Unmount
umount "$BACKUP_MOUNT"
log "Backup drive unmounted"
log "Backup process finished"Make it executable:
sudo chmod +x /usr/local/bin/backup-systemRun it manually:
sudo backup-systemOr schedule it with cron (weekly on Sundays at 2 AM):
sudo crontab -e
# Add this line:
0 2 * * 0 /usr/local/bin/backup-systemComparison: rsync vs dd
| Feature | rsync | dd |
|---|---|---|
| Works on running system | ✅ Excellent | ⚠️ Risky |
| Copies empty space | ❌ No (faster) | ✅ Yes (slower) |
| Bootable backup | ✅ Yes (with steps) | ✅ Yes (automatic) |
| Incremental updates | ✅ Yes (fast) | ❌ No |
| Browse files | ✅ Yes | ❌ No (binary image) |
| Restore individual files | ✅ Easy | ❌ Difficult |
| Handles sparse files | ✅ Yes | ⚠️ With conv=sparse |
| LVM support | ✅ Excellent | ⚠️ Limited |
| Complexity | Medium | Simple |
Tips and Best Practices
-
Test Your Backup: Boot from your backup drive at least once to verify it works
-
Regular Updates: Run incremental backups weekly or monthly
-
Multiple Backups: Keep at least 2 backups (3-2-1 rule: 3 copies, 2 different media, 1 offsite)
-
Document Your Setup: Save the commands you used in case you need to recreate the backup
-
Monitor Backup Size: Check that your backup drive has enough space:
df -h /mnt/backup -
Verify After Backup: Spot-check some files to ensure they copied correctly
-
Keep Important Data Separate: Don't rely solely on system backups for irreplaceable files (photos, documents)
Troubleshooting
"No space left on device"
Your target drive is too small. Check actual usage:
df -h /"Operation not permitted" Errors
Some files require special handling. The rsync command already handles most cases, but if you see errors, they're usually for /proc, /sys, or /dev which are excluded anyway.
Backup Won't Boot
- Check that you installed GRUB on the correct drive
- Verify
/etc/fstabhas correct UUIDs - Check BIOS/UEFI boot order
Rsync is Slow
- First backup is always slow (copies everything)
- Subsequent incremental backups are much faster
- USB 2.0 drives are slow - use USB 3.0 or faster
Final Thoughts
Using rsync to create bootable backups gives you flexibility and safety that dd cannot match. While it requires a few more steps than dd, the ability to update incrementally, restore individual files, and safely backup running systems makes it worth the extra effort.
The backup created using this method is a complete, bootable clone of your system that you can boot from if your main drive fails. Regular incremental updates keep it current with minimal time investment.
Remember: The best backup is the one you actually make and test!
Questions or suggestions? Leave a comment below!

Written by Robin te Hofstee
Technology enthusiast with a deep love for programming. Sharing practical guides on React, Next.js, Linux and self-hosting.
Related Posts
How to Clone Your System or Create a Backup Image in Linux Using `dd`
How to Clone Your System or Create a Backup Image in Linux Using `dd`.
Cron Jobs Cheatsheet
A concise reference for understanding and managing cron jobs, including syntax, special characters, common pitfalls, and troubleshooting tips.


