diff options
author | Tim Hildering | 2023-01-02 16:31:54 +0100 |
---|---|---|
committer | Tim Hildering | 2023-01-02 16:31:54 +0100 |
commit | 5543e81ceed1a2e3b1e2263d421bfe41594f3dff (patch) | |
tree | c69b35018c94c565eaa0c4cb7b222c441ab9a42a | |
parent | 9900338858e5345b0737babfb73944912c2dc6b1 (diff) | |
download | aur-5543e81ceed1a2e3b1e2263d421bfe41594f3dff.tar.gz |
Added configuration file to set change some predefined values
Added further configuration options
Updated PKGBUILD, README.md, .SRCINFO
-rw-r--r-- | .SRCINFO | 2 | ||||
-rw-r--r-- | PKGBUILD | 5 | ||||
-rw-r--r-- | README.md | 43 | ||||
-rw-r--r-- | mount.overlayroot | 15 | ||||
-rw-r--r-- | overlayroot-install.hooks | 1 | ||||
-rw-r--r-- | overlayroot-runtime.hooks | 127 | ||||
-rw-r--r-- | overlayroot.conf | 43 |
7 files changed, 187 insertions, 49 deletions
@@ -1,6 +1,6 @@ pkgbase = overlayroot pkgdesc = Overlay the root filesystem with a tmpfs filesystem. - pkgver = 1.0 + pkgver = 1.0.1 pkgrel = 1 url = https://github.com/hilderingt/archlinux-overlayroot arch = any @@ -16,7 +16,7 @@ # Maintainer: Tim Hildering <hilderingt@posteo.net> pkgname=overlayroot -pkgver=1.0 +pkgver=1.0.1 pkgrel=1 pkgdesc="Overlay the root filesystem with a tmpfs filesystem." arch=('any') @@ -29,11 +29,13 @@ source=( 'overlayroot-install.hooks' 'overlayroot-runtime.hooks' 'mount.overlayroot' + 'overlayroot.conf' ) sha256sums=( 'SKIP' 'SKIP' 'SKIP' + 'SKIP' ) build() { @@ -44,4 +46,5 @@ package() { install -Dm644 "$srcdir/overlayroot-install.hooks" "$pkgdir/usr/lib/initcpio/install/overlayroot" install -Dm644 "$srcdir/overlayroot-runtime.hooks" "$pkgdir/usr/lib/initcpio/hooks/overlayroot" install -Dm755 "$srcdir/mount.overlayroot" "$pkgdir/usr/bin/mount.overlayroot" + install -Dm644 "$srcdir/overlayroot.conf" "$pkgdir/etc/overlayroot.conf" } diff --git a/README.md b/README.md index 0be561f56483..b2bc4664c647 100644 --- a/README.md +++ b/README.md @@ -28,12 +28,45 @@ write access is not needed and you want to protect it against changes. - add `overlayroot` to the end of __HOOKS__ array in mkinitcpio.conf - update initramfs with `mkinitcpio -P` -### 2.2 Kernel command line +### 2.2 Kernel Command Line - add `overlayroot` to your kernel command line - optional: + - add `opts=<option>,...` to `overlayroot=...` + - available options: + - `noswap` : deactivate swap space - add `tmpfs=/<path>/<to>/<mountpoint>,...` to `overlayroot=...` to overlay - these filesystems with a tmpfs filesystem - - add `ro=/<path>/<to>/<mountpoint>,...` to `overlayroot=...` to mount these + filesystems with a tmpfs filesystem + - add `ro=/<path>/<to>/<mountpoint>,...` to `overlayroot=...` to mount filesystems read-only - - separate both options with a `:` - - complete example: `overlayroot=tmpfs=/usr:ro=/boot,/boot/efi` + - specify `all` instead of dedicated mountpoints for `tmpfs` or `ro` + - separate options with a `:` + - examples: + overlayroot=tmpfs=/usr:ro=/boot,/boot/efi + overlayroot=tmpfs=all:opts=noswap + overlayroot=ro=all + +### 2.3 Configuration File +- path `/etc/overlayroot.conf` + - `OVLROOT_FS_ROONLY=<fs>,...` filesystems that can't be used as lower layer + - examples: `msdos, (v)fat, ntfs-3g` + - `OVLROOT_FS_RAMONLY=<fs>,...` filesystems that are always ignored by overlayroot + - examples: `tmpfs, proc, sysfs` + - `OVLROOT_FSTAB=/<path>/<to>/<fstab>` modified fstab created by overlayroot + during initramfs phase to replace system-wide fstab + - default: `/tmp/overlayroot.fstab` + - `OVLROOT_MAINDIR=/<path>/<to>/<mountpoint>` mountpoint for tmpfs filesystem + - default: `/.overlay` + - `OVLROOT_LOWDERDIR_NAME=<dirname>` subdirectory of all lower filesystem mounts + - default: `ro` + - `OVLROOT_UPPERDIR_NAME=<dirname>` subdirectory for all changes made to the filesystems + - default: `rw` + - `OVLROOT_WORKDIR_NAME=<dirname>` subdirectory needed by OverlayFS + - default: `work` + - `FSTAB_SYSTEM=/<path>/<to>/<fstab>` system-wide fstab + - default: `/etc/fstab` + - `ROOTMNT=/<path>/<to>/<mountpoint>` mountpoint of root filesystem in initramfs phase + - default: `/new_root` + + + + diff --git a/mount.overlayroot b/mount.overlayroot index c9b1ab6725db..b4dcad41ab1e 100644 --- a/mount.overlayroot +++ b/mount.overlayroot @@ -22,16 +22,21 @@ MOUNT_FSDIR="${2}" MOUNT_FSOPTIONS="" MOUNT_OPTIONS="" MOUNT_FSTYPE="" - +OVLROOT_CFGFILE="/etc/overlayroot.conf" OVLROOT_MAINDIR="/.overlay" -OVLROOT_LOWERDIR="${OVLROOT_MAINDIR}/ro" -OVLROOT_UPPERDIR="${OVLROOT_MAINDIR}/rw" -OVLROOT_WORKDIR="${OVLROOT_MAINDIR}/work" - +OVLROOT_LOWERDIR_NAME="ro" +OVLROOT_UPPERDIR_NAME="rw" +OVLROOT_WORKDIR_NAME="work" BASEDIR="" LIMIT=10 CNT=0 +[ -f "${OVLROOT_CFGFILE}" ] && . "${OVLROOT_CFGFILE}" + +OVLROOT_LOWERDIR="${OVLROOT_MAINDIR}/${OVLROOT_LOWERDIR_NAME}" +OVLROOT_UPPERDIR="${OVLROOT_MAINDIR}/${OVLROOT_UPPERDIR_NAME}" +OVLROOT_WORKDIR="${OVLROOT_MAINDIR}/${OVLROOT_WORKDIR_NAME}" + shift 2 while getopts 'fnsvN:o:t:' OPT 2>/dev/null do diff --git a/overlayroot-install.hooks b/overlayroot-install.hooks index 57e0e69aac16..43132c7a0f90 100644 --- a/overlayroot-install.hooks +++ b/overlayroot-install.hooks @@ -17,4 +17,5 @@ build() { add_runscript + add_file "/etc/overlayroot.conf" "/etc/overlayroot.conf" "644" } diff --git a/overlayroot-runtime.hooks b/overlayroot-runtime.hooks index e7e4524c41e2..b8728e5ca680 100644 --- a/overlayroot-runtime.hooks +++ b/overlayroot-runtime.hooks @@ -15,17 +15,20 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -OVLROOT_MAINDIR="/.overlay" -OVLROOT_LOWERDIR="${OVLROOT_MAINDIR}/ro" -OVLROOT_UPPERDIR="${OVLROOT_MAINDIR}/rw" -OVLROOT_WORKDIR="${OVLROOT_MAINDIR}/work" +MSG_MODIFIED="original line modified by overlayroot" +MSG_DEACTIVATED="line deactivated by overlayroot" +OVLROOT_FS_ROONLY="msdos,fat,vfat,iso9660,udf,ntfs-3g,ntfs3" +OVLROOT_FS_RAMONLY="tmpfs,devpts,devtmpfs,tracefs,debugfs,\ +configfs,securityfs,proc,sysfs,swap,ramfs" +OVLROOT_CFGFILE="/etc/overlayroot.conf" OVLROOT_FSTAB="/tmp/overlayroot.fstab" +OVLROOT_MAINDIR="/.overlay" +OVLROOT_LOWERDIR_NAME="ro" +OVLROOT_UPPERDIR_NAME="rw" +OVLROOT_WORKDIR_NAME="work" FSTAB_SYSTEM="/etc/fstab" ROOTMNT="/new_root" -MSG_MODIFIED="original entry modified by overlayroot" -MSG_DEACTIVATED="entry deactivated by overlayroot" - add_comments() { while [ ${#} -gt 0 ] do @@ -33,6 +36,17 @@ add_comments() { done } +list_contains() { + local list="${1}" item="${2}" + + for _item in ${list} + do + [ "${_item}" = "${item}" ] && return 0 + done + + return 1 +} + fsopts_add_ro() { local fsopts=${1}, fsopts_ro="ro" local opt="" @@ -56,10 +70,11 @@ fsopts_add_ro() { } run_latehook() { - local line="" opts="" mnts_overlay="" mnts_rdonly="" + local line="" options="" noswap="" mnts_overlay="" mnts_rdonly="" + local ovlroot_lowerdir="" ovlroot_upperdir="" ovlroot_workdir="" local fsopts_root="ro" - [ ${#overlayroot} -eq 0 ] && return 0 + [ ${#overlayroot} -eq 0 ] && return for opt in ${overlayroot//:/ } do @@ -69,29 +84,47 @@ run_latehook() { ;; ro=*) mnts_rdonly="${opt#ro=}" - ;; - *) ;; + opts=*) + options="${opt#options=}" + + for opt in ${options//,/ } + do + case "${opt}" in + noswap) + noswap="y" + ;; + esac + done + ;; esac done + [ -f "${OVLROOT_CFGFILE}" ] && . "${OVLROOT_CFGFILE}" + + ovlroot_lowerdir="${OVLROOT_MAINDIR}/${OVLROOT_LOWERDIR_NAME}" + ovlroot_upperdir="${OVLROOT_MAINDIR}/${OVLROOT_UPPERDIR_NAME}" + ovlroot_workdir="${OVLROOT_MAINDIR}/${OVLROOT_WORKDIR_NAME}" + mkdir -p "${OVLROOT_MAINDIR}" mount -t "tmpfs" "overlayroot-tmpfs" "${OVLROOT_MAINDIR}" - mkdir -p "${OVLROOT_LOWERDIR}" - mkdir -p "${OVLROOT_UPPERDIR}/root" - mkdir -p "${OVLROOT_WORKDIR}/root" + mkdir -p "${ovlroot_lowerdir}" + mkdir -p "${ovlroot_upperdir}/root" + mkdir -p "${ovlroot_workdir}/root" - mount -o "move" "${ROOTMNT}" "${OVLROOT_LOWERDIR}" + mount -o "move" "${ROOTMNT}" "${ovlroot_lowerdir}" + mount -t "overlay" -o "lowerdir=${ovlroot_lowerdir},\ +upperdir=${ovlroot_upperdir}/root,workdir=${ovlroot_workdir}/root" \ +"overlayroot" "${ROOTMNT}" - mount -t "overlay" -o "\ -lowerdir=${OVLROOT_LOWERDIR},upperdir=${OVLROOT_UPPERDIR}/root,\ -workdir=${OVLROOT_WORKDIR}/root" "overlayroot" "${ROOTMNT}" + mkdir -p "${ROOTMNT}/${OVLROOT_MAINDIR}" + mount -o "move" "${OVLROOT_MAINDIR}" "${ROOTMNT}/${OVLROOT_MAINDIR}" while IFS= read -r line do local fs="" fsdir="" fstype="" fsopts="" fsdump="" fspass="" - local error="" mnt="" fsopts_ro="" + local error="" fsclass="" fsopts_ro="" local _line="${line%%#*}" [ ${#_line} -eq 0 ] && { echo "${line}"; continue; } @@ -113,40 +146,60 @@ workdir=${OVLROOT_WORKDIR}/root" "overlayroot" "${ROOTMNT}" fsopts_ro="$(fsopts_add_ro "${fsopts}")" + if [ "${fstype}" = "swap" ] + then + if [ "${noswap}" = "y" ] + then + add_comments "${MSG_DEACTIVATED}" "${line}" + continue + fi + + fsclass="ram_only" + else + if list_contains "${OVLROOT_FS_ROONLY//,/ }" "${fstype}" + then + fsclass="ro_only" + elif list_contains "${OVLROOT_FS_RAMONLY//,/ }" "${fstype}" + then + fsclass="ram_only" + else + fsclass="overlay" + fi + fi + if [ "${fsdir}" = "/" ] then + [ "${fsclass}" != "overlay" ] && return + fsopts_root="${fsopts_ro}" add_comments "${MSG_DEACTIVATED}" "${line}" continue fi - for mnt in ${mnts_overlay//,/ } - do - if [ "${mnt}" = "${fsdir}" ] + if [ "${fsclass}" != "ram_only" ] + then + if [ "${mnts_overlay}" = "all" ] || \ + list_contains "${mnts_overlay//,/ }" "${fsdir}" then - add_comments "${MSG_MODIFIED}" "${line}" - fstype="overlayroot.${fstype}" - fsopts="${fsopts_ro}" - fi - done - - for mnt in ${mnts_rdonly//,/ } - do - if [ "${mnt}" = "${fsdir}" ] + if [ "${fsclass}" != "ro_only" ] + then + add_comments "${MSG_MODIFIED}" "${line}" + fstype="overlayroot.${fstype}" + fsopts="${fsopts_ro}" + fi + elif [ "${mnts_rdonly}" = "all" ] || + list_contains "${mnts_rdonly//,/ }" "${fsdir}" then add_comments "${MSG_MODIFIED}" "${line}" fsopts="${fsopts_ro}" - fspass=0; break + fspass=0 fi - done + fi printf "%s\t%s\t%s\t%s\t%s\t%s\n" "${fs}" "${fsdir}" \ "${fstype}" "${fsopts}" "${fsdump}" "${fspass}" done <"${ROOTMNT}/${FSTAB_SYSTEM}" >"${OVLROOT_FSTAB}" - mkdir -p "${ROOTMNT}/${OVLROOT_MAINDIR}" - mount -o "move" "${OVLROOT_MAINDIR}" "${ROOTMNT}/${OVLROOT_MAINDIR}" - mount -o "remount,${fsopts_root}" "${ROOTMNT}/${OVLROOT_LOWERDIR}" - + mount -o "remount,${fsopts_root}" "${ROOTMNT}/${ovlroot_lowerdir}" mv "${OVLROOT_FSTAB}" "${ROOTMNT}/${FSTAB_SYSTEM}" } diff --git a/overlayroot.conf b/overlayroot.conf new file mode 100644 index 000000000000..01ec8344a617 --- /dev/null +++ b/overlayroot.conf @@ -0,0 +1,43 @@ +# Copyright 2022 Tim Hildering + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# filesystems that can't be used as lower layer +#OVLROOT_FS_ROONLY="msdos,fat,vfat,iso9660,udf,ntfs-3g,ntfs3" + +# filesystems that are always ignored by overlayroot +#OVLROOT_FS_RAMONLY="tmpfs,devpts,devtmpfs,tracefs,debugfs,\ +#configfs,securityfs,proc,sysfs,swap,ramfs" + +# modified fstab created by overlayroot during initramfs phase +# to replace system-wide fstab +#OVLROOT_FSTAB="/tmp/overlayroot.fstab" + +# mountpoint for tmpfs filesystem +#OVLROOT_MAINDIR="/.overlay" + +# subdirectory of all lower filesystem mounts +#OVLROOT_LOWERDIR_NAME="ro" + +# subdirectory for all changes made to the filesystems +#OVLROOT_UPPERDIR_NAME="rw" + +# subdirectory needed by OverlayFS +#OVLROOT_WORKDIR_NAME="work" + +# system-wide fstab +#FSTAB_SYSTEM="/etc/fstab" + +# mountpoint of root filesystem in initramfs phase +#ROOTMNT="/new_root" |