Skip to content

Instantly share code, notes, and snippets.

@harilvfs
Last active September 19, 2025 21:41
Show Gist options
  • Save harilvfs/d8f1584206417482b6f6f9928d9af030 to your computer and use it in GitHub Desktop.
Save harilvfs/d8f1584206417482b6f6f9928d9af030 to your computer and use it in GitHub Desktop.
Timeshift GRUB Boot Integration for EXT4 & BTRFS with Legacy BIOS/MBR and UUID Support

Timeshift GRUB Boot Integration (EXT4 & BTRFS)

This guide will show you how to:

  • Create and manage Timeshift snapshots
  • Boot into the latest Timeshift snapshot from GRUB
  • Automatically update the GRUB menu with new snapshots
  • Set up Timeshift for both EXT4 (rsync) and BTRFS
  • Use both blkid and non-blkid (Legacy BIOS/MBR) methods

๐Ÿ› ๏ธ 1. Installing Timeshift

Timeshift is a backup tool for Linux that supports rsync (EXT4) and BTRFS snapshots.

# Install Timeshift on Arch-based systems
sudo pacman -S timeshift
# Install Timeshift on Debian/Ubuntu
sudo apt install timeshift -y
# Install Timeshift on Fedora
sudo dnf install timeshift -y

๐Ÿ“ธ 2. Creating a Timeshift Snapshot

To create a snapshot manually:

sudo timeshift --create --comments "Backup before update" --tags O

To list available snapshots:

sudo timeshift --list

Example output:

Device : /dev/sda3
Snapshots:
  Num   Name                 Tags  Date
  ------------------------------------------
  0     2025-02-11_23-33-09  O     2025-02-11

โš™๏ธ 3. Adding Timeshift to GRUB (EXT4 - Rsync)

๐Ÿ› ๏ธ Step 1: Find Your Snapshot Path

Find the latest snapshot:

ls -1t /timeshift/snapshots | head -n 1

Example path:

/timeshift/snapshots/2025-02-11_23-33-09/localhost/boot

๐Ÿ”„ 4. Automate GRUB Entry for Latest Snapshot

โœ… For Systems with blkid (Recommended)

Create /usr/local/bin/update-grub-timeshift.sh:

sudo vim /usr/local/bin/update-grub-timeshift.sh

Paste:

#!/bin/bash

SNAPSHOT_DIR="/timeshift/snapshots"
LATEST_SNAPSHOT=$(ls -1t "$SNAPSHOT_DIR" | head -n 1)

if [ -z "$LATEST_SNAPSHOT" ]; then
    echo "No Timeshift snapshots found!"
    exit 1
fi

BOOT_PATH="$SNAPSHOT_DIR/$LATEST_SNAPSHOT/localhost/boot"

if [ ! -f "$BOOT_PATH/vmlinuz-linux" ] || [ ! -f "$BOOT_PATH/initramfs-linux.img" ]; then
    echo "Kernel or initramfs missing!"
    exit 1
fi

ROOT_UUID=$(blkid -s UUID -o value /dev/sda3)

GRUB_CUSTOM="/etc/grub.d/40_custom"

cat <<EOF > "$GRUB_CUSTOM"
menuentry "Timeshift Recovery (Latest: $LATEST_SNAPSHOT)" {
    set root=(hd0,3)
    linux $BOOT_PATH/vmlinuz-linux root=UUID=$ROOT_UUID rw
    initrd $BOOT_PATH/initramfs-linux.img
}
EOF

grub-mkconfig -o /boot/grub/grub.cfg

Make executable:

sudo chmod +x /usr/local/bin/update-grub-timeshift.sh

Run manually:

sudo /usr/local/bin/update-grub-timeshift.sh

โœ… For Legacy BIOS/MBR Systems (Non-blkid Method)

This script avoids using UUIDs and directly refers to the disk device.

Edit the 40_custom file for Legacy BIOS:

menuentry "Timeshift Recovery (Latest: $LATEST_SNAPSHOT)" {
    set root=(hd0,msdos3)    # Adjust 'msdos3' based on your partition
    linux /timeshift/snapshots/2025-02-11_23-33-09/localhost/boot/vmlinuz-linux root=/dev/sda3 rw
    initrd /timeshift/snapshots/2025-02-11_23-33-09/localhost/boot/initramfs-linux.img
}

Important

