From aa0822166662256d511eb6588af2928f50e104e4 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Wed, 22 Apr 2020 20:08:52 +0200 Subject: [PATCH] configure: Remove --enable-rw-rootfs detect using /etc/fstab instead This patch removes the --enable-rw-rootfs build flag. Like OpenRC we now check /etc/fstab instad; if `/` is listed *and* doesn't have the `ro` flag set, we remount / read-write. Signed-off-by: Joachim Nilsson --- configure.ac | 8 -------- contrib/alpine/build.sh | 2 +- contrib/debian/build.sh | 2 +- contrib/void/build.sh | 2 +- docs/bootstrap.md | 2 +- docs/build.md | 7 +------ src/finit.c | 30 +++++++++++++++++++++++++----- 7 files changed, 30 insertions(+), 23 deletions(-) diff --git a/configure.ac b/configure.ac index f6ccc563..f38fecd3 100644 --- a/configure.ac +++ b/configure.ac @@ -61,10 +61,6 @@ AC_ARG_ENABLE(auto_reload, AS_HELP_STRING([--enable-auto-reload], [Automatic reload on any .conf change]),,[ enable_auto_reload=no]) -AC_ARG_ENABLE(rw-rootfs, - AS_HELP_STRING([--enable-rw-rootfs], [Remount / R/W at boot, usually not for embedded]),,[ - enable_rw_rootfs=no]) - AC_ARG_ENABLE(progress, AS_HELP_STRING([--enable-progress], [Modern progress display at bootup]),,[ enable_progress=no]) @@ -164,9 +160,6 @@ AS_IF([test "x$enable_fallback_shell" = "xyes"], [ AS_IF([test "x$enable_auto_reload" = "xyes"], [ AC_DEFINE(AUTO_RELOAD, 1, [Finit automatically does `initctl reload` on any .conf change])]) -AS_IF([test "x$enable_rw_rootfs" = "xyes"], [ - AC_DEFINE(REMOUNT_ROOTFS, 1, [Remount / as rw at boot])]) - AS_IF([test "x$enable_progress" = "xyes"], [ AC_DEFINE(PROGRESS_STYLE, 2, [Modern bootup messages, systemd inspired])]) @@ -301,7 +294,6 @@ Optional features: Scripting tool logit..: $enable_logit Emergency shell.......: $enable_emergency_shell Fallback shell........: $enable_fallback_shell - Remount / RW at boot..: $enable_rw_rootfs Modern progress.......: $enable_progress Classic progress......: $enable_progress_classic Default console dev...: $console diff --git a/contrib/alpine/build.sh b/contrib/alpine/build.sh index 4f4adac0..8905ad84 100755 --- a/contrib/alpine/build.sh +++ b/contrib/alpine/build.sh @@ -14,7 +14,7 @@ fi # The plugins are optional, but you may need D-Bus and X11 if you want # to run X-Window, the other configure flags are however required. PKG_CONFIG_LIBDIR=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig ./configure \ - --enable-rw-rootfs --enable-progress \ + --enable-progress \ --enable-dbus-plugin --enable-x11-common-plugin \ --enable-alsa-utils-plugin --enable-inetd-echo-plugin \ --enable-inetd-chargen-plugin --enable-inetd-daytime-plugin \ diff --git a/contrib/debian/build.sh b/contrib/debian/build.sh index 280bb569..b3e75afa 100755 --- a/contrib/debian/build.sh +++ b/contrib/debian/build.sh @@ -22,7 +22,7 @@ echo # The plugins are optional, but you may need D-Bus and X11 if you want # to run X-Window, the other configure flags are however required. ./configure \ - --enable-rw-rootfs --enable-progress \ + --enable-progress \ --enable-dbus-plugin --enable-x11-common-plugin \ --enable-alsa-utils-plugin --enable-inetd-echo-plugin \ --enable-inetd-chargen-plugin --enable-inetd-daytime-plugin \ diff --git a/contrib/void/build.sh b/contrib/void/build.sh index 763a605c..9baa2c37 100755 --- a/contrib/void/build.sh +++ b/contrib/void/build.sh @@ -14,7 +14,7 @@ fi # The plugins are optional, but you may need D-Bus and X11 if you want # to run X-Window, the other configure flags are however required. PKG_CONFIG_LIBDIR=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig ./configure \ - --enable-rw-rootfs --enable-progress \ + --enable-progress \ --enable-dbus-plugin --enable-x11-common-plugin \ --enable-alsa-utils-plugin --enable-inetd-echo-plugin \ --enable-inetd-chargen-plugin --enable-inetd-daytime-plugin \ diff --git a/docs/bootstrap.md b/docs/bootstrap.md index a4c9d1f9..ea71e9e5 100644 --- a/docs/bootstrap.md +++ b/docs/bootstrap.md @@ -12,7 +12,7 @@ Bootstrap 9. Parse `/etc/finit.conf` and all `/etc/finit.d/*.conf` files 10. Start built-in watchdog, if enabled 11. Set hostname -12. Pivot root, or remount `/` read-write, depending on system type +12. Remount `/` read-write if `/` is listed in `/etc/fstab` without `ro` 13. Call 1st level hooks, `HOOK_ROOTFS_UP` 14. Mount all file systems listed in `/etc/fstab` and swap, if available 15. Enable SysV init signals diff --git a/docs/build.md b/docs/build.md index e6b6becf..69661126 100644 --- a/docs/build.md +++ b/docs/build.md @@ -40,11 +40,6 @@ Below are a few of the main switches to configure: * `--disable-inetd`: Disable the built-in inetd server. -* `--enable-rw-rootfs`: Most desktop and server systems boot with the - root file stystem read-only. With this setting Finit will remount it - as read-write early at boot so the `bootmisc.so` plugin can run. - Usually not needed on embedded systems. - * `--enable-static`: Build Finit statically. The plugins will be built-ins (.o files) and all external libraries, except the C library will be linked statically. @@ -73,7 +68,7 @@ First, unpack the archive: Then configure, build and install: ```shell - $ ./configure --enable-rw-rootfs --enable-inetd-echo-plugin \ + $ ./configure --enable-inetd-echo-plugin \ --enable-inetd-chargen-plugin --enable-inetd-daytime-plugin \ --enable-inetd-discard-plugin --enable-inetd-time-plugin \ --with-heading="Alpine Linux 3.4" --with-hostname=alpine diff --git a/src/finit.c b/src/finit.c index cf245da1..9f589b2d 100644 --- a/src/finit.c +++ b/src/finit.c @@ -433,7 +433,7 @@ int main(int argc, char *argv[]) */ makedir("/dev/shm", 0755); if (!fismnt("/dev/shm") && !ismnt("/etc/fstab", "/dev/shm")) - mount("shm", "/dev/shm", "tmpfs", 0, NULL); + mount("shm", "/dev/shm", "tmpfs", 0, "mode=0777"); /* * New tmpfs based /run for volatile runtime data @@ -498,10 +498,30 @@ int main(int argc, char *argv[]) * Mount filesystems */ if (!rescue) { -#ifdef REMOUNT_ROOTFS - run("mount -n -o remount,rw /"); -#endif -#ifdef SYSROOT +#ifndef SYSROOT + /* + * Remount / read-write if it exists in fstab is not 'ro'. + * This is what the Debian sysv initscripts does. + */ + if (setfsent()) { + struct fstab *fs; + + while ((fs = getfsent())) { + if (strcmp(fs->fs_file, "/")) + continue; + + if (strcmp(fs->fs_type, "ro")) + run_interactive("mount -n -o remount,rw /", "Remounting / as read-write"); + break; + } + + endfsent(); + } +#else + /* + * XXX: Untested, in the initramfs age we should + * probably use switch_root instead. + */ mount(SYSROOT, "/", NULL, MS_MOVE, NULL); #endif }