| 1 | #!/bin/sh |
| 2 | |
| 3 | # This program is free software; you can redistribute it and/or |
| 4 | # modify it under the terms of the GNU General Public License |
| 5 | # as published by the Free Software Foundation; either version 2 |
| 6 | # of the License, or (at your option) any later version. |
| 7 | # |
| 8 | # This program is distributed in the hope that it will be useful, |
| 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | # GNU General Public License for more details. |
| 12 | # |
| 13 | # You should have received a copy of the GNU General Public License |
| 14 | # along with this program; if not, write to the Free Software |
| 15 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, |
| 16 | # USA. |
| 17 | |
| 18 | PREREQ="" |
| 19 | |
| 20 | prereqs() { |
| 21 | echo "$PREREQ" |
| 22 | } |
| 23 | |
| 24 | pause_error() { |
| 25 | local _ignored |
| 26 | |
| 27 | #exit 1 # won't work; initramfs-tools ignores hook script exit code |
| 28 | echo "" >&2 |
| 29 | |
| 30 | # Script is called from update-initramfs which in turn can be |
| 31 | # called manually by the admin from the CLI or via various |
| 32 | # postinst and trigger hooks or from the installer. |
| 33 | # |
| 34 | # If debconf appears to be running then it is important that |
| 35 | # we do not block on stdin since this would hang the |
| 36 | # installer. |
| 37 | if [ "$DEBIAN_HAS_FRONTEND" ] || [ "$DEBIAN_FRONTEND" ]; then |
| 38 | echo "Unable to abort; system will probably be broken!" >&2 |
| 39 | else |
| 40 | echo "Press Ctrl-C to abort build, or Enter to continue" >&2 |
| 41 | read _ignored |
| 42 | fi |
| 43 | } |
| 44 | |
| 45 | case $1 in |
| 46 | prereqs) |
| 47 | prereqs |
| 48 | exit 0 |
| 49 | ;; |
| 50 | esac |
| 51 | |
| 52 | FK_DIR="/usr/share/flash-kernel" |
| 53 | |
| 54 | . "${FK_CHECKOUT:-$FK_DIR}/functions" |
| 55 | |
| 56 | . /usr/share/initramfs-tools/hook-functions |
| 57 | |
| 58 | # Record the root filesystem device for use during boot |
| 59 | rootdev=$(egrep '^[^# ]+[ ]+/[ ]' /etc/fstab | awk '{print $1}') || true |
| 60 | |
| 61 | # Map LVM devices in the form of /dev/vg/lv to /dev/mapper/..., otherwise |
| 62 | # initramfs won't initialize them. |
| 63 | if [ -n "$rootdev" ]; then |
| 64 | path=$(readlink -f $rootdev) |
| 65 | if echo "$path" | grep -q "^/dev/mapper/"; then |
| 66 | rootdev=$path |
| 67 | fi |
| 68 | fi |
| 69 | |
| 70 | # Translate LABEL, UUID, and PARTUUID entries into a proper device name. |
| 71 | if echo "$rootdev" | grep -q "="; then |
| 72 | a=$(echo "$rootdev" | cut -d "=" -f 1) |
| 73 | b=$(echo "$rootdev" | cut -d "=" -f 2- | sed -e 's/^"\(.*\)"$/\1/') |
| 74 | case "$a" in |
| 75 | LABEL) |
| 76 | c=$(echo "$b" | sed 's#/#\\x2f#g') |
| 77 | if [ -e /dev/disk/by-label/$c ]; then |
| 78 | rootdev="/dev/disk/by-label/$c" |
| 79 | else |
| 80 | echo "Label $b not found in /dev/disk/by-label" >&2 |
| 81 | fi |
| 82 | ;; |
| 83 | UUID) |
| 84 | rootdev=/dev/disk/by-uuid/$b |
| 85 | if [ ! -e $rootdev ]; then |
| 86 | echo "UUID $b doesn't exist in /dev/disk/by-uuid" >&2 |
| 87 | fi |
| 88 | ;; |
| 89 | PARTUUID) |
| 90 | rootdev=/dev/disk/by-partuuid/$b |
| 91 | if [ ! -e $rootdev ]; then |
| 92 | echo "PARTUUID $b doesn't exist in /dev/disk/by-partuuid" >&2 |
| 93 | fi |
| 94 | ;; |
| 95 | PARTLABEL) |
| 96 | rootdev=/dev/disk/by-partlabel/$b |
| 97 | if [ ! -e $rootdev ]; then |
| 98 | echo "PARTLABEL $b doesn't exist in /dev/disk/by-partlabel" >&2 |
| 99 | fi |
| 100 | ;; |
| 101 | *) |
| 102 | echo "/etc/fstab parse error; cannot recognize root $rootdev" >&2 |
| 103 | rootdev=/dev/sda2 |
| 104 | echo "guessing that the root device is $rootdev" >&2 |
| 105 | ;; |
| 106 | esac |
| 107 | fi |
| 108 | |
| 109 | # Most mount options don't matter for the initial boot, but some are |
| 110 | # vital, make sure we preserve them |
| 111 | rootfstype=$(egrep '^[^# ]+[ ]+/[ ]' /etc/fstab | awk '{print $3}') || true |
| 112 | rootmntopts=$(egrep '^[^# ]+[ ]+/[ ]' /etc/fstab | awk '{print $4}') || true |
| 113 | |
| 114 | case "$rootfstype" in |
| 115 | "btrfs") |
| 116 | rootflags="$rootflags$(expr ",${rootmntopts}," : '.*,\(subvol=[^,]*,\)')" |
| 117 | rootflags="$rootflags$(expr ",${rootmntopts}," : '.*,\(degraded,\)')" |
| 118 | rootflags="${rootflags%,}" # Remove possible trailing , |
| 119 | ;; |
| 120 | esac |
| 121 | |
| 122 | get_machine |
| 123 | |
| 124 | # Should we override the root device or merely provide a default root |
| 125 | # device? |
| 126 | blsir="$(get_machine_field "$machine" "Bootloader-Sets-Incorrect-Root")" |
| 127 | if [ -z "$blsir" ] ; then |
| 128 | blsir="$(get_machine_field "$machine" "Bootloader-Sets-Root")" |
| 129 | if [ -n "$blsir" ] ; then |
| 130 | echo "WARNING: flash-kernel configuration contains deprecated" >&2 |
| 131 | echo "WARNING: \"Bootloader-Sets-Root\" option please update to" >&2 |
| 132 | echo "WARNING: use \"Bootloader-Sets-Incorrect-Root\" instead." >&2 |
| 133 | fi |
| 134 | fi |
| 135 | |
| 136 | if [ ! -e "$rootdev" ]; then |
| 137 | echo "Warning: root device $rootdev does not exist" >&2 |
| 138 | if [ "$blsir" = "yes" ]; then |
| 139 | pause_error |
| 140 | fi |
| 141 | fi |
| 142 | |
| 143 | if [ "$blsir" = "yes" ]; then |
| 144 | # The boot loader passes a bogus root= (e.g. root=/dev/ram), so |
| 145 | # override the command line parameter. |
| 146 | install -d $DESTDIR/conf |
| 147 | echo "ROOT=\"$rootdev\"" >> $DESTDIR/conf/param.conf |
| 148 | if [ -n "${rootflags}" ]; then |
| 149 | echo "ROOTFLAGS=\"-o ${rootflags}\"" >> $DESTDIR/conf/param.conf |
| 150 | fi |
| 151 | else |
| 152 | # The boot loader may or may not pass root= on the command line, so |
| 153 | # provide a default. |
| 154 | install -d $DESTDIR/conf/conf.d |
| 155 | echo "ROOT=\"$rootdev\"" > $DESTDIR/conf/conf.d/default_root |
| 156 | if [ -n "${rootflags}" ]; then |
| 157 | echo "ROOTFLAGS=\"-o ${rootflags}\"" >> $DESTDIR/conf/conf.d/default_root |
| 158 | fi |
| 159 | fi |
| 160 | |
| 161 | # vim:noexpandtab shiftwidth=8 |