xref: /freebsd-13.1/libexec/rc/rc.d/linux (revision 0bf6e572)
1028af4aeSEdward Tomasz Napierala#!/bin/sh
2028af4aeSEdward Tomasz Napierala#
3028af4aeSEdward Tomasz Napierala# $FreeBSD$
4028af4aeSEdward Tomasz Napierala#
5028af4aeSEdward Tomasz Napierala
6028af4aeSEdward Tomasz Napierala# PROVIDE: linux
7028af4aeSEdward Tomasz Napierala# REQUIRE: archdep
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
18*0bf6e572SMateusz Piotrowskilinux_mount() {
19*0bf6e572SMateusz Piotrowski	local _fs _mount_point
20*0bf6e572SMateusz Piotrowski	_fs="$1"
21*0bf6e572SMateusz Piotrowski	_mount_point="$2"
22*0bf6e572SMateusz Piotrowski	shift 2
23*0bf6e572SMateusz Piotrowski	if ! mount | grep -q "^$_fs on $_mount_point ("; then
24*0bf6e572SMateusz Piotrowski		mkdir -p "$_mount_point"
25*0bf6e572SMateusz Piotrowski		mount "$@" -t "$_fs" "$_fs" "$_mount_point"
26*0bf6e572SMateusz Piotrowski	fi
27*0bf6e572SMateusz Piotrowski}
28*0bf6e572SMateusz Piotrowski
29028af4aeSEdward Tomasz Napieralalinux_start()
30028af4aeSEdward Tomasz Napierala{
31c13f19c0SEdward Tomasz Napierala	local _emul_path _tmpdir
32028af4aeSEdward Tomasz Napierala
33028af4aeSEdward Tomasz Napierala	case `sysctl -n hw.machine_arch` in
34933cb282SEdward Tomasz Napierala	aarch64)
35028af4aeSEdward Tomasz Napierala		load_kld -e 'linux64elf' linux64
36028af4aeSEdward Tomasz Napierala		;;
37933cb282SEdward Tomasz Napierala	amd64)
38933cb282SEdward Tomasz Napierala		load_kld -e 'linuxelf' linux
39933cb282SEdward Tomasz Napierala		load_kld -e 'linux64elf' linux64
40933cb282SEdward Tomasz Napierala		;;
41933cb282SEdward Tomasz Napierala	i386)
42933cb282SEdward Tomasz Napierala		load_kld -e 'linuxelf' linux
43933cb282SEdward Tomasz Napierala		;;
44028af4aeSEdward Tomasz Napierala	esac
455dc2e1bcSEdward Tomasz Napierala
465dc2e1bcSEdward Tomasz Napierala	_emul_path="$(sysctl -n compat.linux.emul_path)"
475dc2e1bcSEdward Tomasz Napierala
481b2802edSEdward Tomasz Napierala	if [ -x ${_emul_path}/sbin/ldconfigDisabled ]; then
49028af4aeSEdward Tomasz Napierala		_tmpdir=`mktemp -d -t linux-ldconfig`
501b2802edSEdward Tomasz Napierala		${_emul_path}/sbin/ldconfig -C ${_tmpdir}/ld.so.cache
511b2802edSEdward Tomasz Napierala		if ! cmp -s ${_tmpdir}/ld.so.cache ${_emul_path}/etc/ld.so.cache; then
521b2802edSEdward Tomasz Napierala			cat ${_tmpdir}/ld.so.cache > ${_emul_path}/etc/ld.so.cache
53028af4aeSEdward Tomasz Napierala		fi
54028af4aeSEdward Tomasz Napierala		rm -rf ${_tmpdir}
55028af4aeSEdward Tomasz Napierala	fi
56c13f19c0SEdward Tomasz Napierala
57c13f19c0SEdward Tomasz Napierala	# Linux uses the pre-pts(4) tty naming scheme.
58c13f19c0SEdward Tomasz Napierala	load_kld pty
59c13f19c0SEdward Tomasz Napierala
602ffd6857SEdward Tomasz Napierala	# Explicitly load the filesystem modules; they are usually required,
612ffd6857SEdward Tomasz Napierala	# even with linux_mounts_enable="NO".
622ffd6857SEdward Tomasz Napierala	load_kld fdescfs
632ffd6857SEdward Tomasz Napierala	load_kld linprocfs
642ffd6857SEdward Tomasz Napierala	load_kld linsysfs
652ffd6857SEdward Tomasz Napierala
66c13f19c0SEdward Tomasz Napierala	# Handle unbranded ELF executables by defaulting to ELFOSABI_LINUX.
67c13f19c0SEdward Tomasz Napierala	if [ `sysctl -ni kern.elf64.fallback_brand` -eq "-1" ]; then
68c13f19c0SEdward Tomasz Napierala		sysctl kern.elf64.fallback_brand=3 > /dev/null
69c13f19c0SEdward Tomasz Napierala	fi
70c13f19c0SEdward Tomasz Napierala
71c13f19c0SEdward Tomasz Napierala	if [ `sysctl -ni kern.elf32.fallback_brand` -eq "-1" ]; then
72c13f19c0SEdward Tomasz Napierala		sysctl kern.elf32.fallback_brand=3 > /dev/null
73c13f19c0SEdward Tomasz Napierala	fi
74c13f19c0SEdward Tomasz Napierala
755dece9b2SEdward Tomasz Napierala	if checkyesno linux_mounts_enable; then
76*0bf6e572SMateusz Piotrowski		linux_mount linprocfs "${_emul_path}/proc" -o nocover
77*0bf6e572SMateusz Piotrowski		linux_mount linsysfs "${_emul_path}/sys" -o nocover
78*0bf6e572SMateusz Piotrowski		linux_mount devfs "${_emul_path}/dev" -o nocover
79*0bf6e572SMateusz Piotrowski		linux_mount fdescfs "${_emul_path}/dev/fd" -o nocover,linrdlnk
80*0bf6e572SMateusz Piotrowski		linux_mount tmpfs "${_emul_path}/dev/shm" -o nocover,mode=1777
815dece9b2SEdward Tomasz Napierala	fi
82028af4aeSEdward Tomasz Napierala}
83028af4aeSEdward Tomasz Napierala
84028af4aeSEdward Tomasz Napieralaload_rc_config $name
85028af4aeSEdward Tomasz Napieralarun_rc_command "$1"
86