In the Legacy BIOS (MBR) setup, you use /dev/sda3 directly for root= instead of the UUID.

After editing, save and update GRUB:

sudo grub-mkconfig -o /boot/grub/grub.cfg

Create /usr/local/bin/update-grub-timeshift-legacy.sh:

sudo vim /usr/local/bin/update-grub-timeshift-legacy.sh

Paste:

#!/bin/bash

SNAPSHOT_DIR="/timeshift/snapshots"
LATEST_SNAPSHOT=$(ls -1t "$SNAPSHOT_DIR" | head -n 1)

if [ -z "$LATEST_SNAPSHOT" ]; then
    echo "No Timeshift snapshots found!"
    exit 1
fi

BOOT_PATH="$SNAPSHOT_DIR/$LATEST_SNAPSHOT/localhost/boot"

if [ ! -f "$BOOT_PATH/vmlinuz-linux" ] || [ ! -f "$BOOT_PATH/initramfs-linux.img" ]; then
    echo "Kernel or initramfs missing!"
    exit 1
fi

GRUB_CUSTOM="/etc/grub.d/40_custom"

cat <<EOF > "$GRUB_CUSTOM"
menuentry "Timeshift Recovery (Latest: $LATEST_SNAPSHOT)" {
    set root=(hd0,msdos3)
    linux $BOOT_PATH/vmlinuz-linux root=/dev/sda3 rw
    initrd $BOOT_PATH/initramfs-linux.img
}
EOF

grub-mkconfig -o /boot/grub/grub.cfg

Make executable:

sudo chmod +x /usr/local/bin/update-grub-timeshift-legacy.sh

Run manually:

sudo /usr/local/bin/update-grub-timeshift-legacy.sh

Important

Use root=/dev/sdX instead of UUID if you have a legacy MBR system.


๐Ÿ•’ 5. Automate via Systemd Timer

Create /etc/systemd/system/update-grub-timeshift.service:

sudo vim /etc/systemd/system/update-grub-timeshift.service

Paste:

[Unit]
Description=Update GRUB with latest Timeshift snapshot
After=timeshift.service

[Service]
ExecStart=/usr/local/bin/update-grub-timeshift.sh
Type=oneshot

Create /etc/systemd/system/update-grub-timeshift.timer:

sudo nano /etc/systemd/system/update-grub-timeshift.timer

Paste:

[Unit]
Description=Run GRUB update when Timeshift snapshot changes

[Timer]
OnCalendar=hourly
Persistent=true

[Install]
WantedBy=timers.target

Enable:

sudo systemctl daemon-reload
sudo systemctl enable --now update-grub-timeshift.timer

๐Ÿ–ฅ๏ธ 6. Adding Timeshift to GRUB (BTRFS)

Important

BTRFS snapshots use subvolumes instead of regular directories.

Find the default subvolume:

sudo btrfs subvolume list /

To boot into a snapshot, use:

menuentry "Timeshift BTRFS Recovery" {
    set root=(hd0,3)
    linux /@/boot/vmlinuz-linux root=UUID=<your-btrfs-uuid> rw rootflags=subvol=@
    initrd /@/boot/initramfs-linux.img
}

Replace <your-btrfs-uuid> with:

blkid -s UUID -o value /dev/sda3

Update GRUB:

sudo grub-mkconfig -o /boot/grub/grub.cfg

Caution

I do not recommend using the auto script if you are not familiar with shell scripting. It is safer to edit the GRUB configuration manually if you're unsure. This way, you can carefully check each step and avoid mistakes that could make your system unbootable.

For UUID (Standard Method)

Edit the 40_custom file for your UUID-based entry:

sudo vim /etc/grub.d/40_custom

Add:

menuentry "Timeshift Recovery (Latest: $LATEST_SNAPSHOT)" {
    set root=(hd0,3)
    linux /timeshift/snapshots/2025-02-11_23-33-09/localhost/boot/vmlinuz-linux root=UUID=12345678-90ab-cdef-1234-567890abcdef rw
    initrd /timeshift/snapshots/2025-02-11_23-33-09/localhost/boot/initramfs-linux.img
}

Replace 12345678-90ab-cdef-1234-567890abcdef with the UUID of your root partition, which can be found with the blkid command.

Then, update GRUB:

sudo grub-mkconfig -o /boot/grub/grub.cfg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment