source: grub-pc/trunk/fuentes/debian/postinst.in @ 22

Last change on this file since 22 was 22, checked in by mabarracus, 4 years ago

updated version and apply net.ifnames=0 into debian/rules

File size: 26.5 KB
Line 
1#!/bin/bash
2set -e
3
4merge_debconf_into_conf()
5{
6  local tmpfile; tmpfile="$1"
7  local setting; setting="$2"
8  local template; template="$3"
9
10  db_get "$template"
11  local value; value="$(echo "$RET" | sed -e 's,[$`"\],\\&,g')"
12  if grep -q "^${setting}=" "$tmpfile"; then
13    value="$(echo "$value" | sed -e 's,[\@],\\&,g')"
14    sed -i -re "s@^(${setting}=).*@\1\"${value}\"@" "$tmpfile"
15  else
16    echo >> "$tmpfile"
17    echo "${setting}=\"${value}\"" >> "$tmpfile"
18  fi
19}
20
21get_wubi_device()
22{
23  if [ ! -x /usr/share/lupin-support/grub-mkimage ] || \
24     ! /usr/share/lupin-support/grub-mkimage --test; then
25    return 1
26  fi
27
28  local bootdev="$(grub-probe --target=device /boot)" || true
29  local loop_file=
30  case $bootdev in
31    /dev/loop/*|/dev/loop[0-9])
32      loop_file="$(losetup "$bootdev" | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/")"
33      # If it's loop-mounted from another device, it isn't Wubi.
34      case $loop_file in
35        /dev/*) return 1 ;;
36      esac
37    ;;
38    *) return 1 ;;
39  esac
40
41  echo "$bootdev"
42}
43
44# This only works on a Linux system with udev running.  This is probably the
45# vast majority of systems where we need any of this, though, and we fall
46# back reasonably gracefully if we don't have it.
47cached_available_ids=
48available_ids()
49{
50  local id path
51
52  if [ "$cached_available_ids" ]; then
53    echo "$cached_available_ids"
54    return
55  fi
56
57  [ -d /dev/disk/by-id ] || return
58  cached_available_ids="$(
59    for path in /dev/disk/by-id/*; do
60      [ -e "$path" ] || continue
61      printf '%s %s\n' "$path" "$(readlink -f "$path")"
62    done | sort -k2 -s -u | cut -d' ' -f1
63  )"
64  echo "$cached_available_ids"
65}
66
67# Returns non-zero and no output if no mapping can be found.
68device_to_id()
69{
70  local id
71  for id in $(available_ids); do
72    if [ "$(readlink -f "$id")" = "$(readlink -f "$1")" ]; then
73      echo "$id"
74      return 0
75    fi
76  done
77  # Fall back to the plain device name if there's no by-id link for it.
78  if [ -e "$1" ]; then
79    echo "$1"
80    return 0
81  fi
82  return 1
83}
84
85devices_to_ids()
86{
87  local device id ids
88  ids=
89  for device; do
90    id="$(device_to_id "$device" || true)"
91    if [ "$id" ]; then
92      ids="${ids:+$ids, }$id"
93    fi
94  done
95  echo "$ids"
96}
97
98all_disks()
99{
100  local id
101  for id in $(available_ids); do
102    case $id in
103      *-part*) ;;
104      *) echo "$id" ;;
105    esac
106  done
107}
108
109all_partitions()
110{
111  local id ids
112  ids=
113  for id in $(available_ids); do
114    if [ "$id" != "$1" ] && [ "${id%-part*}" = "$1" ]; then
115      ids="${ids:+$ids }$id"
116    fi
117  done
118  echo "$ids"
119}
120
121# In order to determine whether we accidentally ran grub-install without
122# upgrade-from-grub-legacy on versions older than 1.98+20100617-1, we need
123# to be able to scan a disk to determine whether GRUB 2 was installed in its
124# boot sector.  This is specific to i386-pc (but that's the only platform
125# where we need it).
126scan_grub2()
127{
128  if ! dd if="$1" bs=512 count=1 2>/dev/null | grep -aq GRUB; then
129    # No version of GRUB is installed.
130    return 1
131  fi
132
133  # The GRUB boot sector always starts with a JMP instruction.
134  initial_jmp="$(dd if="$1" bs=2 count=1 2>/dev/null | od -Ax -tx1 | \
135                 head -n1 | cut -d' ' -f2,3)"
136  [ "$initial_jmp" ] || return 1
137  initial_jmp_opcode="${initial_jmp%% *}"
138  [ "$initial_jmp_opcode" = eb ] || return 1
139  initial_jmp_operand="${initial_jmp#* }"
140  case $initial_jmp_operand in
141    47|4b|4c|63)
142      # I believe this covers all versions of GRUB 2 up to the package
143      # version where we gained a more explicit mechanism.  GRUB Legacy
144      # always had 48 here.
145      return 0
146    ;;
147  esac
148
149  return 1
150}
151
152# for Linux
153sysfs_size()
154{
155  local num_sectors sector_size size
156  # Try to find out the size without relying on a partitioning tool being
157  # installed. This isn't too hard on Linux 2.6 with sysfs, but we have to
158  # try a couple of variants on detection of the sector size.
159  if [ -e "$1/size" ]; then
160    num_sectors="$(cat "$1/size")"
161    sector_size=512
162    if [ -e "$1/queue/logical_block_size" ]; then
163      sector_size="$(cat "$1/queue/logical_block_size")"
164    elif [ -e "$1/queue/hw_sector_size" ]; then
165      sector_size="$(cat "$1/queue/hw_sector_size")"
166    fi
167    size="$(expr "$num_sectors" \* "$sector_size" / 1000 / 1000)"
168  fi
169  [ "$size" ] || size='???'
170  echo "$size"
171}
172
173# for kFreeBSD
174camcontrol_size()
175{
176  local num_sectors sector_size size=
177
178  if num_sectors="$(camcontrol readcap "$1" -q -s -N)"; then
179    sector_size="$(camcontrol readcap "$1" -q -b)"
180    size="$(expr "$num_sectors" \* "$sector_size" / 1000 / 1000)"
181  fi
182
183  [ "$size" ] || size='???'
184  echo "$size"
185}
186
187# Returns value in $RET, like a debconf command.
188describe_disk()
189{
190  local disk id base size
191  disk="$1"
192  id="$2"
193
194  model=
195  case $(uname -s) in
196    Linux)
197      if which udevadm >/dev/null 2>&1; then
198        size="$(sysfs_size "/sys$(udevadm info -n "$disk" -q path)")"
199      else
200        base="${disk#/dev/}"
201        base="$(printf %s "$base" | sed 's,/,!,g')"
202        size="$(sysfs_size "/sys/block/$base")"
203      fi
204
205      if which udevadm >/dev/null 2>&1; then
206        model="$(udevadm info -n "$disk" -q property | sed -n 's/^ID_MODEL=//p')"
207        if [ -z "$model" ]; then
208          model="$(udevadm info -n "$disk" -q property | sed -n 's/^DM_NAME=//p')"
209          if [ -z "$model" ]; then
210            model="$(udevadm info -n "$disk" -q property | sed -n 's/^MD_NAME=//p')"
211            if [ -z "$model" ] && which dmsetup >/dev/null 2>&1; then
212              model="$(dmsetup info -c --noheadings -o name "$disk" 2>/dev/null || true)"
213            fi
214          fi
215        fi
216      fi
217    ;;
218    GNU/kFreeBSD)
219      disk_basename=$(basename "$disk")
220      size="$(camcontrol_size "$disk_basename")"
221      model="$(camcontrol inquiry "$disk_basename" | sed -ne "s/^pass0: <\([^>]*\)>.*/\1/p")"
222    ;;
223  esac
224
225  [ "$model" ] || model='???'
226
227  db_subst grub-pc/disk_description DEVICE "$disk"
228  db_subst grub-pc/disk_description SIZE "$size"
229  db_subst grub-pc/disk_description MODEL "$model"
230  db_metaget grub-pc/disk_description description
231}
232
233# Returns value in $RET, like a debconf command.
234describe_partition()
235{
236  local disk part id path diskbase partbase size
237  disk="$1"
238  part="$2"
239  id="$3"
240  path="$4"
241
242  if which udevadm >/dev/null 2>&1; then
243    size="$(sysfs_size "/sys$(udevadm info -n "$part" -q path)")"
244  else
245    diskbase="${disk#/dev/}"
246    diskbase="$(printf %s "$diskbase" | sed 's,/,!,g')"
247    partbase="${part#/dev/}"
248    partbase="$(printf %s "$partbase" | sed 's,/,!,g')"
249    size="$(sysfs_size "/sys/block/$diskbase/$partbase")"
250  fi
251
252  db_subst grub-pc/partition_description DEVICE "$part"
253  db_subst grub-pc/partition_description SIZE "$size"
254  db_subst grub-pc/partition_description PATH "$path"
255  db_metaget grub-pc/partition_description description
256}
257
258usable_partitions()
259{
260  local last_partition path partition partition_id
261
262  last_partition=
263  for path in / /boot /boot/grub; do
264    partition="$(grub-probe -t device "$path" || true)"
265    if [ -z "$partition" ] || [ "$partition" = "$last_partition" ]; then
266      continue
267    fi
268    partition_id="$(device_to_id "$partition" || true)"
269    echo "$path:$partition_id"
270    last_partition="$partition"
271  done | sort -t: -k2
272}
273
274get_mountpoint()
275{
276  local relpath boot_mountpoint
277
278  relpath="$(grub-mkrelpath "$1")"
279  boot_mountpoint="${1#$relpath}"
280  echo "${boot_mountpoint:-/}"
281}
282
283config_item()
284{
285  for x in /etc/default/grub /etc/default/grub.d/*.cfg; do
286    if [ -e "$x" ]; then
287      . "$x"
288    fi
289  done
290  if [ "$(eval echo "\${$1+set}")" = set ]; then
291    eval echo "\$$1"
292  else
293    return
294  fi
295}
296
297running_in_container()
298{
299  type running-in-container >/dev/null 2>&1 && running-in-container >/dev/null
300}
301
302run_grub_install()
303{
304    if ! grub-install $@ ; then
305        echo "Failed: grub-install $@" >&2
306        echo "WARNING: Bootloader is not properly installed, system may not be bootable" >&2
307    fi
308}
309
310case "$1" in
311  configure)
312    . /usr/share/debconf/confmodule
313
314    devicemap_regenerated=
315
316    if egrep -q '^[[:space:]]*post(inst|rm)_hook[[:space:]]*=[[:space:]]*(/sbin/|/usr/sbin/)?update-grub' /etc/kernel-img.conf 2>/dev/null; then
317      echo 'Removing update-grub hooks from /etc/kernel-img.conf in favour of' >&2
318      echo '/etc/kernel/ hooks.' >&2
319      sed -ri /etc/kernel-img.conf -e '\%^[[:space:]]*post(inst|rm)_hook[[:space:]]*=[[:space:]]*(/sbin/|/usr/sbin/)?update-grub%d'
320    fi
321
322    case @PACKAGE@ in
323      grub-pc)
324        mkdir -p /boot/grub
325
326        if test -e /boot/grub/device.map && ! test -e /boot/grub/core.img && \
327           ! test -e /boot/grub/@FIRST_CPU_PLATFORM@/core.img; then
328          # Looks like your device.map was generated by GRUB Legacy, which
329          # used to generate broken device.map (see #422851).  Avoid the risk
330          # by regenerating it.
331          grub-mkdevicemap --no-floppy
332          devicemap_regenerated=1
333        fi
334      ;;
335    esac
336
337    if test -z "$devicemap_regenerated" && test -s /boot/grub/device.map && \
338       dpkg --compare-versions "$2" lt-nl 1.98+20100702-1 && \
339       test "$(uname -s)" = Linux; then
340      # Earlier versions of GRUB used unstable device names in device.map,
341      # which caused a variety of problems.  There is some risk associated with
342      # regenerating it (so we prompt the user if it's non-trivial), but on the
343      # whole it's less risky to move to /dev/disk/by-id/.
344      devicemap_lines="$(egrep -v '^[[:space:]]+#' /boot/grub/device.map | wc -l)"
345      grub-mkdevicemap --no-floppy
346      devicemap_regenerated=1
347      if test "$devicemap_lines" != 1; then
348        db_input critical grub2/device_map_regenerated || true
349        db_go || true
350      fi
351    fi
352
353    if test -z "$devicemap_regenerated" && \
354       dpkg --compare-versions "$2" lt-nl 1.99~20101210-2 && \
355       grep -qs /md-uuid- /boot/grub/device.map; then
356      echo "Removing MD devices from device.map, since the BIOS cannot read from these." >&2
357      sed -i '/\/md-uuid-/d' /boot/grub/device.map
358    fi
359
360    tmp_default_grub="$(mktemp -t grub.XXXXXXXXXX)"
361    trap "rm -f ${tmp_default_grub}" EXIT
362    cp -p /usr/share/grub/default/grub ${tmp_default_grub}
363
364    merge_debconf_into_conf "$tmp_default_grub" GRUB_CMDLINE_LINUX grub2/linux_cmdline
365    merge_debconf_into_conf "$tmp_default_grub" GRUB_CMDLINE_LINUX_DEFAULT grub2/linux_cmdline_default
366
367    case @PACKAGE@ in
368      grub-pc)
369        merge_debconf_into_conf "$tmp_default_grub" GRUB_TIMEOUT grub-pc/timeout
370        sed -i -e 's/^\(GRUB_TIMEOUT=\)"\([0-9][0-9]*\)"/\1\2/' "$tmp_default_grub"
371        db_get grub-pc/hidden_timeout
372        if [ "$RET" = false ]; then
373          sed -i -e 's/^GRUB_HIDDEN_TIMEOUT=/#&/' "$tmp_default_grub"
374        fi
375      ;;
376    esac
377
378    ucf --three-way --debconf-ok --sum-file=/usr/share/grub/default/grub.md5sum ${tmp_default_grub} /etc/default/grub
379    package="$(ucfq --with-colons /etc/default/grub | cut -d : -f 2)"
380    if echo $package | grep -q "^grub-" ; then
381      ucfr --force @PACKAGE@ /etc/default/grub
382    else
383      ucfr @PACKAGE@ /etc/default/grub
384    fi
385
386    case @PACKAGE@ in
387      grub-pc)
388
389        fix_mixed_system=
390        if test -e /boot/grub/stage2 && test -e /boot/grub/menu.lst && \
391           ! test -e /boot/grub/grub2-installed && \
392           test -z "$UPGRADE_FROM_GRUB_LEGACY"; then
393          # Unfortunately, it's still possible that the user upgraded fully
394          # to GRUB 2 in some way other than running
395          # upgrade-from-grub-legacy; perhaps they ran grub-install by hand
396          # for some reason.  It's really quite difficult to detect this
397          # situation, because the only difference between this and a
398          # working chainloaded setup is that in this case grub-setup has
399          # been run.  So, to try to tell the difference, we scan the boot
400          # sectors of all disks for a GRUB 2 boot sector.  Hopefully this
401          # won't cause too much to explode, since I can't think of a better
402          # method.
403          grub2_disks=
404          for disk in $(all_disks); do
405            if scan_grub2 "$disk"; then
406              grub2_disks="${grub2_disks:+$grub2_disks }$(readlink -f "$disk")"
407            fi
408          done
409          if [ "$grub2_disks" ]; then
410            # No || true here; it's vital that the user sees this, and it's
411            # better to throw an error than to do the wrong thing.
412            db_subst grub-pc/mixed_legacy_and_grub2 DISKS "$grub2_disks"
413            db_fset grub-pc/mixed_legacy_and_grub2 seen false
414            db_input critical grub-pc/mixed_legacy_and_grub2
415            db_go
416            db_get grub-pc/mixed_legacy_and_grub2
417            if [ "$RET" = true ]; then
418              db_reset grub-pc/install_devices
419              UPGRADE_FROM_GRUB_LEGACY=1
420              fix_mixed_system=1
421              # Fall through to normal installation logic.
422            fi
423          fi
424        fi
425
426        # Make sure that Wubi users never see confusing device prompts.
427        # Wubi is a very specialised hack that does complicated things with
428        # grub-install diversions to create an image that's chained from the
429        # Windows boot loader to boot an operating system from a file on a
430        # Windows file system.  In these circumstances, prompting for where
431        # to install GRUB is not going to help anyone.
432        wubi_device="$(get_wubi_device)" || true
433        if [ "$wubi_device" ]; then
434          db_set grub-pc/install_devices "$wubi_device"
435          db_fset grub-pc/install_devices seen true
436        fi
437
438        if test -e /boot/grub/stage2 && test -e /boot/grub/menu.lst && \
439           ! test -e /boot/grub/grub2-installed && \
440           test -z "$UPGRADE_FROM_GRUB_LEGACY"; then
441          db_get grub-pc/chainload_from_menu.lst
442          if $RET ; then
443            # Create core.img (but do not risk writing to MBR).
444            # Using grub-probe instead of "(hd0)" avoids (UUID=) hack slowness
445            # in case /boot/grub is not on (hd0) in device.map.
446            echo "Generating core.img" >&2
447            grub-install --target=i386-pc --no-floppy --grub-setup=/bin/true "$(grub-probe -t drive /boot/grub)" > /dev/null
448
449            # Update menu.lst to reflect that:
450            # - core.img is present now
451            # - core.img has to be the first option
452            echo "Saving menu.lst backup in /boot/grub/menu.lst_backup_by_grub2_postinst" >&2
453            cp /boot/grub/menu.lst{,_backup_by_grub2_postinst}
454            echo "Running update-grub Legacy to hook our core.img in it" >&2
455            LET_US_TRY_GRUB_2=true /usr/lib/grub-legacy/update-grub 2>&1 | sed -e "s/^/    /g" >&2
456            # We just hooked GRUB 2 in menu.lst; then also generate grub.cfg.
457            touch /boot/grub/grub.cfg
458          fi
459        elif running_in_container; then
460          # Skip grub-install in containers.
461          :
462        elif test -z "$2" || test -e /boot/grub/core.img || \
463             test -e /boot/grub/@FIRST_CPU_PLATFORM@/core.img || \
464             test "$UPGRADE_FROM_GRUB_LEGACY" || test "$wubi_device"; then
465          question=grub-pc/install_devices
466          priority=high
467          device_map="$(grub-mkdevicemap -m - | grep -v '^(fd[0-9]\+)' || true)"
468          devices="$(echo "$device_map" | cut -f2)"
469          if dpkg --compare-versions "$2" lt 1.98+20100702-1 && \
470             test "$(uname -s)" = Linux && [ -z "$wubi_device" ]; then
471            # Migrate to new by-id naming scheme.
472            db_get grub-pc/install_devices
473            old_devices="$(echo "$RET" | sed 's/, / /g')"
474            new_devices=
475            # Common-case optimisation: if the list of devices is
476            # identical to the LHS of grub-mkdevicemap's output, then
477            # there's no point asking again; just install to all disks.
478            # (This handles e.g. "(hd0)" with one disk.)
479            if [ "$(echo "$device_map" | cut -f1 | sort)" = \
480                 "$(echo "$old_devices" | xargs -n1 | sort)" ]; then
481              new_devices="$(devices_to_ids $devices)"
482              db_set grub-pc/install_devices "$new_devices"
483            # Alternatively, we might be installing to a single partition
484            # on a single disk, and we can deal with that too if there's
485            # only one available disk and it has an appropriate partition.
486            # This doesn't necessarily work for multiple disks because now
487            # the order matters.
488            elif [ "$(echo "$device_map" | wc -l)" = 1 ] && \
489                 [ "$(echo "$old_devices" | wc -w)" = 1 ] && \
490                 echo "$old_devices" | grep -q ,; then
491              old_device="${old_devices#(}"
492              old_device="${old_device%)}"
493              old_disk="${old_device%,*}"
494              old_partition="${old_device##*,}"
495              new_device="$(echo "$device_map" | grep "^($old_disk)" | \
496                            cut -f2)"
497              new_device="$(device_to_id $new_device)"
498              if [ "$new_device" ]; then
499                new_device="$new_device-part$old_partition"
500                # Run through device_to_id again to check for existence.
501                new_device="$(device_to_id $new_device)"
502              fi
503              if [ "$new_device" ]; then
504                new_devices="$new_device"
505                db_set grub-pc/install_devices "$new_device"
506              fi
507            fi
508            if [ -z "$new_devices" ]; then
509              new_devices="$(devices_to_ids $old_devices)"
510              db_set grub-pc/install_devices "$new_devices"
511              # Common-case optimisation: if all devices are translatable
512              # to by-id and the number of devices there is the same as
513              # the number of devices GRUB can see, then there's no point
514              # asking again.  (This handles e.g. "/dev/sda" with one
515              # disk.)
516              old_devices_count="$(echo "$old_devices" | wc -w)"
517              new_devices_count="$(echo "$new_devices" | wc -w)"
518              devices_count="$(echo "$devices" | wc -w)"
519              if [ "$old_devices_count" != "$new_devices_count" ] || \
520                 [ "$new_devices_count" != "$devices_count" ]; then
521                db_fset grub-pc/install_devices seen false
522                db_fset grub-pc/install_devices_empty seen false
523              fi
524            fi
525          else
526            db_get grub-pc/install_devices
527            valid=1
528            for device in $RET; do
529              if [ ! -e "${device%,}" ]; then
530                valid=0
531                break
532              fi
533            done
534            if [ "$valid" = 0 ]; then
535              question=grub-pc/install_devices_disks_changed
536              priority=critical
537              db_set "$question" "$RET"
538              db_fset "$question" seen false
539              db_fset grub-pc/install_devices_empty seen false
540            fi
541          fi
542
543          while :; do
544            ids=
545            descriptions=
546            partitions="$(usable_partitions)"
547            for device in $devices; do
548              disk_id="$(device_to_id "$device" || true)"
549              if [ "$disk_id" ]; then
550                ids="${ids:+$ids, }$disk_id"
551                describe_disk "$(readlink -f "$device")" "$disk_id"
552                RET="$(printf %s "$RET" | sed 's/,/\\,/g')"
553                descriptions="${descriptions:+$descriptions, }$RET"
554                for partition_pair in $partitions; do
555                  partition_id="${partition_pair#*:}"
556                  if [ "${partition_id#$disk_id-part}" != "$partition_id" ]; then
557                    ids="${ids:+$ids, }$partition_id"
558                    describe_partition "$(readlink -f "$device")" "$(readlink -f "$partition_id")" "$partition_id" "$(get_mountpoint "${partition_pair%%:*}")"
559                    RET="$(printf %s "$RET" | sed 's/,/\\,/g')"
560                    descriptions="${descriptions:+$descriptions, }$RET"
561                  fi
562                done
563              fi
564            done
565            # Some "partitions" may in fact be at the disk level, e.g. RAID.
566            # List these as well if they haven't already been listed.
567            for partition_pair in $partitions; do
568              partition_id="${partition_pair#*:}"
569              if [ "${partition_id#*-part}" = "$partition_id" ]; then
570                case ", $ids, " in
571                  ", $partition_id, ") ;;
572                  *)
573                    ids="${ids:+$ids, }$partition_id"
574                    describe_disk "$(readlink -f "$partition_id")" "$partition_id"
575                    RET="$(printf %s "$RET" | sed 's/,/\\,/g')"
576                    descriptions="${descriptions:+$descriptions, }$RET"
577                    ;;
578                esac
579              fi
580            done
581            db_subst "$question" RAW_CHOICES "$ids"
582            db_subst "$question" CHOICES "$descriptions"
583            db_input "$priority" "$question" || true
584            db_go
585            db_get "$question"
586            failed_devices=
587            for i in `echo $RET | sed -e 's/, / /g'` ; do
588              real_device="$(readlink -f "$i")"
589              if grub-install --target=i386-pc --force --no-floppy $real_device ; then
590                # We just installed GRUB 2; then also generate grub.cfg.
591                touch /boot/grub/grub.cfg
592              else
593                failed_devices="$failed_devices $real_device"
594              fi
595            done
596
597            if [ "$question" != grub-pc/install_devices ]; then
598              db_set grub-pc/install_devices "$RET"
599              db_fset grub-pc/install_devices seen true
600            fi
601
602            if [ "$failed_devices" ]; then
603              if [ "$UPGRADE_FROM_GRUB_LEGACY" ]; then
604                db_subst grub-pc/install_devices_failed_upgrade FAILED_DEVICES "$failed_devices"
605                db_fset grub-pc/install_devices_failed_upgrade seen false
606                if db_input critical grub-pc/install_devices_failed_upgrade; then
607                  db_go
608                  db_get grub-pc/install_devices_failed_upgrade
609                  if [ "$RET" = true ]; then
610                    db_fset "$question" seen false
611                    db_fset grub-pc/install_devices_failed_upgrade seen false
612                    continue
613                  else
614                    exit 1
615                  fi
616                else
617                  exit 1 # noninteractive
618                fi
619              else
620                db_subst grub-pc/install_devices_failed FAILED_DEVICES "$failed_devices"
621                db_fset grub-pc/install_devices_failed seen false
622                if db_input critical grub-pc/install_devices_failed; then
623                  db_go
624                  db_get grub-pc/install_devices_failed
625                  if [ "$RET" = true ]; then
626                    break
627                  else
628                    db_fset "$question" seen false
629                    db_fset grub-pc/install_devices_failed seen false
630                    continue
631                  fi
632                else
633                  break # noninteractive
634                fi
635              fi
636            fi
637
638            db_get grub-pc/install_devices
639            if [ -z "$RET" ]; then
640              # Reset the seen flag if the current answer is false, since
641              # otherwise we'll loop with no indication of why.
642              db_get grub-pc/install_devices_empty
643              if [ "$RET" = false ]; then
644                db_fset grub-pc/install_devices_empty seen false
645              fi
646              if db_input critical grub-pc/install_devices_empty; then
647                db_go
648                db_get grub-pc/install_devices_empty
649                if [ "$RET" = true ]; then
650                  break
651                else
652                  db_fset "$question" seen false
653                  db_fset grub-pc/install_devices_empty seen false
654                fi
655              else
656                break # noninteractive
657              fi
658            else
659              break
660            fi
661          done
662        fi
663
664        # /boot/grub/ has more chances of being accessible by GRUB
665        for i in /usr/share/grub/unicode.pf2 ; do
666          if test -e $i ; then
667            mkdir -p /boot/grub
668            cp $i /boot/grub/
669          fi
670        done
671
672        if [ "$fix_mixed_system" ]; then
673          # These never contain any valuable information, and they aren't
674          # useful for boot any more, since we just overwrote MBR/PBR.
675          rm -f /boot/grub/{{xfs,reiserfs,e2fs,fat,jfs,minix}_stage1_5,stage{1,2}}
676          # Remove marker file used to indicate that grub-install was run
677          # rather than upgrade-from-grub-legacy.  Since stage2 has been
678          # removed, we don't need this any more.
679          rm -f /boot/grub/grub2-installed
680        fi
681      ;;
682
683      grub-efi-ia32|grub-efi-amd64|grub-efi-ia64|grub-efi-arm|grub-efi-arm64)
684        bootloader_id="$(config_item GRUB_DISTRIBUTOR | tr A-Z a-z | \
685                         cut -d' ' -f1)"
686        case $bootloader_id in
687          kubuntu) bootloader_id=ubuntu ;;
688        esac
689        if [ "$bootloader_id" ] && [ -d "/boot/efi/EFI/$bootloader_id" ]; then
690          case @PACKAGE@ in
691            grub-efi-ia32)  target=i386-efi ;;
692            grub-efi-amd64) target=x86_64-efi ;;
693            grub-efi-ia64)  target=ia64-efi ;;
694            grub-efi-arm)   target=arm-efi ;;
695            grub-efi-arm64) target=arm64-efi ;;
696          esac
697          db_get grub2/force_efi_extra_removable
698          if [ "$RET" = true ]; then
699            FORCE_EXTRA_REMOVABLE="--force-extra-removable"
700          fi
701          run_grub_install --target="$target" "$FORCE_EXTRA_REMOVABLE"
702        fi
703
704        # /boot/grub/ has more chances of being accessible by GRUB
705        for i in /usr/share/grub/unicode.pf2 ; do
706          if test -e $i ; then
707            mkdir -p /boot/grub
708            cp $i /boot/grub/
709          fi
710        done
711      ;;
712
713      grub-ieee1275)
714        case $(dpkg --print-architecture) in
715          ppc64el)
716            # Output may be empty; if so, just update the core image but
717            # don't install it to any PReP partition.
718            prep_bootdev="$(/usr/lib/grub/powerpc-ieee1275/prep-bootdev)"
719            run_grub_install --target=powerpc-ieee1275 $prep_bootdev
720          ;;
721        esac
722      ;;
723
724      grub-yeeloong)
725        run_grub_install --target=mipsel-loongson
726      ;;
727
728      grub-xen)
729        # Install for x86_64 regardless of arch, since a 32-bit userspace can still boot with a 64-bit kernel.
730        mkdir -p /boot/xen
731        run_grub_install --target=x86_64-xen
732        case $(dpkg --print-architecture) in
733          i386)
734            run_grub_install --target=i386-xen
735          ;;
736        esac
737      ;;
738    esac
739
740    # If grub.cfg has been generated, update it.
741    if test -e /boot/grub/grub.cfg && ! running_in_container; then
742      update-grub 3>&-
743    fi
744  ;;
745  abort-upgrade|abort-remove|abort-deconfigure)
746  ;;
747  *)
748    echo "postinst called with unknown argument \`$1'" >&2
749    exit 1
750  ;;
751esac
752
753# dh_installdeb will replace this with shell code automatically
754# generated by other debhelper scripts.
755
756#DEBHELPER#
757
758exit 0
Note: See TracBrowser for help on using the repository browser.