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