File: flash_kernel_set_root

package info (click to toggle)
flash-kernel 3.3%2Bdeb7u2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 500 kB
  • sloc: sh: 577; makefile: 6
file content (112 lines) | stat: -rwxr-xr-x 3,048 bytes parent folder | download
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
#!/bin/sh

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,
# USA.

PREREQ=""

prereqs() {
	echo "$PREREQ"
}

pause_error() {
	local _ignored

	#exit 1 # won't work; initramfs-tools ignores hook script exit code
	echo "" >&2
	if [ "$DEBIAN_FRONTEND" = "noninteractive" ] ; then
		echo "Unable to abort; system will probably be broken!" >&2
	else
		echo "Press Ctrl-C to abort build, or Enter to continue" >&2
		read _ignored
	fi
}

case $1 in
prereqs)
	prereqs
	exit 0
	;;
esac

FK_DIR="/usr/share/flash-kernel"

. "${FK_CHECKOUT:-$FK_DIR}/functions"

. /usr/share/initramfs-tools/hook-functions

# Record the root filesystem device for use during boot
rootdev=$(egrep '^[^# 	]+[ 	]+/[ 	]' /etc/fstab | awk '{print $1}') || true

# Map LVM devices in the form of /dev/vg/lv to /dev/mapper/..., otherwise
# initramfs won't initialize them.
if [ -n "$rootdev" ]; then
	path=$(readlink -f $rootdev)
	if echo "$path" | grep -q "^/dev/mapper/"; then
		rootdev=$path
	fi
fi

# Translate LABEL and UUID entries into a proper device name.
if echo "$rootdev" | grep -q "="; then
	a=$(echo "$rootdev" | cut -d "=" -f 1)
	b=$(echo "$rootdev" | cut -d "=" -f 2- | sed -e 's/^"\(.*\)"$/\1/')
	case "$a" in
		LABEL)
			c=$(echo "$b" | sed 's#/#\\x2f#g')
			if [ -e /dev/disk/by-label/$c ]; then
				rootdev="/dev/disk/by-label/$c"
			else
				echo "Label $b not found in /dev/disk/by-label" >&2
			fi
		;;
		UUID)
			rootdev=/dev/disk/by-uuid/$b
			if [ ! -e $rootdev ]; then
				echo "UUID $b doesn't exist in /dev/disk/by-uuid" >&2
			fi
		;;
		*)
			echo "/etc/fstab parse error; cannot recognize root $rootdev" >&2
			rootdev=/dev/sda2
			echo "guessing that the root device is $rootdev" >&2
		;;
	esac
fi

if [ ! -e "$rootdev" ]; then
	echo "Warning: root device $rootdev does not exist" >&2
	pause_error
fi

machine="$(get_machine)"

# Should we override the root device or merely provide a default root
# device?
blsr="$(get_machine_field "$machine" "Bootloader-sets-root")"

if [ "$blsr" = "no" ]; then
	# The boot loader doesn't pass root= on the command line, so
	# provide a default.
	install -d $DESTDIR/conf/conf.d
	echo "ROOT=\"$rootdev\"" > $DESTDIR/conf/conf.d/default_root
else
	# The boot loader passes a bogus root= (e.g. root=/dev/ram), so
	# override the command line parameter.
	install -d $DESTDIR/conf
	echo "ROOT=\"$rootdev\"" >> $DESTDIR/conf/param.conf
fi

# vim:noexpandtab shiftwidth=8