1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510
|
#!/bin/sh
set -e
. /usr/share/debconf/confmodule
log() {
logger -t yaboot-installer "$@"
}
error() {
log "error: $@"
}
info() {
log "info: $@"
}
debug() {
log "debug: $@"
}
writefile () {
cat >>"$1" || die yaboot-installer/conferr "Error writing $2"
}
findfs () {
mount | grep "on /target${1%/} " | cut -d' ' -f1
}
partitions_with_flag () {
/usr/lib/partconf/find-partitions --colons --flag "$1" 2>/dev/null || true
}
db_capb backup
db_progress START 0 6 yaboot-installer/progress
die() {
template="$1"
shift
error "$@"
db_input critical "$template" || [ $? -eq 30 ]
db_go || true
db_progress STOP
exit 1
}
ARCH="$(archdetect)"
info "architecture: $ARCH"
# Install yaboot in /target
db_progress INFO yaboot-installer/apt-install
PACKAGES=yaboot
if [ "$ARCH" = powerpc/powermac_newworld ]; then
PACKAGES="$PACKAGES hfsutils"
fi
if ! apt-install $PACKAGES; then
info "Calling 'apt-install $PACKAGES' failed"
# Hm, unable to install yaboot into /target/, what should we do?
db_input critical yaboot-installer/apt-install-failed || [ $? -eq 30 ]
if ! db_go; then
db_progress STOP
exit 10 # back up to menu
fi
db_get yaboot-installer/apt-install-failed
if [ "$RET" != true ]; then
db_progress STOP
exit 1
fi
fi
# Find the boot partition
db_progress STEP 1
db_progress INFO yaboot-installer/part
# Telling parted to create an Apple_Bootstrap partition doesn't work as well
# as we might like: parted's probe function isn't intelligent enough to know
# about this, and reports the partition as containing whatever filesystem
# was there beforehand.
#
# As a workaround, we only check for partitions with the boot flag set, and
# don't bother checking the filesystem. However, this means that we *must*
# ask the user to confirm the bootstrap partition, otherwise we might
# mistakenly overwrite some other partition that happened to be flagged as
# bootable.
PARTITIONS=
DEFAULT=
bootdev_priority=critical
if [ "$ARCH" = powerpc/powermac_newworld ] && \
db_get partman-newworld/boot_partitions && [ "$RET" ]; then
OLDIFS="$IFS"
IFS=,
for part in $RET; do
IFS="$OLDIFS"
mappart="$(mapdevfs "$part")"
if [ -z "$PARTITIONS" ]; then
DEFAULT="$mappart"
PARTITIONS="$mappart"
else
PARTITIONS="$PARTITIONS, $mappart"
fi
IFS=,
done
IFS="$OLDIFS"
info "partman-supplied bootstrap partitions: $PARTITIONS"
info "partman-supplied default bootstrap partition: $DEFAULT"
if [ "$PARTITIONS" ] && [ "$DEFAULT" = "$PARTITIONS" ]; then
# We have explicit information from partman-newworld that only one
# bootstrap partition is available, so it's safe to bypass this
# question.
bootdev_priority=medium
fi
fi
if [ -z "$PARTITIONS" ]; then
case $ARCH in
powerpc/powermac_newworld)
PARTED_FLAGS='boot'
;;
powerpc/chrp|powerpc/chrp_rs6k|powerpc/chrp_ibm)
PARTED_FLAGS='prep prep-boot'
;;
powerpc/chrp_pegasos)
PARTED_FLAGS=
;;
*)
error 'unknown subarchitecture; allowing any bootable partition'
PARTED_FLAGS='boot'
;;
esac
for flag in $PARTED_FLAGS; do
for part in $(partitions_with_flag "$flag" | cut -d: -f1); do
mappart="$(mapdevfs "$part")"
if [ -z "$PARTITIONS" ]; then
DEFAULT="$mappart"
PARTITIONS="$mappart"
else
PARTITIONS="$PARTITIONS, $mappart"
fi
done
done
if [ "$PARTED_FLAGS" ]; then
info "guessed bootstrap partitions: $PARTITIONS"
info "guessed default bootstrap partition: $DEFAULT"
fi
fi
if [ "$PARTED_FLAGS" ] && [ -z "$PARTITIONS" ]; then
# error: no viable boot partitions found; fall over
die yaboot-installer/nopart 'No bootstrap partitions found'
fi
if [ "$PARTITIONS" ]; then
db_subst yaboot-installer/bootdev DEVICES "$PARTITIONS"
db_set yaboot-installer/bootdev "$DEFAULT"
db_input "$bootdev_priority" yaboot-installer/bootdev || [ $? -eq 30 ]
if ! db_go; then
db_progress STOP
exit 10 # back up to menu
fi
db_get yaboot-installer/bootdev
if [ "$RET" = false ]; then
die yaboot-installer/nopart 'No bootstrap partition selected (?)'
fi
# already devfs-mapped
boot="$RET"
else
# no bootstrap partition on Pegasos
boot=
fi
# Find the root partition
db_progress STEP 1
db_progress INFO yaboot-installer/root
rootdev="$(findfs /)"
[ "$rootdev" ] || die yaboot-installer/noroot 'No root partition found'
slashbootdev="$(findfs /boot)"
[ "$slashbootdev" ] || slashbootdev="$rootdev"
mountvirtfs () {
fstype="$1"
path="$2"
if grep -q "[[:space:]]$fstype\$" /proc/filesystems && \
! grep -q "^[^ ]\+ \+$path " /proc/mounts; then
mkdir -p "$path" || \
die yaboot-installer/mounterr "Error creating $path"
mount -t "$fstype" "$fstype" "$path" || \
die yaboot-installer/mounterr "Error mounting $path"
trap "umount $path" HUP INT QUIT KILL PIPE TERM EXIT
fi
}
# mkofboot needs proc in /target
mountvirtfs proc /target/proc
# ofpath needs sysfs in /target for 2.6
mountvirtfs sysfs /target/sys
# Probe for other OSes.
db_progress STEP 1
db_progress INFO yaboot-installer/os-probing
os-prober >/tmp/os-probed || true
if [ -s /tmp/os-probed ]; then
# Other operating systems are installed, so use a longer timeout.
timeout=100
else
timeout=50
fi
extraglobals=/tmp/yaboot.conf.extraglobals
rm -f "$extraglobals"
extraimages=/tmp/yaboot.conf.extraimages
rm -f "$extraimages"
writeglobals() {
writefile "$extraglobals" 'extra global settings'
}
writeimages() {
writefile "$extraimages" 'extra image records'
}
# Get the Open Firmware path for a device. Requires non-devfs syntax.
map_of_path() {
# TODO: look for shorter name using OF aliases?
chroot /target ofpath "$1" || return 1
}
OLDIFS="$IFS"
IFS=:
# Note that this creates a subshell, so variables set inside this loop won't
# persist outside it.
cat /tmp/os-probed | while read partition title label loadertype; do
IFS="$OLDIFS"
info "probed: $partition:$title:$label:$loadertype"
mappedpartition="$(mapdevfs "$partition")"
debug "mapped: $mappedpartition"
# You only get the first of each non-Linux OS here, as that's all
# yaboot supports without painful hacking. Sorry.
case $loadertype in
linux)
IFS=:
linux-boot-prober "$partition" | while read \
rootpart bootpart label kernel initrd params; do
IFS="$OLDIFS"
info "linux-boot-probed:" \
"$rootpart:$bootpart:$label:$kernel:$initrd:$params"
ofrootpart="$(map_of_path "$mappedpartition")" || continue
debug "OF root partition: $ofrootpart"
# bootpart may or may not be in devfs syntax.
mappedbootpart="$(mapdevfs "$bootpart")" || \
mappedbootpart="$bootpart"
debug "mapped boot partition: $mappedbootpart"
ofbootpart="$(map_of_path "$mappedbootpart")" || continue
debug "OF boot partition: $ofbootpart"
if [ -z "$label" ]; then
label="$title"
fi
# Prepend the last part of the partition name to the label,
# for uniqueness and (I hope) clarity, given that we don't
# have a way to display a useful description in yaboot.
label="${mappedbootpart##*/}-$label"
if echo "$kernel" | grep -q '^/boot/' && \
[ "$mappedbootpart" != "$mappedpartition" ]; then
# separate /boot partition
kernel="${kernel#/boot}"
initrd="${initrd#/boot}"
fi
writeimages <<EOF
# This entry automatically added by the Debian installer for an existing
# Linux installation on $mappedpartition.
image=$ofbootpart,$kernel
label=$label
root=$ofrootpart
append="$params"
EOF
if [ -n "$initrd" ]; then
writeimages <<EOF
initrd=$ofbootpart,$initrd
EOF
fi
IFS=:
done
IFS="$OLDIFS"
;;
macosx)
if ! [ "$macosx" ]; then
macosx=1
echo "macosx=$mappedpartition" | writeglobals
fi
;;
macos)
if ! [ "$macos" ]; then
macos=1
echo "macos=$mappedpartition" | writeglobals
fi
;;
*)
info "unhandled: $partition:$title:$label:$loadertype"
;;
esac
IFS=:
done
IFS="$OLDIFS"
# Generate yaboot.conf
db_progress STEP 1
db_progress INFO yaboot-installer/conf
root="`mapdevfs "$rootdev"`"
slashboot="`mapdevfs "$slashbootdev"`"
partnr="`printf %s "$slashboot" | sed 's/[^0-9]*\([0-9]\)/\1/'`"
if [ "$ARCH" = powerpc/chrp_pegasos ]; then
# Pegasos OF starts counting at 0.
partnr="$(($partnr - 1))"
fi
disk="`printf %s "$slashboot" | sed 's/[0-9].*//'`"
ofpath="$(map_of_path "$disk" || true)"
if [ -e /target/boot/vmlinux ]; then
kernel=/boot/vmlinux
else
kernel=/vmlinux
fi
if [ -e /target/boot/initrd.img ]; then
initrd=/boot/initrd.img
elif [ -e /target/initrd.img ]; then
initrd=/initrd.img
else
initrd=
fi
# Is /boot on a separate partition?
if [ "$slashboot" != "$root" ]; then
kernel="${kernel#/boot}"
initrd="${initrd#/boot}"
fi
# Work out user parameters.
user_params="$(echo $(user-params))" || true
# If we're using an HVC virtual serial console, put that in append=.
# TODO: should we do this for other types of serial console too?
OLDIFS="$IFS"
IFS=' '
for arg in $(cat /proc/cmdline); do
IFS="$OLDIFS"
case $arg in
console=*)
defconsole="$arg"
;;
esac
IFS=' '
done
IFS="$OLDIFS"
case $defconsole in
hvc*)
user_params="console=$defconsole${user_params:+ $user_params}"
;;
esac
if [ "$ARCH" = powerpc/chrp_pegasos ]; then
# Create a /boot/yaboot symlink, and get yaboot to maintain it for us.
# TODO: a symlink is suboptimal because it doesn't work if /boot != /.
# mkofboot should probably be changed to take a copy instead.
ln -sf /usr/lib/yaboot/yaboot /target/boot/yaboot
yaboot_location=/boot/yaboot
else
yaboot_location=/usr/lib/yaboot/yaboot
fi
# we generate our own yaboot.conf kernel (yabootconfig is horribly broken)
# cjwatson: a little more justification of that would have been nice ...
# but it does seem clear that yabootconfig isn't flexible enough for our
# needs, e.g. OS probing.
rm -f /target/etc/yaboot.conf
writeyabootconf() {
writefile /target/etc/yaboot.conf yaboot.conf
}
writeyabootconf <<EOF
## yaboot.conf generated by debian-installer
##
## run: "man yaboot.conf" for details. Do not make changes until you have!!
## see also: /usr/share/doc/yaboot/examples for example configurations.
##
## For a dual-boot menu, add one or more of:
## bsd=/dev/hdaX, macos=/dev/hdaY, macosx=/dev/hdaZ
EOF
if [ "$boot" ]; then
writeyabootconf <<EOF
boot=$boot
EOF
fi
if [ "$ofpath" ]; then
writeyabootconf <<EOF
device=$ofpath
EOF
else
info "ofpath returned nothing; leaving out device= line and praying"
fi
writeyabootconf <<EOF
partition=$partnr
root=$root
timeout=$timeout
install=$yaboot_location
EOF
if [ "$ARCH" = powerpc/powermac_newworld ]; then
writeyabootconf <<EOF
magicboot=/usr/lib/yaboot/ofboot
EOF
fi
writeyabootconf <<EOF
enablecdboot
EOF
if [ -s "$extraglobals" ]; then
cat "$extraglobals" | writeyabootconf
rm -f "$extraglobals"
fi
writeyabootconf <<EOF
image=$kernel
label=Linux
read-only
EOF
if [ "$initrd" ]; then
writeyabootconf <<EOF
initrd=$initrd
EOF
fi
if [ "$user_params" ]; then
writeyabootconf <<EOF
append="$user_params"
EOF
fi
writeyabootconf <<EOF
image=$kernel.old
label=old
read-only
EOF
if [ "$initrd" ]; then
writeyabootconf <<EOF
initrd=$initrd.old
EOF
fi
if [ "$user_params" ]; then
writeyabootconf <<EOF
append="$user_params"
EOF
fi
if [ -s "$extraimages" ]; then
cat "$extraimages" | writeyabootconf
rm -f "$extraimages"
fi
# Install into bootstrap partition
db_progress STEP 1
db_progress INFO yaboot-installer/ybin
if [ "$ARCH" = powerpc/chrp_pegasos ]; then
if [ "$slashboot" = "$root" ]; then
yabootpath=boot/yaboot
else
yabootpath=yaboot
fi
db_subst yaboot-installer/of_pegasos OF_BOOT_DEVICE "$ofpath$partnr"
db_subst yaboot-installer/of_pegasos OF_BOOT_FILE "$yabootpath"
db_subst yaboot-installer/of_pegasos BOOT "boot $ofpath$partnr $yabootpath"
db_input high yaboot-installer/of_pegasos || true
else
log-output -t yaboot-installer chroot /target mkofboot -v -f || \
die yaboot-installer/ybinerr "mkofboot failed with exit status $?"
fi
# Done!
db_progress STEP 1
db_progress STOP
db_input medium yaboot-installer/success || [ $? -eq 30 ]
db_go || true
|