Edward Tomasz Napierala 45aec46246 rc: make the 'linux' script explicitly load filesystem modules
This removes a minor annoyance with Linux jails, where you often
want linux_mounts_enable="NO", yet you want those filesystems
available for mounting in jails; normally mount(8) would result
in kernel automatically loading the KLD, but this doesn't work
inside jails or chroots.

PR:		242955
Sponsored By:	EPSRC
Differential Revision:	https://reviews.freebsd.org/D29725
2021-04-21 12:54:37 +01:00

75 lines
1.7 KiB
Bash
Executable File

#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: linux
# REQUIRE: kldxref
# KEYWORD: nojail
. /etc/rc.subr
name="linux"
desc="Enable Linux ABI"
rcvar="linux_enable"
start_cmd="${name}_start"
stop_cmd=":"
linux_start()
{
local _emul_path _tmpdir
case `sysctl -n hw.machine_arch` in
aarch64)
load_kld -e 'linux64elf' linux64
;;
amd64)
load_kld -e 'linuxelf' linux
load_kld -e 'linux64elf' linux64
;;
i386)
load_kld -e 'linuxelf' linux
;;
esac
_emul_path="$(sysctl -n compat.linux.emul_path)"
if [ -x ${_emul_path}/sbin/ldconfigDisabled ]; then
_tmpdir=`mktemp -d -t linux-ldconfig`
${_emul_path}/sbin/ldconfig -C ${_tmpdir}/ld.so.cache
if ! cmp -s ${_tmpdir}/ld.so.cache ${_emul_path}/etc/ld.so.cache; then
cat ${_tmpdir}/ld.so.cache > ${_emul_path}/etc/ld.so.cache
fi
rm -rf ${_tmpdir}
fi
# Linux uses the pre-pts(4) tty naming scheme.
load_kld pty
# Explicitly load the filesystem modules; they are usually required,
# even with linux_mounts_enable="NO".
load_kld fdescfs
load_kld linprocfs
load_kld linsysfs
# Handle unbranded ELF executables by defaulting to ELFOSABI_LINUX.
if [ `sysctl -ni kern.elf64.fallback_brand` -eq "-1" ]; then
sysctl kern.elf64.fallback_brand=3 > /dev/null
fi
if [ `sysctl -ni kern.elf32.fallback_brand` -eq "-1" ]; then
sysctl kern.elf32.fallback_brand=3 > /dev/null
fi
if checkyesno linux_mounts_enable; then
mount -o nocover -t linprocfs linprocfs "${_emul_path}/proc"
mount -o nocover -t linsysfs linsysfs "${_emul_path}/sys"
mount -o nocover -t devfs devfs "${_emul_path}/dev"
mount -o nocover,linrdlnk -t fdescfs fdescfs "${_emul_path}/dev/fd"
mount -o nocover,mode=1777 -t tmpfs tmpfs "${_emul_path}/dev/shm"
fi
}
load_rc_config $name
run_rc_command "$1"