summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlad2015-07-08 15:37:49 +0300
committervlad2015-07-08 15:37:49 +0300
commitf02556f7631bdad1bb1f85ce36d8e44163600526 (patch)
tree04c88212698cc9df3ff81dc82e9b91fdf68fd5f8
downloadaur-f02556f7631bdad1bb1f85ce36d8e44163600526.tar.gz
Initial import
-rw-r--r--.AURINFO18
-rw-r--r--.SRCINFO21
-rw-r--r--PKGBUILD24
-rw-r--r--btrfs_config50
-rw-r--r--btrfs_hook379
-rw-r--r--btrfs_install26
-rw-r--r--mkinitcpio-btrfs.install74
7 files changed, 592 insertions, 0 deletions
diff --git a/.AURINFO b/.AURINFO
new file mode 100644
index 000000000000..43da59874d3a
--- /dev/null
+++ b/.AURINFO
@@ -0,0 +1,18 @@
+pkgbase = mkinitcpio-btrfs
+ pkgdesc = mkinitcpio hook containing advanced features for btrfs-based root devices
+ pkgver = 0.4.3
+ pkgrel = 1
+ url = https://github.com/xtfxme/mkinitcpio-btrfs
+ install = mkinitcpio-btrfs.install
+ arch = any
+ license = BSD
+ depends = mkinitcpio>=0.9.0
+ depends = btrfs-progs
+ depends = kexec-tools
+ source = btrfs_hook
+ source = btrfs_install
+ source = btrfs_config
+ backup = etc/default/btrfs_advanced
+
+pkgname = mkinitcpio-btrfs
+
diff --git a/.SRCINFO b/.SRCINFO
new file mode 100644
index 000000000000..68deab4e463e
--- /dev/null
+++ b/.SRCINFO
@@ -0,0 +1,21 @@
+pkgbase = mkinitcpio-btrfs
+ pkgdesc = mkinitcpio hook containing advanced features for btrfs-based root devices
+ pkgver = 0.4.3
+ pkgrel = 1
+ url = https://github.com/xtfxme/mkinitcpio-btrfs
+ install = mkinitcpio-btrfs.install
+ arch = any
+ license = BSD
+ depends = mkinitcpio>=0.9.0
+ depends = btrfs-progs
+ depends = kexec-tools
+ backup = etc/default/btrfs_advanced
+ source = btrfs_hook
+ source = btrfs_install
+ source = btrfs_config
+ md5sums = 0e2b0a9bebfca0ebc2145cc6b2c0de76
+ md5sums = dc4bf193c9581625a5623d26f6096183
+ md5sums = 73806b834c9fa8a8bb39d0201c63f21a
+
+pkgname = mkinitcpio-btrfs
+
diff --git a/PKGBUILD b/PKGBUILD
new file mode 100644
index 000000000000..fdbb201f3fa3
--- /dev/null
+++ b/PKGBUILD
@@ -0,0 +1,24 @@
+# Maintainer: C Anthony Risinger
+# Contributor: Michael Goehler
+# Contributor: Dave Reisner
+pkgname='mkinitcpio-btrfs'
+pkgver=0.4.3
+pkgrel=1
+pkgdesc='mkinitcpio hook containing advanced features for btrfs-based root devices'
+url='https://github.com/xtfxme/mkinitcpio-btrfs'
+arch=('any')
+license=('BSD')
+install="${pkgname}.install"
+depends=('mkinitcpio>=0.9.0' 'btrfs-progs' 'kexec-tools')
+backup=('etc/default/btrfs_advanced')
+source=('btrfs_hook' 'btrfs_install' 'btrfs_config')
+
+package() {
+ install -o root -g root -D ${srcdir}/btrfs_install ${pkgdir}/usr/lib/initcpio/install/btrfs_advanced
+ install -o root -g root -D ${srcdir}/btrfs_hook ${pkgdir}/usr/lib/initcpio/hooks/btrfs_advanced
+ install -o root -g root -D ${srcdir}/btrfs_config ${pkgdir}/etc/default/btrfs_advanced
+}
+
+md5sums=('0e2b0a9bebfca0ebc2145cc6b2c0de76'
+ 'dc4bf193c9581625a5623d26f6096183'
+ '73806b834c9fa8a8bb39d0201c63f21a')
diff --git a/btrfs_config b/btrfs_config
new file mode 100644
index 000000000000..5a4d3577c9a2
--- /dev/null
+++ b/btrfs_config
@@ -0,0 +1,50 @@
+# This file contains some information for the btrfs_advanced initcpio hook.
+
+# Define the default subvolume for our root filesystem.
+BTRFS_DIR_ACTIVE="/__active"
+
+# Define the folder containing snapshots of our root filesystem.
+BTRFS_DIR_SNAPSHOT="/__snapshot"
+
+# Define the subvolume used for rollback operations.
+#
+# This subvolume is temporary and gets deleted each time a restore is
+# triggered. To make it permanent create a snapshot to BTRFS_DIR_ACTIVE.
+BTRFS_DIR_ROLLBACK="/__rollback"
+
+# Define if we have to do kernel rollbacks (enabled by default).
+#
+# In setup with a separate /boot partiton this must be enabled to prevent
+# this hook from searching for the kernel on your btrfs root.
+#BTRFS_ROLLBACK_KERNEL=false
+
+# If you use a custom kernel, specify its name and location below.
+#
+# Currently the kernel must be part on your root volume, as we don't mount
+# anything else in early boot stage.
+#BTRFS_KERNEL="/boot/vmlinuz-linux"
+#BTRFS_INITRD="/boot/initramfs-linux.img"
+
+# It is possible to move and replace BTRFS_DIR_ACTIVE with an older snapshot
+# while it is mounted and reboot afterwards. If you prefer to rollback like
+# this, you can optionally disable the on-boot rollback dialog. This will
+# improve your boot speed by > 3 seconds.
+#BTRFS_ROLLBACK_DIALOG=false
+
+# By default we reload the kernel image from the chosen boot root subvolume
+# only if the version and build-number/date differs from `uname -rv`.
+#
+# If you want to reload the kernel on every boot, you can disable this check.
+#BTRFS_KVER_CHECK=false
+
+# Try to mount RAID setups, when there are devices missing.
+#
+# This is usualy wanted on productive setups, because btrfs supports to
+# replace faulty drives online.
+#
+# ATTENTION: If you enable this, you need to make sure to rebalance the btrfs
+# RAID after system upgrade. Otherwise kernal panic is possible by unbalanced
+# libraries.
+#BTRFS_ENABLE_DEGRADED=true
+
+# vim:set syntax=sh:
diff --git a/btrfs_hook b/btrfs_hook
new file mode 100644
index 000000000000..3d0e97c9e2a3
--- /dev/null
+++ b/btrfs_hook
@@ -0,0 +1,379 @@
+#!/bin/ash
+# BTRFS repair/bootstrap initramfs hook
+#
+# Copyright (c) 2010-2012, C Anthony Risinger
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice, this
+# list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# hook name
+: ${BTRFS_HOOK_NAME:="btrfs_advanced"}
+
+# output handlers
+btrfs_info () { [ "${quiet}" != "y" ] && echo ":: ${BTRFS_HOOK_NAME} [INFO]: ${@}"; }
+btrfs_warn () { echo ":: ${BTRFS_HOOK_NAME} [WARN]: ${@}"; }
+btrfs_error () { echo ":: ${BTRFS_HOOK_NAME} [ERROR]: ${@}"; }
+btrfs_fatal () { echo ":: ${BTRFS_HOOK_NAME} [FATAL]: ${@}"; break=y; }
+
+# source config
+if [ -f /etc/default/btrfs_advanced ]; then
+ . /etc/default/btrfs_advanced
+ btrfs_info "Configuration file /etc/default/btrfs_advanced loaded"
+fi
+
+# set defaults if not specified in config
+: ${BTRFS_DIR_ACTIVE:="/__active"}
+: ${BTRFS_DIR_SNAPSHOT:="/__snapshot"}
+: ${BTRFS_DIR_ROLLBACK:="/__rollback"}
+
+# strip trailing / if needed
+BTRFS_DIR_ACTIVE="${BTRFS_DIR_ACTIVE%/}"
+BTRFS_DIR_SNAPSHOT="${BTRFS_DIR_SNAPSHOT%/}"
+BTRFS_DIR_ROLLBACK="${BTRFS_DIR_ROLLBACK%/}"
+
+# internal variables
+: ${BTRFS_HAS_ROLLBACK:=true}
+: ${BTRFS_DIR_WORK:="/new_root"}
+: ${BTRFS_BOOT_SUBVOL:="."}
+: ${BTRFS_BOOT_SUBVOLID:=0}
+: ${BTRFS_ROLLBACK_DIALOG:=true}
+: ${BTRFS_ROLLBACK_CHOICE:="default"}
+: ${BTRFS_ROLLBACK_LIST:="default"}
+: ${BTRFS_ROLLBACK_LIST_COUNT:=1}
+: ${BTRFS_ROLLBACK_KERNEL:=true}
+: ${BTRFS_KERNEL:="/boot/vmlinuz-linux"}
+: ${BTRFS_INITRD:="/boot/initramfs-linux.img"}
+: ${BTRFS_KVER_CHECK:=true}
+: ${BTRFS_KVER_DIFFER:=true}
+: ${BTRFS_ENABLE_DEGRADED:=false}
+: ${BTRFS_ENABLE_DEGRADED_ROLLBACK:=false}
+: ${BTRFS_BOOT_DELAY:=0}
+
+root_is_btrfs() {
+ [ "$(blkid -s TYPE -o value "$root" )" != "btrfs" ] &&
+ [ "$(blkid -s TYPE -o value -lt "$root" )" != "btrfs" ]
+} 2>/dev/null
+
+kver() {
+ # extract kernel_version from header in kernel image
+ # according to kernel documentation:
+ # https://www.kernel.org/doc/Documentation/x86/boot.txt
+
+ local offset=$(hexdump -s 526 -n 2 -e '"%d"' "$1")
+ hexdump -s $(( 0x200 + offset )) -n 128 -e '"%.2s"' "$1" | strings -n10
+}
+
+btrfs_mount_handler () {
+ local x i=1 work=${1%/}
+ BTRFS_DIR_WORK=${work}
+
+ if ! root_is_btrfs; then
+ default_mount_handler "$@"
+ return
+ fi
+
+ # temporary mount btrfs root subvolume
+ if ! mount -t btrfs -o subvolid=0,rw ${root} ${work}; then
+
+ # try to mount in degraded mode
+ if ${BTRFS_ENABLE_DEGRADED}; then
+ if ! mount -t btrfs -o subvolid=0,rw,degraded ${root} ${work}; then
+ btrfs_fatal "Unable to mount root subvolume in degraded mode"
+ return 1
+ else
+ btrfs_warn "Mounted root subvolume in degraded mode"
+ sleep 3
+ rootflags="${rootflags},degraded"
+
+ # supress rollback choice in degraded mode
+ if ! ${BTRFS_ENABLE_DEGRADED_ROLLBACK}; then
+ btrfs_info "Disabled rollback feature in degraded mode"
+ kexeced=1
+ fi
+ fi
+ else
+ btrfs_fatal "Unable to mount root subvolume"
+ return 1
+ fi
+ fi
+
+ # check if we already ran kexec
+ if [ -z "$kexeced" ]; then
+
+ if ! [ -d ${work}${BTRFS_DIR_ACTIVE} ]; then
+
+ # ask to initialize active subvolume
+ if ! btrfs_ask_volatile && btrfs_set_volatile; then
+ BTRFS_HAS_ROLLBACK=false
+ fi
+ fi
+
+ if ${BTRFS_HAS_ROLLBACK}; then
+
+ # ask for rollback
+ if ${BTRFS_ROLLBACK_DIALOG} && btrfs_ask_rollback; then
+
+ # collect available snapshots
+ for x in $(btrfs subvolume list ${work} --sort=gen | awk '{print $2 ",/" $9}' | grep -E "^[0-9]*,${BTRFS_DIR_SNAPSHOT}/"); do
+ i=$((${i}+1))
+ BTRFS_ROLLBACK_LIST_COUNT=${i}
+ BTRFS_ROLLBACK_LIST="${BTRFS_ROLLBACK_LIST} ${x}"
+ done; i=1
+
+ # print available snapshots
+ echo "Available rollback snapshots:"
+ for x in ${BTRFS_ROLLBACK_LIST}; do
+ echo -e "${i})\t${x#*,}"
+ i=$((${i}+1))
+ done; i=1
+
+ # let the user choose a snapshot
+ BTRFS_ROLLBACK_CHOICE="$(btrfs_get_rollback_choice)"
+
+ if [ "${BTRFS_ROLLBACK_CHOICE}" != "default" ]; then
+ # choose snapshots subvolume
+ BTRFS_BOOT_SUBVOL=${BTRFS_ROLLBACK_CHOICE#*,}
+
+ # snapshot to rollback
+ btrfs_setup_rollback
+
+ # get new subvolid of rollback subvolume
+ x="$(btrfs subvolume list ${work} | awk '{print $2 ",/" $9}' | grep -E "^[0-9]*,${BTRFS_DIR_ROLLBACK}$")"
+ BTRFS_BOOT_SUBVOL=${x#*,}
+ BTRFS_BOOT_SUBVOLID=${x%,*}
+ else
+ # get subvolid of active subvolume
+ x="$(btrfs subvolume list ${work} | awk '{print $2 ",/" $9}' | grep -E "^[0-9]*,${BTRFS_DIR_ACTIVE}$")"
+ BTRFS_BOOT_SUBVOL=${x#*,}
+ BTRFS_BOOT_SUBVOLID=${x%,*}
+ fi
+ else
+ # get subvolid of active subvolume
+ x="$(btrfs subvolume list ${work} | awk '{print $2 ",/" $9}' | grep -E "^[0-9]*,${BTRFS_DIR_ACTIVE}$")"
+ BTRFS_BOOT_SUBVOL=${x#*,}
+ BTRFS_BOOT_SUBVOLID=${x%,*}
+ fi
+
+ # btrfs subvolume set-default
+ btrfs_info "Booting from subvolume [${BTRFS_BOOT_SUBVOL}]..."
+ btrfs subvolume set-default ${BTRFS_BOOT_SUBVOLID} ${work}
+
+ # if kernel rollback is enabled (so it is by default)
+ if ${BTRFS_ROLLBACK_KERNEL}; then
+
+ # test if a new kernel is present
+ if [ -f ${work}${BTRFS_BOOT_SUBVOL}${BTRFS_KERNEL} -a -f ${work}${BTRFS_BOOT_SUBVOL}${BTRFS_INITRD} ]; then
+
+ # compare running kernel's version against kernel image
+ if ${BTRFS_CHECK_KVER}; then
+ if kver "${work}${BTRFS_BOOT_SUBVOL}${BTRFS_KERNEL}" | grep -F "$(uname -r)" | grep -Fq "$(uname -v)"; then
+ BTRFS_KVER_DIFFER=false
+ fi
+ fi
+
+ # only load new kernel if versions differ
+ # if the above check failes they differ by default anyway
+ if ${BTRFS_KVER_DIFFER}; then
+
+ # copy kernel to initramfs
+ cp "${work}${BTRFS_BOOT_SUBVOL}${BTRFS_KERNEL}" "/tmp/linux"
+ cp "${work}${BTRFS_BOOT_SUBVOL}${BTRFS_INITRD}" "/tmp/initrd"
+
+ # unmount btrfs root subvolume
+ if ! umount ${BTRFS_DIR_WORK}; then
+ btrfs_fatal "Unable to umount root subvolume"
+ return 1
+ fi
+
+ # force reload kernel
+ btrfs_info "Reloading kernel from [${BTRFS_BOOT_SUBVOL}]..."
+ kexec -f "/tmp/linux" --initrd="/tmp/initrd" --reuse-cmdline --append="kexeced"
+
+ # at this point the kernel reloads the initramfs and
+ # restarts init - no further code is executed
+ fi
+ else
+ btrfs_warn "Unable to load kernel from new root subvolume"
+ btrfs_warn "Check your config in /etc/default/btrfs_advanced"
+ fi
+ fi
+ fi
+ fi
+
+ # unmount btrfs root subvolume
+ if ! umount ${BTRFS_DIR_WORK}; then
+ btrfs_fatal "Unable to umount root subvolume"
+ return 1
+ fi
+
+ btrfs_process_mount ${work}
+}
+
+btrfs_process_mount () {
+
+ rootfstype=btrfs
+
+ # remove subvol/subvolid mount option
+ rootflags="$(echo ${rootflags} | sed 's/subvol[id]*=[^,]*,\?//g;s/,$//g')"
+
+ # sleep a short period of time to read console messages
+ [ "${quiet}" != "y" ] && sleep ${BTRFS_BOOT_DELAY}
+
+ # call standard mount handler
+ default_mount_handler ${1}
+
+}
+
+btrfs_ask_volatile () {
+ local r
+
+ read -s -p "Press any key to setup BTRFS rollback support..." -n1 -t3
+ r=$?
+
+ echo
+ return $r
+}
+
+btrfs_set_volatile () {
+
+ cat <<MESSAGE
+
+--------------------------------- INFORMATION ----------------------------------
+
+Either this is your first time using this hook, or you have not prepared your
+system for non-volatile rollback support. Support can easily be enabled right
+now, else you can continue using this hook without true non-volatile rollback
+support. To enable support, a snapshot of your system's current state must be
+made to ${BTRFS_DIR_ACTIVE}.
+This snapshot will subsequently be used as the primary boot device from now on.
+This operation is safe. Your original / will remain intact and unused. It is
+up to you to rm -rf the stagnant files from your old /{var,usr,lib,etc},
+and reclaim what would in time become dead space.
+
+ATTENTION: When deleting your old /boot, it may be necessary to reconfigure AND
+ reinstall your bootloader, to search its configuration under
+ ${BTRFS_DIR_ACTIVE}/boot! Otherwise your system may become
+ unbootable!
+
+DO NOT remove ${BTRFS_DIR_ACTIVE}, ${BTRFS_DIR_SNAPSHOT}, or ${BTRFS_DIR_ROLLBACK}.
+
+The following commands will be executed:
+
+# btrfs subvolume snapshot / ${BTRFS_DIR_ACTIVE}
+# mkdir ${BTRFS_DIR_SNAPSHOT}
+
+If you do not understand the above, are afraid, or become clammy/panicky when
+presented with decisions, answer no, and seek the maintainer for clarification.
+
+--------------------------------- INFORMATION ----------------------------------
+
+MESSAGE
+
+ local x i=0 ans prompt="Continue setup rollback support? (y/[n]) "
+ while true; do
+ read -p "${prompt}" ans
+ if [ -z "${ans}" ]; then
+ ans=n; break
+ elif ! echo "${ans}" | grep -q -E "^[yn]$"; then
+ prompt="Try again, this time choose y or n: "
+ else
+ break
+ fi
+ done
+
+ # return 1 to DISABLE NON-VOLATILE SUPPORT, and boot / instead
+ if [ ${ans} = y ]; then
+ btrfs_info "Snapshotting system state to ${BTRFS_DIR_ACTIVE}..."
+ if ! btrfs subvolume snapshot ${BTRFS_DIR_WORK} ${BTRFS_DIR_WORK}${BTRFS_DIR_ACTIVE}; then
+ btrfs_error "Unknown problem creating ${BTRFS_DIR_ACTIVE}, fallback to /"
+ return 1
+ fi
+ if ! mkdir ${BTRFS_DIR_WORK}${BTRFS_DIR_SNAPSHOT}; then
+ btrfs_error "Unknown problem creating ${BTRFS_DIR_SNAPSHOT}, fallback to /"
+ return 1
+ fi
+ return 0
+ else
+ btrfs_warn "Skipping setup of non-volatile rollback support"
+ return 1
+ fi
+
+}
+
+btrfs_ask_rollback () {
+ local r
+
+ read -s -p "Press any key to prepare BTRFS rollback..." -n1 -t3;
+ r=$?
+
+ echo
+ return $r
+}
+
+btrfs_get_rollback_choice () {
+
+ local x i=1 ans prompt="Select snapshot [${BTRFS_ROLLBACK_LIST_COUNT}]: "
+ while true; do
+ read -p "${prompt}" ans
+ if [ -z "${ans}" ]; then
+ ans=${BTRFS_ROLLBACK_LIST_COUNT}
+ break
+ elif ! echo "${ans}" | grep -q -E "^[0-9]+$"; then
+ prompt="Invalid choice (not a number), please try again: "
+ elif [ ${ans} -lt 1 ]; then
+ prompt="Selection (${ans}) is too low, please try again: "
+ elif [ ${ans} -gt ${BTRFS_ROLLBACK_LIST_COUNT} ]; then
+ prompt="Selection (${ans}) is too high, please try again: "
+ else
+ break
+ fi
+ done
+
+ for x in ${BTRFS_ROLLBACK_LIST}; do
+ if [ ${ans} -eq ${i} ]; then
+ echo "${x}"
+ return 0
+ fi
+ i=$((${i}+1))
+ done
+
+ echo "default"
+}
+
+btrfs_setup_rollback () {
+
+ local source=${BTRFS_DIR_WORK}${BTRFS_BOOT_SUBVOL}
+ local target=${BTRFS_DIR_WORK}${BTRFS_DIR_ROLLBACK}
+ if [ -d ${target} ]; then
+ btrfs_info "Delete stagnant rollback environment in [${BTRFS_DIR_ROLLBACK}]..."
+ btrfs subvolume delete ${target} || rm -rf ${target}
+ fi
+ btrfs_info "Creating new rollback environment in [${BTRFS_DIR_ROLLBACK}] from [${BTRFS_BOOT_SUBVOL}]..."
+ btrfs subvolume snapshot ${source} ${target}
+
+}
+
+# main
+run_hook () {
+ mount_handler="btrfs_mount_handler"
+}
+
+# vim:set syntax=sh:
diff --git a/btrfs_install b/btrfs_install
new file mode 100644
index 000000000000..61fa255cad7f
--- /dev/null
+++ b/btrfs_install
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+build() {
+ add_module btrfs
+
+ add_binary btrfs
+ add_binary btrfsck
+ add_binary kexec
+
+ if [ -f /etc/default/btrfs_advanced ]; then
+ add_file /etc/default/btrfs_advanced
+ fi
+
+ add_runscript
+}
+
+
+help() {
+ cat <<HELPEOF
+This hook provides advanced support for single and multi device btrfs
+partitions, including rollback operations at boot time. If you do not
+use the "udev" hook, then you MUST add the "btrfs" hook before this one.
+HELPEOF
+}
+
+# vim: set ft=sh ts=4 sw=4 et:
diff --git a/mkinitcpio-btrfs.install b/mkinitcpio-btrfs.install
new file mode 100644
index 000000000000..4e2cd4bd4af5
--- /dev/null
+++ b/mkinitcpio-btrfs.install
@@ -0,0 +1,74 @@
+post_install() { post_upgrade "${@}"; }
+
+post_upgrade() {
+
+ { grep -qe '^HOOKS=.*btrfs[^_]' /etc/mkinitcpio.conf && cat <<'MSG'
+
+==> WARNING: detected active hook "btrfs" in /etc/mkinitcpio.conf
+ -> You MUST rename it to "btrfs_advanced".
+ Else this hook will *not* run!
+MSG
+} || {
+ [ -z "${2}" ] && ! grep -qe '^HOOKS=.*btrfs_advanced' /etc/mkinitcpio.conf && cat <<'MSG'
+
+==> Add hook to /etc/mkinitcpio.conf:
+ -> HOOKS="[...] btrfs_advanced"
+MSG
+}
+
+ cat <<'MSG'
+
+==> Have a look in /etc/default/btrfs_advanced to configure advanced options.
+
+==> Run mkinitcpio to update your initramfs image
+ # mkinitcpio -p linux
+
+==> ATTENTION: GRUB 2.02 does no longer support relative paths from set-default
+ subvolumes. Thus it is recommended to regenerate your GRUB configuration
+ using grub-mkconfig and also reinstall GRUB to your drive using
+ grub-install, as this is not done automatically on GRUB version updates.
+MSG
+
+ [ $(vercmp ${1} 0.3) -ge 0 ] &&
+ [ $(vercmp ${2:-0} 0.3) -lt 0 ] &&
+ _display_rollback_add_info
+
+ cat <<'MSG'
+
+==> Have ideas for this hook? Share!
+ -> [GitHub] https://github.com/xtfxme/mkinitcpio-btrfs
+ -> [AUR] https://aur.archlinux.org/packages/mkinitcpio-btrfs
+MSG
+
+ echo
+}
+
+post_remove() {
+
+ cat <<'MSG'
+
+==> Remove "btrfs_advanced" from HOOKS in /etc/mkinitcpio.conf
+
+==> Run mkinitcpio to update your initramfs image (remove hook)
+ # mkinitcpio -p linux
+MSG
+
+ echo
+}
+
+_display_rollback_add_info() {
+
+ cat <<'MSG'
+
+==> To ENABLE rollback support, EITHER:
+ -> Reboot and the hook will ask to do it for you.
+ -> Or run the following command RIGHT before rebooting:
+ # btrfs subvolume snapshot / /__active
+ # btrfs subvolume list /
+ ID 256 gen 98 top level 5 path __active
+ # btrfs subvolume set-default 256 .
+ Changes between snapshot and reboot will be ignored!
+MSG
+
+}
+