#!/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 machine="$(get_cpuinfo_hardware)" # Should we override the root device or merely provide a default root # device? blsr="$(get_machine_field "$machine" "Bootloader-sets-root")" if [ "$blsr" = "yes" ] || [ -n "$FLASH_KERNEL_SKIP" ]; then exit 0 fi # Do not run inside an LXC container if type running-in-container >/dev/null 2>&1 && \ running-in-container >/dev/null; then exit 0 fi # 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 # 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 # vim:noexpandtab shiftwidth=8