Permalink
Browse files

Support additional binary formats at boot

This patch mount kernel binfmt_misc filesystem at boot and allow loading of
a default configuration inspired from systemd binfmt.d way.

Signed-off-by: Sébastien Luttringer <seblu@seblu.net>
  • Loading branch information...
seblu committed Mar 12, 2012
1 parent 299c22a commit 788daea5db4445f02fc156132f00829e1107dc6f
Showing with 46 additions and 2 deletions.
  1. +3 −1 Makefile
  2. +36 −0 arch-binfmt
  3. +3 −0 rc.multi
  4. +4 −1 rc.sysinit
View
@@ -8,6 +8,8 @@ DIRS := \
/usr/sbin \
/etc/tmpfiles.d \
/usr/lib/tmpfiles.d \
+ /etc/binfmt.d \
+ /usr/lib/binfmt.d \
/etc/sysctl.d \
/usr/lib/sysctl.d \
/usr/lib/initscripts \
@@ -31,7 +33,7 @@ install: installdirs doc
install -m755 -t $(DESTDIR)/usr/sbin rc.d
install -m644 -t ${DESTDIR}/usr/share/man/man8 rc.d.8
install -m644 -t ${DESTDIR}/usr/share/man/man5 rc.conf.5 locale.conf.5 vconsole.conf.5 hostname.5
- install -m755 -t $(DESTDIR)/usr/lib/initscripts arch-tmpfiles arch-sysctl
+ install -m755 -t $(DESTDIR)/usr/lib/initscripts arch-tmpfiles arch-sysctl arch-binfmt
install -m644 tmpfiles.conf $(DESTDIR)/usr/lib/tmpfiles.d/arch.conf
install -m644 -T bash-completion $(DESTDIR)/etc/bash_completion.d/rc.d
install -m644 -T zsh-completion $(DESTDIR)/usr/share/zsh/site-functions/_rc.d
View
@@ -0,0 +1,36 @@
+#!/bin/bash
+#
+# /usr/lib/initscripts/arch-binfmt
+#
+# Configure additional binary formats at boot
+#
+
+shopt -s nullglob
+
+declare -a binfmt_d=(
+ /usr/lib/binfmt.d/*.conf
+ /etc/binfmt.d/*.conf
+ /run/binfmt.d/*.conf
+)
+declare -A fragments
+
+# check binfmt_misc filesystem is mounted
+mountpoint -q /proc/sys/fs/binfmt_misc ||
+ { echo "/proc/sys/fs/binfmt_misc is not mounted"; exit 1;}
+
+# files declared later in the sysctl_d array will override earlier
+# Example: `/etc/sysctl.d/foo.conf' supersedes `/usr/lib/sysctl.d/foo.conf'.
+for path in "${@:-${binfmt_d[@]}}"; do
+ [[ -f $path ]] && fragments[${path##*/}]=$path
+done
+
+for path in "${fragments[@]}"; do
+ while read -r line; do
+ [[ ${line:0:1} == '#' ]] && continue
+ printf "%s" "$line" > /proc/sys/fs/binfmt_misc/register
+ done < "$path"
+done
+
+:
+
+# vim: set ts=2 sw=2 noet:
View
@@ -11,6 +11,9 @@ run_hook multi_start
# Load sysctl config files
[[ -x /usr/lib/initscripts/arch-sysctl ]] && /usr/lib/initscripts/arch-sysctl
+# Load additional binary formats
+[[ -x /usr/lib/initscripts/arch-binfmt ]] && /usr/lib/initscripts/arch-binfmt
+
# Start daemons
for daemon in "${DAEMONS[@]}"; do
case ${daemon:0:1} in
View
@@ -11,8 +11,11 @@ printhl "Arch Linux\n"
printhl "${C_H2}http://www.archlinux.org"
printsep
-# mount /proc, /sys, /run, /dev, /run/lock, /dev/pts, /dev/shm (the api filesystems)
+# mount the api filesystems
+# /proc, /proc/sys/fs/binfmt_misc, /sys, /run, /dev, /run/lock, /dev/pts, /dev/shm
mountpoint -q /proc || mount -t proc proc /proc -o nosuid,noexec,nodev
+mountpoint -q /proc/sys/fs/binfmt_misc ||
+ mount -t binfmt_misc binfmt /proc/sys/fs/binfmt_misc
mountpoint -q /sys || mount -t sysfs sys /sys -o nosuid,noexec,nodev
mountpoint -q /run || mount -t tmpfs run /run -o mode=0755,nosuid,nodev
mountpoint -q /dev || mount -t devtmpfs dev /dev -o mode=0755,nosuid

0 comments on commit 788daea

Please sign in to comment.