Code Monkey home page Code Monkey logo

manjaro-btrfs's Introduction

Btrfs snapshots with snapper, with easy rollback

These scripts can be used to automate some tasks to setup a complete manjaro system. It may be compatible with manjaro32, but not fully tested.

With btrfs filesystem, we can set up a system with snapshots. With snapper and grub, we can rollback to a previous state, if anything goes wrong after a package install, or system update or anything else.

The main goal is to get a system up and running on btrfs and snapper to make the easy rollback possible. Additional benefit is to get my favorite default software installed :)

The main difference to timeshift, is that you can directly boot into an earlier state of the system in read-only mode, and restore that state.

You can find the video from Nick (unicks.eu) below which inspired me to write these scripts. https://www.youtube.com/watch?v=-fT92-jGniI

When and how to use these scripts?

The scripts designed to run (partially) as a part of the manjaro installation process. Once the installer finished you can execute the first script right from the point when the installer finished but before the system restarted. See more detailed info below.

The basic precondition for the installation is to create a btrfs root, and a swap partition from the installer.

Please note: By default the installer will create only the /home subvolume. These scripts will do additional things to set up a complete btrfs system, prepared for an easy rollback.

Basic flow to run the scripts

Setup:

  1. install/manjaro_setup_btrfs_01_after_install_before_restart.sh
  2. install/manjaro_setup_btrfs_02_after_install_after_restart.sh

Rollback:

  1. btrfs_snapper_do_rollback.sh

You can find the list of scripts in the table below for completeness

Filename Description
install/manjaro_setup_btrfs_01_after_install_before_restart.sh Main script
install/manjaro_setup_btrfs_02_after_install_after_restart.sh Continuation script after restart
install/usr/btrfs_grub_install_chroot.sh This is a technical script called by another script, therefore you should not run it by hand. It will update and re-install grub. This script should be run in the chroot to the default subvolume.
install/usr/btrfs_ro_alert.sh Alert after boot if the btrfs filesystem is read only, and give the command to do the rollback. This script will be installed automatically.
install/usr/btrfs_snapper_do_rollback.sh This script will do a snapper rollback, and then update and re-install grub to use the proper snapshot at boot.
install/script/20-password-timeout-0-ppid-60min This is a setting file for sudo, and will be placed to /etc/sudoers.d/ to increase sudo timeout. If you uncomment the line #Defaults timestamp_type="global", you will have to give your password for sudo only once in one terminal for one hour.
install/script/stage_2_setup.sh Basic system setup, typically executed after an install. Executed by install/manjaro_setup_btrfs_02_after_install_after_restart.sh
install/script/fix_catfish.sh This is the fix for catfish, to resolve the conflict with zeitgeist, see https://bugzilla.xfce.org/show_bug.cgi?id=16419, Executed by install/script/stage_2_setup.sh
manjaro_setup_custom.sh Some custom installations, settings
manjaro_setup_developer.sh Some development related installations, settings
manjaro_setup_encrypted_home.sh Encrypt the home directory for a selected user
manjaro_setup_keyfix.sh Refresh the package signing keys
manjaro_setup_kids.sh Install some games and educational package for the kids
manjaro_setup_lang_hu.sh Install hungarian language packages for some program
manjaro_setup_virtualbox.sh Install the necessary packages for a virtualbox client
xfce/manjaro_setup_xfce.sh Install some xfce related package like dockarx and panel, and some panel applets
xfce/manjaro_setup_xfce_desktop.sh This script will apply some modifications like add dockbarx dock, add some indicators to the panel, etc. It will use the file xfce/xfce_skeleton.tar.bz2
xfce/xfce_skeleton.tar.bz2 This file contains an xfce session with basic settings like dockarx, other than default theme set, additional panel applets, etc.

1. install/manjaro_setup_btrfs_01_after_install_before_restart.sh

When the installer finished, do not restart the system yet! Run this script, right after the installer: install/manjaro_setup_btrfs_01_after_install_before_restart.sh.

