File: flash_kernel_set_root

package info (click to toggle)
flash-kernel 3.109
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 736 kB
  • sloc: sh: 534; makefile: 36
file content (161 lines) | stat: -rwxr-xr-x 4,799 bytes parent folder | download | duplicates (2)
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
#!/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

	# Script is called from update-initramfs which in turn can be
	# called manually by the admin from the CLI or via various
	# postinst and trigger hooks or from the installer.
	#
	# If debconf appears to be running then it is important that
	# we do not block on stdin since this would hang the
	# installer.
	if [ "$DEBIAN_HAS_FRONTEND" ] || [ "$DEBIAN_FRONTEND" ]; 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, UUID, and PARTUUID 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
		;;
		PARTUUID)
			rootdev=/dev/disk/by-partuuid/$b
			if [ ! -e $rootdev ]; then
				echo "PARTUUID $b doesn't exist in /dev/disk/by-partuuid" >&2
			fi
		;;
		PARTLABEL)
			rootdev=/dev/disk/by-partlabel/$b
			if [ ! -e $rootdev ]; then
				echo "PARTLABEL $b doesn't exist in /dev/disk/by-partlabel" >&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

# Most mount options don't matter for the initial boot, but some are
# vital, make sure we preserve them
rootfstype=$(egrep '^[^# 	]+[ 	]+/[ 	]' /etc/fstab | awk '{print $3}') || true
rootmntopts=$(egrep '^[^# 	]+[ 	]+/[ 	]' /etc/fstab | awk '{print $4}') || true

case "$rootfstype" in
	"btrfs")
		rootflags="$rootflags$(expr ",${rootmntopts}," : '.*,\(subvol=[^,]*,\)')"
		rootflags="$rootflags$(expr ",${rootmntopts}," : '.*,\(degraded,\)')"
		rootflags="${rootflags%,}"  # Remove possible trailing ,
	;;
esac

get_machine

# Should we override the root device or merely provide a default root
# device?
blsir="$(get_machine_field "$machine" "Bootloader-Sets-Incorrect-Root")"
if [ -z "$blsir" ] ; then
	blsir="$(get_machine_field "$machine" "Bootloader-Sets-Root")"
	if [ -n "$blsir" ] ; then
		echo "WARNING: flash-kernel configuration contains deprecated" >&2
		echo "WARNING: \"Bootloader-Sets-Root\" option please update to" >&2
		echo "WARNING: use \"Bootloader-Sets-Incorrect-Root\" instead." >&2
	fi
fi

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

if [ "$blsir" = "yes" ]; then
	# 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
	if [ -n "${rootflags}" ]; then
		echo "ROOTFLAGS=\"-o ${rootflags}\"" >> $DESTDIR/conf/param.conf
	fi
else
	# The boot loader may or may not 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
	if [ -n "${rootflags}" ]; then
		echo "ROOTFLAGS=\"-o ${rootflags}\"" >> $DESTDIR/conf/conf.d/default_root
	fi
fi

# vim:noexpandtab shiftwidth=8