aboutsummaryrefslogtreecommitdiffstats
path: root/core/alpine-baselayout/modloop.initd
blob: a8b39bf3448cea4f9364a257a3b414e32217b8ff (plain)
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
#!/sbin/runscript

# script that will mount image with modules

# read kernel options
for i in `cat /proc/cmdline` ; do
	case $i in
		*=*)    eval KOPT_$i ;;
		*)      eval KOPT_$i=yes ;;
	esac
done

find_media() {
	ALPINE_DEV=${KOPT_alpine_dev%%:*}
	ALPINE_MNT=`awk '/^\/dev\/'$ALPINE_DEV'/ { print $2 }' /etc/fstab`
}

start() {
	local rc=
	local imgdir=$(dirname ${KOPT_BOOT_IMAGE:-""})
	find_media
	if [ -z "$ALPINE_DEV" ] ; then
		ebegin "Skipping mount media with modules (specify with alpine_dev)"
		eend 0
		return 0
	fi

	if [ -n "$KOPT_modloop" ]; then
		CMG="$ALPINE_MNT/$KOPT_modloop"
	else
		CMG=$ALPINE_MNT/$imgdir/modloop.cmg
	fi
	ebegin "Mounting loopback device for kernel modules"
	mount $ALPINE_MNT >/dev/null 2>&1 &&\
	mkdir -p /.modloop &&\
	if [ ! -f "$CMG" ] ; then
		CMG=$ALPINE_MNT/$imgdir/modules.cmg
	fi &&\
	mount -o loop,ro -t cramfs $CMG /.modloop
	rc=$?
	if [ "$rc" = 0 ]; then
		rm -rf /lib/modules
		ln -sf /.modloop/modules /lib
	fi
	# copy firmware if there are any
	if [ -d $ALPINE_MNT/firmware ]; then
		mkdir -p /lib/firmware
		cp $ALPINE_MNT/firmware/* /lib/firmware/
	fi
	eend $rc
}

stop() {
	find_media
	if [ "$ALPINE_DEV" ] ; then
		ebegin "Unmounting loopback device for kernel modules"
		umount -d /.modloop &&\
		umount $ALPINE_MNT 2>/dev/null
		eend $?
	fi
}