It will do the following:

  • if more than one partitions found with btrfs filesystem, prompt to choose the target
  • set the default subvolume
  • create subvolume /var to be able to boot into a read-only snapshot
  • create subvolume on /usr/local
  • move the pacman database to /usr/var/pacman to always reflect the state of the snapshot
  • install 20-password-timeout-0-ppid-60min

Creating the /var subvolume will greatly reduce the size of the snapshots, and give the ability to boot a read only snapshot, to do the rollback from there.

After this script has finished, restart the system.

2. after the first start

When you boot into the newly installed system: Before doing anything else, run the script install/manjaro_setup_btrfs_02_after_install_after_restart.sh.

It will do the following:

  • call script/stage_2_setup.sh
    • sync system time
    • try to set up the fastest mirror
    • do a full update, and install some necessary tools, like rsync, lsof ...
    • change login greeter to slick-greeter
    • on 64bit systems, install the kernel bootsplash
    • set up multi thread compression
    • disable speaker
    • enable AUR
    • fix the "sparse file not allowed" error message on startup
    • create snapper config
    • move snapshots to a separate subvolume
    • skip snapshots from updatedb
    • install some btrfs related package to be able to create snapshots on package install, and to list snapshots in grub menu
    • copy some scripts to /usr/local/bin. One of them will alert after boot if the btrfs filesystem is a read only snapshot, and give the command to do the rollback
  • install snap-pac-grub from AUR

rollback to a previous state

If you want to go back to a previous state of the system, you must reboot, and select the snapshot from the grub menu (under 'Select snapshot') to boot into. After you login, a window will warn you, that this is a read only snapshot. It also give you the command to do the rollback. After you are sure that you want to rollback to that state, you should run: sudo btrfs_snapper_do_rollback.sh from the terminal, as this script is installed on the system already.

read only check, rollback command help

After the reboot, you will get back the selected state of your system, like a time travel.

Note: The user's /home partition is not contained in the snapshot.

encrypted home

Because you can only create encrypted home for another not logged in user, you must create a separate user to set up the encrypted home for.

The manjaro_setup_encrypted_home.sh script will set the ecryptfs pam moduls, and encrypt the home dir if the user has no running processes (not logged in).

Follow the original instructions from the encryption output at the end of the process: the target user should test if he/she can log in before the restart.

After setting encrypted home(s), a restart is advised.

xfce desktop modifications

You should run this script for a user, that is not logged in currently.

First run the script xfce/manjaro_setup_xfce.sh to install some xfce related package.

The script xfce/manjaro_setup_xfce_desktop.sh will appy some modifications like add dockbarx dock, add some indicators to the panel, etc, for the selected user.

  • set theme to wallis
  • add dockbarx and set its theme to colors/dmd glass
  • add places and screenshot plugin to the panel
  • set default filemanager to caja
  • pin caja, firefox, catfish to dockbarx
  • set panel size to 42
  • modify energy management
  • set clock format to %a %d %b, %R:%S
  • set gimp theme
  • add synapse to autostart

These are the exact steps:

  • create new user
  • log in with the new user
  • restart
  • run xfce/manjaro_setup_xfce_desktop.sh choosing the new user

fix key problem during package update

Rarely required, but if there are package key problems at update time, the script manjaro_setup_keyfix.sh will refresh the package signing keys.

If we get a key error during an update, we can try to fix it, with this script.

other scripts

The rest of the scripts are self-explanatory, and commented. Feel free to explore, or tailor them to your needs.

For example, if you want to test these scripts in virtualbox, use can use the manjaro_setup_virtualbox.sh script to install the necessary packages for a virtualbox client.

executing the scripts from gui

The scripts can be executed also from gui: set the script as executable exetute with terminal execute

Disclaimer

You should test the scripts before creating a new live system with them. You can also modify them freely to your needs.

Always have backup!

manjaro-btrfs's People

Contributors

avaraljai avatar hrotkogabor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

manjaro-btrfs's Issues

Rolling back snapshot prints grub-install: error: cannot find EFI directory.

Hi,

I've been testing these wonderful scripts on a manjaro 21.0 gnome in a virtualbox and came upon this error when restoring snapshot with sudo btrfs_snapper_do_rollback.sh

