Skip to content

Commit

Permalink
added initramfs scripts for debian and derivatives
Browse files Browse the repository at this point in the history
  • Loading branch information
renaudcerrato committed Dec 2, 2024
1 parent f682e17 commit 0f85292
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
31 changes: 31 additions & 0 deletions initramfs/Debian/grub-btrfs-overlayfs-boot
Original file line number Diff line number Diff line change
@@ -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

10 changes: 10 additions & 0 deletions initramfs/Debian/grub-btrfs-overlayfs-hook
Original file line number Diff line number Diff line change
@@ -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)

12 changes: 12 additions & 0 deletions initramfs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#

0 comments on commit 0f85292

Please sign in to comment.