diff --git a/Makefile b/Makefile index 93be560..a1efe5d 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ PKGNAME ?= grub-btrfs PREFIX ?= /usr INITCPIO ?= false +MKINITRAMFS ?= false SYSTEMD ?= true OPENRC ?= false @@ -59,6 +60,11 @@ install: install -Dm644 "initramfs/Arch Linux/overlay_snap_ro-install" "$(LIB_DIR)/initcpio/install/grub-btrfs-overlayfs"; \ install -Dm644 "initramfs/Arch Linux/overlay_snap_ro-hook" "$(LIB_DIR)/initcpio/hooks/grub-btrfs-overlayfs"; \ fi + @# Ubuntu like distros only : + @if test "$(MKINITRAMFS)" = true; then \ + echo "Installing mkinitramfs hook"; \ + initramfs/ubuntu/setup install; \ + fi @install -Dm644 -t "$(SHARE_DIR)/licenses/$(PKGNAME)/" LICENSE @install -Dm644 -t "$(SHARE_DIR)/doc/$(PKGNAME)/" README.md @install -Dm644 "initramfs/readme.md" "$(SHARE_DIR)/doc/$(PKGNAME)/initramfs-overlayfs.md" @@ -80,6 +86,7 @@ uninstall: @rm -f "$(DESTDIR)/etc/conf.d/grub-btrfsd;" @rm -f "$(LIB_DIR)/initcpio/install/grub-btrfs-overlayfs" @rm -f "$(LIB_DIR)/initcpio/hooks/grub-btrfs-overlayfs" + @initramfs/ubuntu/setup uninstall || true @rm -f "$(MAN_DIR)/man8/grub-btrfs.8.bz2" @rm -f "$(MAN_DIR)/man8/grub-btrfsd.8.bz2" @# Arch Linux UNlike distros only : @@ -108,14 +115,15 @@ help: @echo " uninstall" @echo " help" @echo - @echo " parameter | type | description | defaults" - @echo " ----------+------+--------------------------------+----------------------------" - @echo " DESTDIR | path | install destination | " - @echo " PREFIX | path | system tree prefix | '/usr'" - @echo " SHARE_DIR | path | shared data location | '\$$(DESTDIR)\$$(PREFIX)/share'" - @echo " LIB_DIR | path | system libraries location | '\$$(DESTDIR)\$$(PREFIX)/lib'" - @echo " PKGNAME | name | name of the ditributed package | 'grub-btrfs'" - @echo " INITCPIO | bool | include mkinitcpio hook | false" - @echo " SYSTEMD | bool | include unit files | true" - @echo " OPENRC | bool | include OpenRc daemon | false" + @echo " parameter | type | description | defaults" + @echo " ------------+------+--------------------------------+----------------------------" + @echo " DESTDIR | path | install destination | " + @echo " PREFIX | path | system tree prefix | '/usr'" + @echo " SHARE_DIR | path | shared data location | '\$$(DESTDIR)\$$(PREFIX)/share'" + @echo " LIB_DIR | path | system libraries location | '\$$(DESTDIR)\$$(PREFIX)/lib'" + @echo " PKGNAME | name | name of the ditributed package | 'grub-btrfs'" + @echo " INITCPIO | bool | include mkinitcpio hook | false" + @echo " MKINITRAMFS | bool | include mkinitramfs hook | false" + @echo " SYSTEMD | bool | include unit files | true" + @echo " OPENRC | bool | include OpenRc daemon | false" @echo diff --git a/initramfs/readme.md b/initramfs/readme.md index 233f667..8de44cc 100644 --- a/initramfs/readme.md +++ b/initramfs/readme.md @@ -44,6 +44,13 @@ Distributions that use Dracut to make their initramfs (many of the Fedora based Grub-btrfs provides the variable `GRUB_BTRFS_SNAPSHOT_KERNEL_PARAMETERS` to add any command to the kernel command line. Set it to `GRUB_BTRFS_SNAPSHOT_KERNEL_PARAMETERS="rd.live.overlay.overlayfs=1"` to make snapshots immutable when booted into. After changing this run `sudo /etc/grub.d/41_snapshots-btrfs` to generate a new snapshot-submenu with the parameter added. +#### Ubuntu + Install initramfs scripts & re-generate initramfs. + +``` shell +sudo initramfs/ubuntu/setup install +``` + #### Other distribution Refer to your distribution's documentation or contribute to this project to add a paragraph. # diff --git a/initramfs/ubuntu/hooks/grub-btrfs-overlay b/initramfs/ubuntu/hooks/grub-btrfs-overlay new file mode 100755 index 0000000..f0676c1 --- /dev/null +++ b/initramfs/ubuntu/hooks/grub-btrfs-overlay @@ -0,0 +1,15 @@ +#!/bin/sh -e +PREREQ= +prereqs() { + echo "$PREREQ" +} +case "$1" in + prereqs) + prereqs + exit 0 + ;; +esac + +. /usr/share/initramfs-tools/hook-functions +manual_add_modules overlay +copy_exec /usr/bin/findmnt /usr/bin diff --git a/initramfs/ubuntu/scripts/local-bottom/grub-btrfs-overlay b/initramfs/ubuntu/scripts/local-bottom/grub-btrfs-overlay new file mode 100755 index 0000000..3049423 --- /dev/null +++ b/initramfs/ubuntu/scripts/local-bottom/grub-btrfs-overlay @@ -0,0 +1,32 @@ +#!/bin/sh -e +PREREQ= +prereqs() { + echo "$PREREQ" +} +case $1 in + prereqs) + prereqs + exit 0 + ;; +esac + +. /scripts/functions +on_err() { + log_failure_msg 'error setting up overlay' +} +trap on_err ERR +if [ -x /usr/bin/btrfs -a -x /usr/bin/findmnt ] && + [ "$(findmnt -no FSTYPE -M "$rootmnt")" = btrfs ] && + [ "$(btrfs property get $rootmnt ro)" != ro=false ] +then + log_begin_msg 'remount read-only subvolume as read-only layer in non-persistent, writable overlay' + trap log_end_msg EXIT + lower_dir="$(mktemp -dp /)" + ram_dir="$(mktemp -dp /)" + upper_dir="$ram_dir"/upper + work_dir="$ram_dir"/work + mount --move "$rootmnt" "$lower_dir" + mount -t tmpfs cowspace "$ram_dir" + mkdir -p "$upper_dir" "$work_dir" + mount -t overlay -o lowerdir="$lower_dir",upperdir="$upper_dir",workdir="$work_dir" rootfs "$rootmnt" +fi diff --git a/initramfs/ubuntu/setup b/initramfs/ubuntu/setup new file mode 100755 index 0000000..c9e7e23 --- /dev/null +++ b/initramfs/ubuntu/setup @@ -0,0 +1,70 @@ +#!/usr/bin/env bash +log() { + local CODE=$? + echo >&2 "$*" + return $CODE +} +print-help() { + log "\ +usage: ${0##*/} [-h] [--] (install|uninstall) +Install initramfs scripts for Ubuntu. + +# Options +-h display this help & exit + +# Subcommands +install install initramfs scripts +uninstall remove initramfs scripts" +} +usage-error() { + print-help + exit 2 +} +action-install() { + local SCRIPT_DIR="$(cd -P -- "$(dirname -- "$BASH_SOURCE")" && pwd)" + install {"$SCRIPT_DIR",/etc/initramfs-tools}/hooks/grub-btrfs-overlay + install {"$SCRIPT_DIR",/etc/initramfs-tools}/scripts/local-bottom/grub-btrfs-overlay +} +action-uninstall() { + rm -f /etc/initramfs-tools/{hooks,scripts/local-bottom}/grub-btrfs-overlay +} +set -e +while getopts h OPT +do case "$OPT" in + h) + print-help + exit + ;; + *) + usage-error +esac done +shift $(( OPTIND - 1 )) +OPTIND=1 +ACTION= +case "$#" in + 0) + log event: a subcommand is required + usage-error + ;; + 1) + case "$1" in + install|uninstall) + ACTION="action-$1" + ;; + *) + log "\ +event: unknown subcommand +subcommand: $1" + usage-error + esac + ;; + *) + log "\ +event: too many arguments +arguments: $*" + usage-error +esac +"$ACTION" || log "\ +event: execution failure +suggestion: rerun with sudo" +exec update-initramfs -u