This file is indexed.

/usr/bin/os-prober is in os-prober 1.51ubuntu3.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/sh
set -e

. /usr/share/os-prober/common.sh

newns "$@"
require_tmpdir

log_output () {
	if type log-output >/dev/null 2>&1; then
		log-output -t os-prober --pass-stdout $@
	else
		$@
	fi
}

on_sataraid () {
	type dmraid >/dev/null 2>&1 || return 1
	local parent="${1%/*}"
	local device="/dev/${parent##*/}"
	if dmraid -r -c | grep -q "$device"; then
		return 0
	fi
	return 1
}

partitions () {
	# Exclude partitions that have whole_disk sysfs attribute set.
	if [ -d /sys/block ]; then
		# Exclude partitions on physical disks that are part of a
		# Serial ATA RAID disk.
		for part in /sys/block/*/*[0-9]; do
			if [ -f "$part/start" ] && \
			   [ ! -f "$part/whole_disk" ] && ! on_sataraid $part; then
				name="$(echo "${part##*/}" | sed 's,[!.],/,g')"
				if [ -e "/dev/$name" ]; then
					echo "/dev/$name"
				fi
			fi
		done

		# Add Serial ATA RAID devices
		if type dmraid >/dev/null 2>&1 && \
		   dmraid -s -c >/dev/null 2>&1; then
			for raidset in $(dmraid -sa -c); do
				for part in /dev/mapper/"$raidset"*[0-9]; do
					echo "$part"
				done
			done
		fi
	elif [ "$(uname -s)" = Linux ]; then
		echo "Cannot find list of partitions!  (Try mounting /sys.)" >&2
		exit 1
	else
		# We don't know how to probe OSes on non-Linux kernels.  For
		# now, just don't get in the way.
		exit 0
	fi

	# Also detect OSes on LVM volumes (assumes LVM is active)
	if type lvs >/dev/null 2>&1; then
		echo "$(LVM_SUPPRESS_FD_WARNINGS=1 log_output lvs --noheadings --separator : -o vg_name,lv_name |
			sed "s|-|--|g;s|^[[:space:]]*\(.*\):\(.*\)$|/dev/mapper/\1-\2|")"
	fi
}

parse_proc_swaps () {
	while read line; do
		set -f
		set -- $line
		set +f
		echo "$(mapdevfs $1) swap"
	done
}

parse_proc_mdstat () {
	if type udevadm >/dev/null 2>&1; then
		udevinfo () {
			udevadm info "$@"
		}
	fi
	while read line; do
		for word in $line; do
			dev="${word%%[*}"
			# TODO: factor this out to something in di-utils if
			# it's needed elsewhere
			if [ -d /sys/block ] && type udevinfo >/dev/null 2>&1; then
				if ! udevinfo -q path -n "/dev/$dev" 2>/dev/null | \
				     grep -q '/.*/.*/'; then
					continue
				fi
			elif ! echo "$dev" | grep -q "/part"; then
				continue
			fi
			raidpart="/dev/$dev"
			echo "$(mapdevfs "$raidpart")"
		done
	done
}

# Needed for idempotency
rm -f /var/lib/os-prober/labels

for prog in /usr/lib/os-probes/init/*; do
	if [ -x "$prog" ] && [ -f "$prog" ]; then
		"$prog" || true
	fi
done

# We need to properly canonicalize partitions with mount points and partitions
# used in RAID
grep "^/dev/" /proc/mounts | parse_proc_mounts >"$OS_PROBER_TMP/mounted-map" || true
grep "^/dev/" /proc/swaps | parse_proc_swaps >"$OS_PROBER_TMP/swaps-map" || true
: >"$OS_PROBER_TMP/raided-map"
if [ -f /proc/mdstat ] ; then
	grep "^md" /proc/mdstat | parse_proc_mdstat >"$OS_PROBER_TMP/raided-map" || true
fi

for partition in $(partitions); do
	if ! mapped="$(mapdevfs "$partition")"; then
		log "Device '$partition' does not exist; skipping"
		continue
	fi

	# Skip partitions used in software RAID arrays
	if grep -q "^$mapped" "$OS_PROBER_TMP/raided-map" ; then
		debug "$partition: part of software raid array"
		continue
	fi

	# Skip partitions used as active swap
	if grep -q "^$mapped " "$OS_PROBER_TMP/swaps-map" ; then
		debug "$partition: is active swap"
		continue
	fi

	if ! grep -q "^$mapped " "$OS_PROBER_TMP/mounted-map" ; then
		for test in /usr/lib/os-probes/*; do
			if [ -f "$test" ] && [ -x "$test" ]; then
				debug "running $test on $partition"
				if "$test" "$partition"; then
					debug "os detected by $test"
			   		break
				fi
			fi
		done
	else
		mpoint=$(grep "^$mapped " "$OS_PROBER_TMP/mounted-map" | head -n1 | cut -d " " -f 2)
		mpoint="$(unescape_mount "$mpoint")"
		if [ "$mpoint" != "/target/boot" ] && [ "$mpoint" != "/target" ] && [ "$mpoint" != "/" ]; then
			type=$(grep "^$mapped " "$OS_PROBER_TMP/mounted-map" | head -n1 | cut -d " " -f 3)
			for test in /usr/lib/os-probes/mounted/*; do
				if [ -f "$test" ] && [ -x "$test" ]; then
					debug "running $test on mounted $partition"
					if "$test" "$partition" "$mpoint" "$type"; then
						debug "os detected by $test"
						break
					fi
				fi
			done
		fi
	fi
done