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