xref: /freebsd/libexec/rc/rc.d/linux (revision e17f5b1d)
1#!/bin/sh
2#
3# $FreeBSD$
4#
5
6# PROVIDE: linux
7# REQUIRE: archdep
8# KEYWORD: nojail
9
10. /etc/rc.subr
11
12name="linux"
13desc="Enable Linux ABI"
14rcvar="linux_enable"
15start_cmd="${name}_start"
16stop_cmd=":"
17
18linux_start()
19{
20	local _emul_path _tmpdir
21
22	load_kld -e 'linux(aout|elf)' linux
23	case `sysctl -n hw.machine_arch` in
24	amd64)
25		load_kld -e 'linux64elf' linux64
26		;;
27	esac
28	if [ -x /compat/linux/sbin/ldconfigDisabled ]; then
29		_tmpdir=`mktemp -d -t linux-ldconfig`
30		/compat/linux/sbin/ldconfig -C ${_tmpdir}/ld.so.cache
31		if ! cmp -s ${_tmpdir}/ld.so.cache /compat/linux/etc/ld.so.cache; then
32			cat ${_tmpdir}/ld.so.cache > /compat/linux/etc/ld.so.cache
33		fi
34		rm -rf ${_tmpdir}
35	fi
36
37	# Linux uses the pre-pts(4) tty naming scheme.
38	load_kld pty
39
40	# Handle unbranded ELF executables by defaulting to ELFOSABI_LINUX.
41	if [ `sysctl -ni kern.elf64.fallback_brand` -eq "-1" ]; then
42		sysctl kern.elf64.fallback_brand=3 > /dev/null
43	fi
44
45	if [ `sysctl -ni kern.elf32.fallback_brand` -eq "-1" ]; then
46		sysctl kern.elf32.fallback_brand=3 > /dev/null
47	fi
48
49	if checkyesno linux_mounts_enable; then
50		_emul_path="/compat/linux"
51		mount -o nocover -t linprocfs linprocfs "${_emul_path}/proc"
52		mount -o nocover -t linsysfs linsysfs "${_emul_path}/sys"
53		mount -o nocover -t devfs devfs "${_emul_path}/dev"
54		mount -o nocover,linrdlnk -t fdescfs fdescfs "${_emul_path}/dev/fd"
55		mount -o nocover,mode=1777 -t tmpfs tmpfs "${_emul_path}/dev/shm"
56	fi
57}
58
59load_rc_config $name
60run_rc_command "$1"
61