sudo btrfs_snapper_do_rollback.sh
[sudo] password for nightliss: 
calling snapper rollback
Ambit is classic.
Creating read-only snapshot of default subvolume. (Snapshot 13.)
Creating read-write snapshot of current subvolume. (Snapshot 14.)
Setting default subvolume to snapshot 14.
updating and re-installing grub
Using /dev/sda3, and /dev/sda as parent.
mkdir: cannot create directory '/root/.config/manjaro-tools': Read-only file system
mkdir: cannot create directory '/root/.config/manjaro-tools': Read-only file system
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.10-x86_64
Found initrd image: /boot/intel-ucode.img /boot/initramfs-5.10-x86_64.img
Found initrd fallback image: /boot/initramfs-5.10-x86_64-fallback.img
Warning: os-prober will be executed to detect other bootable partitions.
It's output will be used to detect bootable binaries on them and create new boot entries.
mkdir: cannot create directory ‘/var/lib/os-prober/mount’: No such file or directory
mkdir: cannot create directory ‘/var/lib/os-prober/mount’: No such file or directory
mkdir: cannot create directory ‘/var/lib/os-prober/mount’: No such file or directory
Adding boot menu entry for UEFI Firmware Settings ...
Detecting snapshots ...
Info: Separate boot partition not detected 
Info: snapper detected, using config 'root'
Found snapshot: 2021-04-02 10:57:13 | @.snapshots/14/snapshot | single | writable copy of #5
Found snapshot: 2021-04-02 10:57:13 | @.snapshots/13/snapshot | single | rollback backup of #12
Found snapshot: 2021-04-02 10:29:57 | @.snapshots/12/snapshot | single | writable copy of #5
Found snapshot: 2021-04-02 10:29:57 | @.snapshots/11/snapshot | single | rollback backup of #10
Found snapshot: 2021-04-02 10:24:23 | @.snapshots/10/snapshot | single | writable copy of #5
Found snapshot: 2021-04-02 10:24:23 | @.snapshots/9/snapshot  | single | rollback backup of #8
Found snapshot: 2021-04-02 10:22:24 | @.snapshots/8/snapshot  | single | writable copy of #5
Found snapshot: 2021-04-02 10:22:24 | @.snapshots/7/snapshot  | single | rollback backup
Found snapshot: 2021-04-02 10:18:49 | @.snapshots/6/snapshot  | post   | micro wl-clipboard
Found snapshot: 2021-04-02 10:18:49 | @.snapshots/5/snapshot  | pre    | /usr/bin/pamac-daemon
Found snapshot: 2021-04-02 10:18:28 | @.snapshots/4/snapshot  | post   | firefox gnome-shell-extension-arcmenu gnome-shell-extension-dash-to-dock...
Found snapshot: 2021-04-02 10:18:25 | @.snapshots/3/snapshot  | pre    | /usr/bin/pamac-daemon
Found snapshot: 2021-04-02 09:46:00 | @.snapshots/2/snapshot  | post   | snap-pac-grub
Found snapshot: 2021-04-02 09:46:00 | @.snapshots/1/snapshot  | pre    | pacman -U --noconfirm --config /etc/pacman.conf -- /home/nightliss/.cach...
Found 14 snapshot(s)
Found memtest86+ image: /boot/memtest86+/memtest.bin
done
Installing for x86_64-efi platform.
grub-install: error: cannot find EFI directory.

after trial and error I realized that grub cannot find efi directory because it's not mounted.

outside chroot

mount | grep /boot/efi
/dev/sda1 on /boot/efi type vfat (rw,relatime,fmask=0077,dmask=0077.,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro)

I don't see anything in the script which would mount boot partition.

I have followed the guide from the video link in the readme.

sudo parted -l
[sudo] password for nightliss: 
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 21,5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system     Name  Flags
 1      1049kB  538MB   537MB   fat32                 boot, esp
 2      538MB   2685MB  2147MB  linux-swap(v1)        swap
 3      2685MB  21,5GB  18,8GB  btrfs

Does the script assumes there is only root partition with boot or is this a bug?

Gnome support

This looks cool! I would consider using if it had a gnome mode that doesn’t install xfce stuff.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.