1028af4aeSEdward Tomasz Napierala#!/bin/sh 2028af4aeSEdward Tomasz Napierala# 3028af4aeSEdward Tomasz Napierala# 4028af4aeSEdward Tomasz Napierala 5028af4aeSEdward Tomasz Napierala# PROVIDE: linux 66f62e3a7SXin LI# REQUIRE: kldxref zfs 7028af4aeSEdward Tomasz Napierala# KEYWORD: nojail 8028af4aeSEdward Tomasz Napierala 9028af4aeSEdward Tomasz Napierala. /etc/rc.subr 10028af4aeSEdward Tomasz Napierala 11028af4aeSEdward Tomasz Napieralaname="linux" 12028af4aeSEdward Tomasz Napieraladesc="Enable Linux ABI" 13ee0ee18cSEdward Tomasz Napieralarcvar="linux_enable" 14028af4aeSEdward Tomasz Napieralastart_cmd="${name}_start" 15028af4aeSEdward Tomasz Napieralastop_cmd=":" 16028af4aeSEdward Tomasz Napierala 1756902618SMateusz Piotrowskilinux_mount() { 1856902618SMateusz Piotrowski local _fs _mount_point 1956902618SMateusz Piotrowski _fs="$1" 2056902618SMateusz Piotrowski _mount_point="$2" 2156902618SMateusz Piotrowski shift 2 2256902618SMateusz Piotrowski if ! mount | grep -q "^$_fs on $_mount_point ("; then 2356902618SMateusz Piotrowski mkdir -p "$_mount_point" 2456902618SMateusz Piotrowski mount "$@" -t "$_fs" "$_fs" "$_mount_point" 2556902618SMateusz Piotrowski fi 2656902618SMateusz Piotrowski} 2756902618SMateusz Piotrowski 28028af4aeSEdward Tomasz Napieralalinux_start() 29028af4aeSEdward Tomasz Napierala{ 30c13f19c0SEdward Tomasz Napierala local _emul_path _tmpdir 31028af4aeSEdward Tomasz Napierala 32028af4aeSEdward Tomasz Napierala case `sysctl -n hw.machine_arch` in 33e026f424SEdward Tomasz Napierala aarch64) 34028af4aeSEdward Tomasz Napierala load_kld -e 'linux64elf' linux64 35028af4aeSEdward Tomasz Napierala ;; 36e026f424SEdward Tomasz Napierala amd64) 37e026f424SEdward Tomasz Napierala load_kld -e 'linuxelf' linux 38e026f424SEdward Tomasz Napierala load_kld -e 'linux64elf' linux64 39e026f424SEdward Tomasz Napierala ;; 40e026f424SEdward Tomasz Napierala i386) 41e026f424SEdward Tomasz Napierala load_kld -e 'linuxelf' linux 42e026f424SEdward Tomasz Napierala ;; 43028af4aeSEdward Tomasz Napierala esac 4407cac176SEdward Tomasz Napierala 4507cac176SEdward Tomasz Napierala _emul_path="$(sysctl -n compat.linux.emul_path)" 4607cac176SEdward Tomasz Napierala 47e40787f9SEdward Tomasz Napierala if [ -x ${_emul_path}/sbin/ldconfigDisabled ]; then 48028af4aeSEdward Tomasz Napierala _tmpdir=`mktemp -d -t linux-ldconfig` 49e40787f9SEdward Tomasz Napierala ${_emul_path}/sbin/ldconfig -C ${_tmpdir}/ld.so.cache 50e40787f9SEdward Tomasz Napierala if ! cmp -s ${_tmpdir}/ld.so.cache ${_emul_path}/etc/ld.so.cache; then 51e40787f9SEdward Tomasz Napierala cat ${_tmpdir}/ld.so.cache > ${_emul_path}/etc/ld.so.cache 52028af4aeSEdward Tomasz Napierala fi 53028af4aeSEdward Tomasz Napierala rm -rf ${_tmpdir} 54028af4aeSEdward Tomasz Napierala fi 55c13f19c0SEdward Tomasz Napierala 56c13f19c0SEdward Tomasz Napierala # Linux uses the pre-pts(4) tty naming scheme. 57c13f19c0SEdward Tomasz Napierala load_kld pty 58c13f19c0SEdward Tomasz Napierala 5945aec462SEdward Tomasz Napierala # Explicitly load the filesystem modules; they are usually required, 6045aec462SEdward Tomasz Napierala # even with linux_mounts_enable="NO". 6145aec462SEdward Tomasz Napierala load_kld fdescfs 6245aec462SEdward Tomasz Napierala load_kld linprocfs 6345aec462SEdward Tomasz Napierala load_kld linsysfs 6445aec462SEdward Tomasz Napierala 65c13f19c0SEdward Tomasz Napierala # Handle unbranded ELF executables by defaulting to ELFOSABI_LINUX. 66c13f19c0SEdward Tomasz Napierala if [ `sysctl -ni kern.elf64.fallback_brand` -eq "-1" ]; then 67c13f19c0SEdward Tomasz Napierala sysctl kern.elf64.fallback_brand=3 > /dev/null 68c13f19c0SEdward Tomasz Napierala fi 69c13f19c0SEdward Tomasz Napierala 70c13f19c0SEdward Tomasz Napierala if [ `sysctl -ni kern.elf32.fallback_brand` -eq "-1" ]; then 71c13f19c0SEdward Tomasz Napierala sysctl kern.elf32.fallback_brand=3 > /dev/null 72c13f19c0SEdward Tomasz Napierala fi 73c13f19c0SEdward Tomasz Napierala 745dece9b2SEdward Tomasz Napierala if checkyesno linux_mounts_enable; then 7556902618SMateusz Piotrowski linux_mount linprocfs "${_emul_path}/proc" -o nocover 7656902618SMateusz Piotrowski linux_mount linsysfs "${_emul_path}/sys" -o nocover 7756902618SMateusz Piotrowski linux_mount devfs "${_emul_path}/dev" -o nocover 7856902618SMateusz Piotrowski linux_mount fdescfs "${_emul_path}/dev/fd" -o nocover,linrdlnk 7956902618SMateusz Piotrowski linux_mount tmpfs "${_emul_path}/dev/shm" -o nocover,mode=1777 805dece9b2SEdward Tomasz Napierala fi 81028af4aeSEdward Tomasz Napierala} 82028af4aeSEdward Tomasz Napierala 83028af4aeSEdward Tomasz Napieralaload_rc_config $name 84*f99f0ee1SAlexander Leidinger 85*f99f0ee1SAlexander Leidinger# doesn't make sense to run in a svcj: kernel modules and FS-mounting 86*f99f0ee1SAlexander Leidingerlinux_svcj="NO" 87*f99f0ee1SAlexander Leidinger 88028af4aeSEdward Tomasz Napieralarun_rc_command "$1" 89