Skip to content

Instantly share code, notes, and snippets.

@ipha
Last active June 18, 2019 01:36
Show Gist options
  • Save ipha/41ad883bf4f51a4c8ae388794a7e1ed7 to your computer and use it in GitHub Desktop.
Save ipha/41ad883bf4f51a4c8ae388794a7e1ed7 to your computer and use it in GitHub Desktop.
title Arch Linux (last)
linux /vmlinuz-linux-last
initrd /intel-ucode.img
initrd /initramfs-linux-last-fallback.img
options root=LABEL=archRoot rootflags=subvol=root-last rw
#!/bin/bash
blue='\e[0;34m'
red='\e[0;31m'
NC='\e[0m'
BTRFS_ROOT="/mnt/btrfs"
NUM_TO_KEEP=7
new_name=$(date +root_%Y-%m-%d_%T)
echo -e "${blue}Taking rw 'last' snapshot of root:${NC}"
btrfs subvolume snapshot ${BTRFS_ROOT}/root ${BTRFS_ROOT}/root-last-new
btrfs subvolume delete ${BTRFS_ROOT}/root-last
mv ${BTRFS_ROOT}/root-last-new ${BTRFS_ROOT}/root-last
cp /boot/vmlinuz-linux /boot/vmlinuz-linux-last
cp /boot/initramfs-linux-fallback.img /boot/initramfs-linux-last-fallback.img
sed -i 's|subvol=root|subvol=root-last|' ${BTRFS_ROOT}/root-last/etc/fstab
echo -e "${blue}Taking ro snapshot of root: ${new_name}${NC}"
btrfs subvolume snapshot -r ${BTRFS_ROOT}/root ${BTRFS_ROOT}/${new_name}
echo -e "${blue}Removing old snapshots${NC}"
for snapshot in $(ls ${BTRFS_ROOT} | grep root_ | sort | head -n -"${NUM_TO_KEEP}"); do
echo -e "Removing ${snapshot}"
btrfs subvolume delete ${BTRFS_ROOT}/${snapshot}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment