Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

document & implement initramfs scripts for ubuntu #250

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ PKGNAME ?= grub-btrfs
PREFIX ?= /usr

INITCPIO ?= false
MKINITRAMFS ?= false
SYSTEMD ?= true
OPENRC ?= false

Expand Down Expand Up @@ -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"
Expand All @@ -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 :
Expand Down Expand Up @@ -108,14 +115,15 @@ help:
@echo " uninstall"
@echo " help"
@echo
@echo " parameter | type | description | defaults"
@echo " ----------+------+--------------------------------+----------------------------"
@echo " DESTDIR | path | install destination | <unset>"
@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 | <unset>"
@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
7 changes: 7 additions & 0 deletions initramfs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
15 changes: 15 additions & 0 deletions initramfs/ubuntu/hooks/grub-btrfs-overlay
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions initramfs/ubuntu/scripts/local-bottom/grub-btrfs-overlay
Original file line number Diff line number Diff line change
@@ -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
70 changes: 70 additions & 0 deletions initramfs/ubuntu/setup
Original file line number Diff line number Diff line change
@@ -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