xref: /freebsd/libexec/rc/rc.d/linux (revision 5e3190f700637fcfc1a52daeaa4a031fdd2557c7)
1#!/bin/sh
2#
3#
4
5# PROVIDE: linux
6# REQUIRE: kldxref zfs
7# KEYWORD: nojail
8
9. /etc/rc.subr
10
11name="linux"
12desc="Enable Linux ABI"
13rcvar="linux_enable"
14start_cmd="${name}_start"
15stop_cmd=":"
16
17linux_mount() {
18	local _fs _mount_point
19	_fs="$1"
20	_mount_point="$2"
21	shift 2
22	if ! mount | grep -q "^$_fs on $_mount_point ("; then
23		mkdir -p "$_mount_point"
24		mount "$@" -t "$_fs" "$_fs" "$_mount_point"
25	fi
26}
27
28linux_start()
29{
30	local _emul_path _tmpdir
31
32	case `sysctl -n hw.machine_arch` in
33	aarch64)
34		load_kld -e 'linux64elf' linux64
35		;;
36	amd64)
37		load_kld -e 'linuxelf' linux
38		load_kld -e 'linux64elf' linux64
39		;;
40	i386)
41		load_kld -e 'linuxelf' linux
42		;;
43	esac
44
45	_emul_path="$(sysctl -n compat.linux.emul_path)"
46
47	if [ -x ${_emul_path}/sbin/ldconfigDisabled ]; then
48		_tmpdir=`mktemp -d -t linux-ldconfig`
49		${_emul_path}/sbin/ldconfig -C ${_tmpdir}/ld.so.cache
50		if ! cmp -s ${_tmpdir}/ld.so.cache ${_emul_path}/etc/ld.so.cache; then
51			cat ${_tmpdir}/ld.so.cache > ${_emul_path}/etc/ld.so.cache
52		fi
53		rm -rf ${_tmpdir}
54	fi
55
56	# Linux uses the pre-pts(4) tty naming scheme.
57	load_kld pty
58
59	# Explicitly load the filesystem modules; they are usually required,
60	# even with linux_mounts_enable="NO".
61	load_kld fdescfs
62	load_kld linprocfs
63	load_kld linsysfs
64
65	# Handle unbranded ELF executables by defaulting to ELFOSABI_LINUX.
66	if [ `sysctl -ni kern.elf64.fallback_brand` -eq "-1" ]; then
67		sysctl kern.elf64.fallback_brand=3 > /dev/null
68	fi
69
70	if [ `sysctl -ni kern.elf32.fallback_brand` -eq "-1" ]; then
71		sysctl kern.elf32.fallback_brand=3 > /dev/null
72	fi
73
74	if checkyesno linux_mounts_enable; then
75		linux_mount linprocfs "${_emul_path}/proc" -o nocover
76		linux_mount linsysfs "${_emul_path}/sys" -o nocover
77		linux_mount devfs "${_emul_path}/dev" -o nocover
78		linux_mount fdescfs "${_emul_path}/dev/fd" -o nocover,linrdlnk
79		linux_mount tmpfs "${_emul_path}/dev/shm" -o nocover,mode=1777
80	fi
81}
82
83load_rc_config $name
84run_rc_command "$1"
85