From fdca1c0926e4913f2f9d20cb2b9abd1d5a6d9fbd Mon Sep 17 00:00:00 2001 From: Willi Mutschler Date: Mon, 4 May 2020 12:23:51 +0200 Subject: [PATCH] Added grub-btrfs support --- README.md | 27 +++++++++++++++++++++++---- timeshift-autosnap-apt | 4 ++++ timeshift-autosnap-apt.conf | 5 +++++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 69d031a..4383ac2 100644 --- a/README.md +++ b/README.md @@ -9,16 +9,24 @@ Timeshift auto-snapshot script which runs before `apt upgrade|install|remove` us * Can be manually executed by running `sudo timeshift-autosnap-apt` command. * Autosnaphot can be temporarily skipped by setting SKIP_AUTOSNAP environment variable (e.g. `sudo SKIP_AUTOSNAP= apt upgrade`) * Supports both `BTRFS` and `RSYNC` mode. +* Supports [grub-btrfs](https://github.com/Antynea/grub-btrfs) which automatically creates boot menu entries of your snapshots into grub. * For a tutorial how to use this script in production to easily rollback your system, see [Pop!_OS 20.04 btrfs-luks disaster recovery and easy system rollback using Timeshift and timeshift-autosnap-apt](https://mutschler.eu/linux/install-guides/pop-os-btrfs-recovery/). ## Installation -If you haven't, first install Timeshift: +#### Install dependencies +```bash +sudo apt install git make +``` +Note that make is only needed for `grub-btrfs`. + +#### Install and configure Timeshift ```bash sudo apt install timeshift ``` Open Timeshift and configure it either using btrfs or rsync. I recommend using btrfs as a filesystem for this, see my [btrfs installation guides](https://mutschler.eu/linux/install-guides/) for Pop!_OS, Ubuntu, and Manjaro. -Clone the repository and run the following commands to copy the hook, bash script and configuration file. +#### Main installation +Clone this repository and run the following commands to copy the hook, bash script and configuration file. ```bash git clone https://github.com/wmutschl/timeshift-autosnap-apt.git cd timeshift-autosnap-apt @@ -35,13 +43,24 @@ sudo nano /etc/timeshift-autosnap-apt.conf ``` For example, if you don't have a dedicated `/boot` partition, then you should set `snapshotBoot=false`. -## Configuration +#### Optionally, install `grub-btrfs` +[grub-btrfs](https://github.com/Antynea/grub-btrfs) is a great package which will include all btrfs snapshots into the Grub menu +This +```bash +git clone https://github.com/Antynea/grub-btrfs.git +cd grub-btrfs +sudo make install +``` +By default the snapshots are displayed as "Arch Linux Snapshots", you can adapt this in `/etc/default/grub-btrfs/config`. + +#### Configuration The configuration file is located in `/etc/timeshift-autosnap-apt.conf`. You can set the following options: * `snapshotBoot`: If set to **true** /boot folder will be cloned into /boot.backup before the call to timeshift. Note that this will not include the /boot/efi folder. Default: **true** * `snapshotEFI`: If set to **true** /boot/efi folder will be cloned into /boot.backup/efi before the call to timeshift. Default: **true** * `skipAutosnap`: If set to **true** script won't be executed. Default: **false**. * `deleteSnapshots`: If set to **false** old snapshots won't be deleted. Default: **true** * `maxSnapshots`: Defines **maximum** number of old snapshots to keep. Default: **3** +* `updateGrub`: If set to **false** grub entries won't be generated. Default: **true** * `snapshotDescription` Defines **value** used to distinguish snapshots created using timeshift-autosnap-apt. Default: **{timeshift-autosnap-apt} {created before call to APT}** ## Test functionality @@ -145,7 +164,7 @@ or for RSYNC: ## Ideas and contributions - [x] Ask to be included into official Timeshift package, [status pending](https://github.com/teejee2008/timeshift/issues/595). - [x] Copy /boot and /boot/efi to filesystem for better control option when restoring (tested on Pop!_OS) -- [ ] Check and adapt [grub-btrfs](https://github.com/Antynea/grub-btrfs) for compatibility with Debian-based systems and this script (test on Ubuntu) to automatically create menu entries into grub. +- [x] Check and adapt [grub-btrfs](https://github.com/Antynea/grub-btrfs) for compatibility with Debian-based systems and this script (test on Ubuntu) to automatically create menu entries into grub. **All new ideas and contributors are welcomed, just open an issue for that!** diff --git a/timeshift-autosnap-apt b/timeshift-autosnap-apt index e974681..594dab5 100755 --- a/timeshift-autosnap-apt +++ b/timeshift-autosnap-apt @@ -69,4 +69,8 @@ if $(get_property "deleteSnapshots" "boolean" "true") ; then fi fi; +if $(get_property "updateGrub" "boolean" "true") && [[ -d /etc/default/grub-btrfs ]]; then + grub-mkconfig -o /boot/grub/grub.cfg +fi; + exit 0 \ No newline at end of file diff --git a/timeshift-autosnap-apt.conf b/timeshift-autosnap-apt.conf index 2e083c5..343426d 100644 --- a/timeshift-autosnap-apt.conf +++ b/timeshift-autosnap-apt.conf @@ -23,6 +23,11 @@ deleteSnapshots=true # Default value is 3. maxSnapshots=3 +# updateGrub defines if grub entries should be auto-generated. +# If grub-btrfs package is not installed grub won't be generated. +# Default value is true. +updateGrub=true + # snapshotDescription defines value used to distinguish snapshots created using timeshift-autosnap # Default value is "{timeshift-autosnap} {created before upgrade}". snapshotDescription={timeshift-autosnap-apt} {created before call to APT} \ No newline at end of file