~elementary-os/ubuntu-package-imports/ubiquity-bionic

« back to all changes in this revision

Viewing changes to d-i/source/flash-kernel/initramfs-tools/hooks/flash_kernel_set_root

  • Committer: RabbitBot
  • Date: 2018-02-05 14:44:42 UTC
  • Revision ID: rabbitbot@elementary.io-20180205144442-vt0fvth7zus90wjh
Initial import, version 17.10.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
        if [ "$DEBIAN_FRONTEND" = "noninteractive" ] ; then
 
30
                echo "Unable to abort; system will probably be broken!" >&2
 
31
        else
 
32
                echo "Press Ctrl-C to abort build, or Enter to continue" >&2
 
33
                read _ignored
 
34
        fi
 
35
}
 
36
 
 
37
case $1 in
 
38
prereqs)
 
39
        prereqs
 
40
        exit 0
 
41
        ;;
 
42
esac
 
43
 
 
44
FK_DIR="/usr/share/flash-kernel"
 
45
 
 
46
. "${FK_CHECKOUT:-$FK_DIR}/functions"
 
47
 
 
48
. /usr/share/initramfs-tools/hook-functions
 
49
 
 
50
machine="$(get_cpuinfo_hardware)"
 
51
 
 
52
# Should we override the root device or merely provide a default root
 
53
# device?
 
54
blsr="$(get_machine_field "$machine" "Bootloader-sets-root")"
 
55
 
 
56
if [ "$blsr" = "yes" ] || [ -n "$FLASH_KERNEL_SKIP" ]; then
 
57
        exit 0
 
58
fi
 
59
 
 
60
# Do not run inside an LXC container
 
61
if systemd-detect-virt --quiet --container; then
 
62
        exit 0
 
63
fi
 
64
 
 
65
# Record the root filesystem device for use during boot
 
66
rootdev=$(egrep '^[^#   ]+[     ]+/[    ]' /etc/fstab | awk '{print $1}') || true
 
67
 
 
68
# Map LVM devices in the form of /dev/vg/lv to /dev/mapper/..., otherwise
 
69
# initramfs won't initialize them.
 
70
if [ -n "$rootdev" ]; then
 
71
        path=$(readlink -f $rootdev)
 
72
        if echo "$path" | grep -q "^/dev/mapper/"; then
 
73
                rootdev=$path
 
74
        fi
 
75
fi
 
76
 
 
77
# Translate LABEL and UUID entries into a proper device name.
 
78
if echo "$rootdev" | grep -q "="; then
 
79
        a=$(echo "$rootdev" | cut -d "=" -f 1)
 
80
        b=$(echo "$rootdev" | cut -d "=" -f 2- | sed -e 's/^"\(.*\)"$/\1/')
 
81
        case "$a" in
 
82
                LABEL)
 
83
                        c=$(echo "$b" | sed 's#/#\\x2f#g')
 
84
                        if [ -e /dev/disk/by-label/$c ]; then
 
85
                                rootdev="/dev/disk/by-label/$c"
 
86
                        else
 
87
                                echo "Label $b not found in /dev/disk/by-label" >&2
 
88
                        fi
 
89
                ;;
 
90
                UUID)
 
91
                        rootdev=/dev/disk/by-uuid/$b
 
92
                        if [ ! -e $rootdev ]; then
 
93
                                echo "UUID $b doesn't exist in /dev/disk/by-uuid" >&2
 
94
                        fi
 
95
                ;;
 
96
                *)
 
97
                        echo "/etc/fstab parse error; cannot recognize root $rootdev" >&2
 
98
                        rootdev=/dev/sda2
 
99
                        echo "guessing that the root device is $rootdev" >&2
 
100
                ;;
 
101
        esac
 
102
fi
 
103
 
 
104
if [ ! -e "$rootdev" ]; then
 
105
        echo "Warning: root device $rootdev does not exist" >&2
 
106
        pause_error
 
107
fi
 
108
 
 
109
# The boot loader doesn't pass root= on the command line, so
 
110
# provide a default.
 
111
install -d $DESTDIR/conf/conf.d
 
112
echo "ROOT=\"$rootdev\"" > $DESTDIR/conf/conf.d/default_root
 
113
 
 
114
# vim:noexpandtab shiftwidth=8