From 7a05467616beae0d9df326a5384543100f50950a Mon Sep 17 00:00:00 2001 From: simono41 Date: Thu, 21 Jun 2018 06:56:45 +0200 Subject: [PATCH] btrfs-snapshotboot --- arch-install | 3 +++ snapshot.sh | 43 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/arch-install b/arch-install index 256fee0..c377a54 100755 --- a/arch-install +++ b/arch-install @@ -472,6 +472,9 @@ function installation { fi + #forbtrfssnapshots + cp ${mountpoint}/etc/fstab ${mountpoint}/etc/fstab.example + diff --git a/snapshot.sh b/snapshot.sh index 692611d..cf0c38d 100755 --- a/snapshot.sh +++ b/snapshot.sh @@ -19,15 +19,52 @@ if [ "make" == "$1" ]; then echo `date "+%Y%m%d-%H%M%S"` > /run/btrfs-root/__current/${pfad}/SNAPSHOT echo "BACKUP" >> /run/btrfs-root/__current/${pfad}/SNAPSHOT - mkdir -p /run/btrfs-root/__snapshot/${pfad%/*} - btrfs subvolume snapshot -r /run/btrfs-root/__current/${pfad} /run/btrfs-root/__snapshot/${pfad}@`head -n 1 /run/btrfs-root/__current/${pfad}/SNAPSHOT` - rm /run/btrfs-root/__current/${pfad}/SNAPSHOT + #only root for the fstab + if [ "${pfad}" == "ROOT" ]; then + sed "s|__current/${pfad}|__snapshot/${pfad}@`head -n 1 /run/btrfs-root/__current/${pfad}/SNAPSHOT`|g;" /etc/fstab.example > /etc/fstab + rootsnapshot="y" + fi + + mkdir -p /run/btrfs-root/__snapshot/${pfad%/*} + btrfs subvolume snapshot /run/btrfs-root/__current/${pfad} /run/btrfs-root/__snapshot/${pfad}@`head -n 1 /run/btrfs-root/__current/${pfad}/SNAPSHOT` + #btrfs subvolume snapshot -r /run/btrfs-root/__current/${pfad} /run/btrfs-root/__snapshot/${pfad}@`head -n 1 /run/btrfs-root/__current/${pfad}/SNAPSHOT` + + if ! [ "${pfad}" == "ROOT" ]; then + rm /run/btrfs-root/__current/${pfad}/SNAPSHOT + fi shift done + #reset-fstab + if [ "${rootsnapshot}" == "y" ]; then + cp /etc/fstab.example /etc/fstab + fi + + #stable-snapshot-boot + if [ -f "/boot/arch-uefi.conf.example" ]; then + + cp /boot/initramfs-*.img /boot/initramfs-linux-stable.img + cp /boot/vmlinuz /boot/vmlinuz-stable + + kernel1="$(echo $(find /boot/ -name "initramfs*-stable.img") | cut -d" " -f2)" + linuz1="$(find /boot/ -name "vmlinuz*-stable")" + kernel="${kernel1#/*/}" + linuz="${linuz1#/*/}" + +sed "s|%LINUZ%|${linuz}|g; +s|%KERNEL%|${kernel}|g; +s|rootflags=subvol=__current/ROOT|rootflags=subvol=__snapshot/${pfad}@`head -n 1 /run/btrfs-root/__current/${pfad}/SNAPSHOT`" /boot/arch-uefi.conf.example > /boot/loader/entries/arch-uefi-stable.conf + + if [ -f /run/btrfs-root/__current/ROOT/SNAPSHOT ]; then + rm /run/btrfs-root/__current/ROOT/SNAPSHOT + fi + + + fi + elif [ "restore" == "$1" ]; then while (( "$(expr $# - 1)" ))