From 4f4a377d7acb555193566db3ee459adc19e2e6a5 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Fri, 6 Apr 2018 18:40:09 +0200 Subject: Add VFS setup scripts Signed-off-by: David Oberhollenzer --- .gitignore | 8 ++++++++ Makefile.am | 7 +++++++ configure.ac | 7 +++++++ scripts/Makemodule.am | 2 ++ scripts/devfs.sh.in | 21 +++++++++++++++++++++ scripts/trymount.sh.in | 7 +++++++ services/Makemodule.am | 6 ++++-- services/devfs.in | 6 ++++++ services/hostname.in | 2 +- services/hwclock.in | 1 + services/loopback.in | 2 +- services/procfs.in | 7 +++++++ services/sysctl.in | 2 +- services/sysfs.in | 11 +++++++++++ services/tmpfs.in | 5 +++++ services/tmpfsrun.in | 8 ++++++++ services/vfs | 3 +++ 17 files changed, 100 insertions(+), 5 deletions(-) create mode 100644 scripts/Makemodule.am create mode 100644 scripts/devfs.sh.in create mode 100644 scripts/trymount.sh.in create mode 100644 services/devfs.in create mode 100644 services/procfs.in create mode 100644 services/sysfs.in create mode 100644 services/tmpfs.in create mode 100644 services/tmpfsrun.in create mode 100644 services/vfs diff --git a/.gitignore b/.gitignore index 7ee6330..2ad2130 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,11 @@ services/reboot services/sigkill services/sigterm services/sync +services/devfs +services/procfs +services/sysfs +services/tmpfs +services/tmpfsrun + +scripts/devfs.sh +scripts/trymount.sh diff --git a/Makefile.am b/Makefile.am index 31a9f35..cd45a47 100644 --- a/Makefile.am +++ b/Makefile.am @@ -13,6 +13,7 @@ helper_PROGRAMS = include lib/Makemodule.am include cmd/Makemodule.am include initd/Makemodule.am +include scripts/Makemodule.am include services/Makemodule.am include servicecmd/Makemodule.am @@ -22,6 +23,12 @@ install-data-local: $(LN_S) $(TEMPLATEDIR)/hostname $(DESTDIR)$(SVCDIR)/hostname $(LN_S) $(TEMPLATEDIR)/sysctl $(DESTDIR)$(SVCDIR)/sysctl $(LN_S) $(TEMPLATEDIR)/sysinit $(DESTDIR)$(SVCDIR)/sysinit + $(LN_S) $(TEMPLATEDIR)/procfs $(DESTDIR)$(SVCDIR)/procfs + $(LN_S) $(TEMPLATEDIR)/sysfs $(DESTDIR)$(SVCDIR)/sysfs + $(LN_S) $(TEMPLATEDIR)/devfs $(DESTDIR)$(SVCDIR)/devfs + $(LN_S) $(TEMPLATEDIR)/tmpfs $(DESTDIR)$(SVCDIR)/tmpfs + $(LN_S) $(TEMPLATEDIR)/tmpfsrun $(DESTDIR)$(SVCDIR)/tmpfsrun + $(LN_S) $(TEMPLATEDIR)/vfs $(DESTDIR)$(SVCDIR)/vfs $(LN_S) $(TEMPLATEDIR)/shutdown $(DESTDIR)$(SVCDIR)/shutdown $(LN_S) $(TEMPLATEDIR)/reboot $(DESTDIR)$(SVCDIR)/reboot $(LN_S) $(TEMPLATEDIR)/sync $(DESTDIR)$(SVCDIR)/sync@shutdown diff --git a/configure.ac b/configure.ac index 708b3fc..65921f2 100644 --- a/configure.ac +++ b/configure.ac @@ -29,5 +29,12 @@ AC_CONFIG_FILES([services/shutdown]) AC_CONFIG_FILES([services/sigkill]) AC_CONFIG_FILES([services/sigterm]) AC_CONFIG_FILES([services/sync]) +AC_CONFIG_FILES([services/sysfs]) +AC_CONFIG_FILES([services/devfs]) +AC_CONFIG_FILES([services/procfs]) +AC_CONFIG_FILES([services/tmpfs]) +AC_CONFIG_FILES([services/tmpfsrun]) +AC_CONFIG_FILES([scripts/devfs.sh]) +AC_CONFIG_FILES([scripts/trymount.sh]) AC_OUTPUT([Makefile]) diff --git a/scripts/Makemodule.am b/scripts/Makemodule.am new file mode 100644 index 0000000..e6de18d --- /dev/null +++ b/scripts/Makemodule.am @@ -0,0 +1,2 @@ +scriptdir = @SCRIPTDIR@ +script_SCRIPTS = scripts/devfs.sh scripts/trymount.sh diff --git a/scripts/devfs.sh.in b/scripts/devfs.sh.in new file mode 100644 index 0000000..a39d3ea --- /dev/null +++ b/scripts/devfs.sh.in @@ -0,0 +1,21 @@ +#!/bin/sh + +@SBINPATH@/mount -t devtmpfs none /dev + +[ -c /dev/console ] || @SBINPATH@/mknod -m 600 /dev/console c 5 1 +[ -c /dev/tty ] || @SBINPATH@/mknod -m 666 /dev/tty c 5 0 +[ -c /dev/null ] || @SBINPATH@/mknod -m 666 /dev/null c 1 3 +[ -c /dev/kmsg ] || @SBINPATH@/mknod -m 660 /dev/kmsg c 1 11 +[ -e /dev/fd ] || @BINPATH@/ln -snf /proc/self/fd /dev/fd +[ -e /dev/stdin ] || @BINPATH@/ln -snf /proc/self/fd/0 /dev/stdin +[ -e /dev/stdout ] || @BINPATH@/ln -snf /proc/self/fd/1 /dev/stdout +[ -e /dev/stderr ] || @BINPATH@/ln -snf /proc/self/fd/2 /dev/stderr +[ -e /proc/kcore ] && @BINPATH@/ln -snf /proc/kcore /dev/core + +@BINPATH@/mkdir -p /dev/mqueue -m 1777 +@BINPATH@/mkdir -p /dev/pts -m 0755 +@BINPATH@/mkdir -p /dev/shm -m 1777 + +@SCRIPTDIR@/trymount.sh "/dev/mqueue" "mqueue" "noexec,nosuid,nodev" +@SCRIPTDIR@/trymount.sh "/dev/pts" "devpts" "noexec,nosuid,gid=5,mode=0620" +@SCRIPTDIR@/trymount.sh "/dev/shm" "tmpfs" "noexec,nosuid,nodev,mode=1777" diff --git a/scripts/trymount.sh.in b/scripts/trymount.sh.in new file mode 100644 index 0000000..a382792 --- /dev/null +++ b/scripts/trymount.sh.in @@ -0,0 +1,7 @@ +#!/bin/sh + +if [ -d "$1" ]; then + if @BINPATH@/grep -qsE "[[:space:]]+$2$" "/proc/filesystems"; then + mount -n -t "$2" -o "$3" "$2" "$1" + fi +fi diff --git a/services/Makemodule.am b/services/Makemodule.am index c9eeeec..f2a15c8 100644 --- a/services/Makemodule.am +++ b/services/Makemodule.am @@ -2,6 +2,8 @@ initdir = @TEMPLATEDIR@ init_DATA = services/agetty services/hostname services/loopback init_DATA += services/sysctl services/hwclock services/sysinit init_DATA += services/reboot services/shutdown services/sigkill -init_DATA += services/sigterm services/sync +init_DATA += services/sigterm services/sync services/devfs +init_DATA += services/sysfs services/procfs services/tmpfs +init_DATA += services/tmpfsrun services/vfs -EXTRA_DIST += services/sysinit +EXTRA_DIST += services/sysinit services/vfs diff --git a/services/devfs.in b/services/devfs.in new file mode 100644 index 0000000..271eae7 --- /dev/null +++ b/services/devfs.in @@ -0,0 +1,6 @@ +description "mount /dev" +type wait +target boot +after procfs sysfs +before vfs +exec "@SCRIPTDIR@/devfs.sh" diff --git a/services/hostname.in b/services/hostname.in index 55b71d9..678e07e 100644 --- a/services/hostname.in +++ b/services/hostname.in @@ -3,4 +3,4 @@ exec "@BINPATH@/hostname" --file /etc/hostname type wait target boot before sysinit -after hwclock +after hwclock vfs diff --git a/services/hwclock.in b/services/hwclock.in index d07b3e7..af3a4e4 100644 --- a/services/hwclock.in +++ b/services/hwclock.in @@ -3,3 +3,4 @@ exec "@SBINPATH@/hwclock" --hctosys --utc type wait target boot before sysinit +after vfs diff --git a/services/loopback.in b/services/loopback.in index a01225a..f76bd42 100644 --- a/services/loopback.in +++ b/services/loopback.in @@ -2,7 +2,7 @@ description configure network loopback device type wait target boot before sysinit -after hwclock hostname +after hwclock hostname vfs exec "@SBINPATH@/ip" addr add 127.0.0.1/8 dev lo brd + exec "@SBINPATH@/ip" link set lo up diff --git a/services/procfs.in b/services/procfs.in new file mode 100644 index 0000000..76d479f --- /dev/null +++ b/services/procfs.in @@ -0,0 +1,7 @@ +description "mount /proc" +type wait +target boot +before vfs + +exec "@SBINPATH@/mount" -t proc proc /proc +exec "@SCRIPTDIR@/trymount.sh" "/proc/sys/fs/binfmt_misc" "binfmt_misc" "nodev,noexec,nosuid" diff --git a/services/sysctl.in b/services/sysctl.in index 2221480..e2e6eaa 100755 --- a/services/sysctl.in +++ b/services/sysctl.in @@ -3,4 +3,4 @@ exec "@SBINPATH@/sysctl" --system type wait target boot before sysinit -after hwclock hostname +after hwclock hostname vfs diff --git a/services/sysfs.in b/services/sysfs.in new file mode 100644 index 0000000..4c0f6ce --- /dev/null +++ b/services/sysfs.in @@ -0,0 +1,11 @@ +description "mount /sys" +type wait +target boot +after procfs +before vfs + +exec "@SBINPATH@/mount" -t sysfs sysfs /sys +exec "@SCRIPTDIR@/trymount.sh" "/sys/kernel/security" "securityfs" "nodev,noexec,nosuid" +exec "@SCRIPTDIR@/trymount.sh" "/sys/kernel/config" "configfs" "nodev,noexec,nosuid" +exec "@SCRIPTDIR@/trymount.sh" "/sys/fs/fuse/connections" "fusectl" "nodev,noexec,nosuid" +exec "@SCRIPTDIR@/trymount.sh" "/sys/firmware/efi/efivars" "efivarfs" "ro" diff --git a/services/tmpfs.in b/services/tmpfs.in new file mode 100644 index 0000000..1aa48cc --- /dev/null +++ b/services/tmpfs.in @@ -0,0 +1,5 @@ +description "mount /tmp" +type wait +target boot +before vfs +exec "@SBINPATH@/mount" -t tmpfs none /tmp diff --git a/services/tmpfsrun.in b/services/tmpfsrun.in new file mode 100644 index 0000000..d20e782 --- /dev/null +++ b/services/tmpfsrun.in @@ -0,0 +1,8 @@ +description "mount /run" +type wait +target boot +before vfs +exec "@SBINPATH@/mount" -t tmpfs none /run +exec "@BINPATH@/mkdir" /run/lock -m 0755 +exec "@BINPATH@/ln" -s /run /var/run +exec "@BINPATH@/ln" -s /run/lock /var/lock diff --git a/services/vfs b/services/vfs new file mode 100644 index 0000000..27cc9e9 --- /dev/null +++ b/services/vfs @@ -0,0 +1,3 @@ +description VFS setup done +type once +target boot -- cgit v1.2.3