diff --git a/initramfs/Debian/grub-btrfs-overlayfs-boot b/initramfs/Debian/grub-btrfs-overlayfs-boot new file mode 100755 index 0000000..cc34a6b --- /dev/null +++ b/initramfs/Debian/grub-btrfs-overlayfs-boot @@ -0,0 +1,31 @@ +#!/bin/sh + +PREREQ="" + +prereqs() +{ + echo "$PREREQ" +} + + +case $1 in +prereqs) + prereqs + exit 0 + ;; +esac + +. /scripts/functions + +current_dev=$(resolve_device "${ROOT}") + +if [[ $(blkid "${current_dev}" -s TYPE -o value) = "btrfs" ]] && [[ $(btrfs property get ${rootmnt} ro) != "ro=false" ]]; then # run only on a read only snapshot + lower_dir=$(mktemp -d -p /) + ram_dir=$(mktemp -d -p /) + mount --move ${rootmnt} ${lower_dir} # move new_root to lower_dir + mount -t tmpfs tmpfs ${ram_dir} + mkdir -p ${ram_dir}/upper + mkdir -p ${ram_dir}/work + mount -t overlay -o lowerdir=${lower_dir},upperdir=${ram_dir}/upper,workdir=${ram_dir}/work rootfs ${rootmnt} +fi + diff --git a/initramfs/Debian/grub-btrfs-overlayfs-hook b/initramfs/Debian/grub-btrfs-overlayfs-hook new file mode 100755 index 0000000..d595b5b --- /dev/null +++ b/initramfs/Debian/grub-btrfs-overlayfs-hook @@ -0,0 +1,10 @@ +#!/bin/sh + +. /usr/share/initramfs-tools/hook-functions + +manual_add_modules btrfs +manual_add_modules overlay +copy_exec $(which btrfs) +copy_exec $(which btrfsck) +copy_exec $(which blkid) + diff --git a/initramfs/readme.md b/initramfs/readme.md index 233f667..c765863 100644 --- a/initramfs/readme.md +++ b/initramfs/readme.md @@ -44,6 +44,18 @@ 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. +#### Debian based distros + +1. Copy [grub-btrfs-overlayfs-hook](Debian/grub-btrfs-overlayfs-hook) script to initramfs-tools hooks directory: +`sudo cp grub-btrfs-overlayfs-hook /etc/initramfs-tools/hooks/` + +2. Copy [grub-btrfs-overlayfs-boot](Debian/grub-btrfs-overlayfs-boot) script to initramfs-tools local-bottom scripts directory: +`sudo cp grub-btrfs-overlayfs-boot /etc/initramfs-tools/scripts/local-bottom/` + +3. Update your initramfs +`sudo update-initramfs -u` + + #### Other distribution Refer to your distribution's documentation or contribute to this project to add a paragraph. #