xref: /freebsd/libexec/rc/rc.d/linux (revision 45aec46246fe61a3f45cf7da1c80850dc226f609)
1028af4aeSEdward Tomasz Napierala#!/bin/sh
2028af4aeSEdward Tomasz Napierala#
3028af4aeSEdward Tomasz Napierala# $FreeBSD$
4028af4aeSEdward Tomasz Napierala#
5028af4aeSEdward Tomasz Napierala
6028af4aeSEdward Tomasz Napierala# PROVIDE: linux
782431b75SEdward Tomasz Napierala# REQUIRE: kldxref
8028af4aeSEdward Tomasz Napierala# KEYWORD: nojail
9028af4aeSEdward Tomasz Napierala
10028af4aeSEdward Tomasz Napierala. /etc/rc.subr
11028af4aeSEdward Tomasz Napierala
12028af4aeSEdward Tomasz Napieralaname="linux"
13028af4aeSEdward Tomasz Napieraladesc="Enable Linux ABI"
14ee0ee18cSEdward Tomasz Napieralarcvar="linux_enable"
15028af4aeSEdward Tomasz Napieralastart_cmd="${name}_start"
16028af4aeSEdward Tomasz Napieralastop_cmd=":"
17028af4aeSEdward Tomasz Napierala
18028af4aeSEdward Tomasz Napieralalinux_start()
19028af4aeSEdward Tomasz Napierala{
20c13f19c0SEdward Tomasz Napierala	local _emul_path _tmpdir
21028af4aeSEdward Tomasz Napierala
22028af4aeSEdward Tomasz Napierala	case `sysctl -n hw.machine_arch` in
23e026f424SEdward Tomasz Napierala	aarch64)
24028af4aeSEdward Tomasz Napierala		load_kld -e 'linux64elf' linux64
25028af4aeSEdward Tomasz Napierala		;;
26e026f424SEdward Tomasz Napierala	amd64)
27e026f424SEdward Tomasz Napierala		load_kld -e 'linuxelf' linux
28e026f424SEdward Tomasz Napierala		load_kld -e 'linux64elf' linux64
29e026f424SEdward Tomasz Napierala		;;
30e026f424SEdward Tomasz Napierala	i386)
31e026f424SEdward Tomasz Napierala		load_kld -e 'linuxelf' linux
32e026f424SEdward Tomasz Napierala		;;
33028af4aeSEdward Tomasz Napierala	esac
3407cac176SEdward Tomasz Napierala
3507cac176SEdward Tomasz Napierala	_emul_path="$(sysctl -n compat.linux.emul_path)"
3607cac176SEdward Tomasz Napierala
37e40787f9SEdward Tomasz Napierala	if [ -x ${_emul_path}/sbin/ldconfigDisabled ]; then
38028af4aeSEdward Tomasz Napierala		_tmpdir=`mktemp -d -t linux-ldconfig`
39e40787f9SEdward Tomasz Napierala		${_emul_path}/sbin/ldconfig -C ${_tmpdir}/ld.so.cache
40e40787f9SEdward Tomasz Napierala		if ! cmp -s ${_tmpdir}/ld.so.cache ${_emul_path}/etc/ld.so.cache; then
41e40787f9SEdward Tomasz Napierala			cat ${_tmpdir}/ld.so.cache > ${_emul_path}/etc/ld.so.cache
42028af4aeSEdward Tomasz Napierala		fi
43028af4aeSEdward Tomasz Napierala		rm -rf ${_tmpdir}
44028af4aeSEdward Tomasz Napierala	fi
45c13f19c0SEdward Tomasz Napierala
46c13f19c0SEdward Tomasz Napierala	# Linux uses the pre-pts(4) tty naming scheme.
47c13f19c0SEdward Tomasz Napierala	load_kld pty
48c13f19c0SEdward Tomasz Napierala
49*45aec462SEdward Tomasz Napierala	# Explicitly load the filesystem modules; they are usually required,
50*45aec462SEdward Tomasz Napierala	# even with linux_mounts_enable="NO".
51*45aec462SEdward Tomasz Napierala	load_kld fdescfs
52*45aec462SEdward Tomasz Napierala	load_kld linprocfs
53*45aec462SEdward Tomasz Napierala	load_kld linsysfs
54*45aec462SEdward Tomasz Napierala
55c13f19c0SEdward Tomasz Napierala	# Handle unbranded ELF executables by defaulting to ELFOSABI_LINUX.
56c13f19c0SEdward Tomasz Napierala	if [ `sysctl -ni kern.elf64.fallback_brand` -eq "-1" ]; then
57c13f19c0SEdward Tomasz Napierala		sysctl kern.elf64.fallback_brand=3 > /dev/null
58c13f19c0SEdward Tomasz Napierala	fi
59c13f19c0SEdward Tomasz Napierala
60c13f19c0SEdward Tomasz Napierala	if [ `sysctl -ni kern.elf32.fallback_brand` -eq "-1" ]; then
61c13f19c0SEdward Tomasz Napierala		sysctl kern.elf32.fallback_brand=3 > /dev/null
62c13f19c0SEdward Tomasz Napierala	fi
63c13f19c0SEdward Tomasz Napierala
645dece9b2SEdward Tomasz Napierala	if checkyesno linux_mounts_enable; then
65c13f19c0SEdward Tomasz Napierala		mount -o nocover -t linprocfs linprocfs "${_emul_path}/proc"
66c13f19c0SEdward Tomasz Napierala		mount -o nocover -t linsysfs linsysfs "${_emul_path}/sys"
67c13f19c0SEdward Tomasz Napierala		mount -o nocover -t devfs devfs "${_emul_path}/dev"
686ef8f9d2SEdward Tomasz Napierala		mount -o nocover,linrdlnk -t fdescfs fdescfs "${_emul_path}/dev/fd"
69c13f19c0SEdward Tomasz Napierala		mount -o nocover,mode=1777 -t tmpfs tmpfs "${_emul_path}/dev/shm"
705dece9b2SEdward Tomasz Napierala	fi
71028af4aeSEdward Tomasz Napierala}
72028af4aeSEdward Tomasz Napierala
73028af4aeSEdward Tomasz Napieralaload_rc_config $name
74028af4aeSEdward Tomasz Napieralarun_rc_command "$1"
75