* updated tzdata (2024a -> 2024b)
[t2sde.git] / package / base / stone / stone_mod_install.sh
blob96f619a63cf9e15e5281f3ca10fa47540d621ae8
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # T2 SDE: package/*/stone/stone_mod_install.sh
3 # Copyright (C) 2004 - 2024 The T2 SDE Project
4 # Copyright (C) 1998 - 2003 ROCK Linux Project
5 #
6 # This Copyright note is generated by scripts/Create-CopyPatch,
7 # more information can be found in the files COPYING and README.
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License version 2.
11 # --- T2-COPYRIGHT-NOTE-END ---
13 # TODO:
14 # - check error, esp. of cryptsetup and lvm commands and display red alert on error
15 # - avoid all direct user input, so the installer works in GUI variants
17 # detect platform once
18 platform=$(uname -m)
19 platform2=$(grep '\(platform\|type\)' /proc/cpuinfo) platform2=${platform2##*: }
20 [ -e /sys/firmware/efi ] && platform="$platform-efi" ||
21 case $platform in
22 alpha)
24 arm*|ia64|riscv*)
25 platform=
27 hppa*)
29 mips*)
31 ppc*)
32 # TODO: prep, ps3, opal, ...
33 case "$platform2" in
34 CHRP|PowerMac|PS3)
35 platform="$platform-$platform2" ;;
36 *) platform= ;;
37 esac
39 sparc*)
40 platform="$platform-$platform2"
41 grep -q gpt /sys/firmware/devicetree/base/packages/disk-label/supported-labels 2>/dev/null &&
42 platform="$platform-gpt"
44 i?86|x86_64)
45 platform="$platform-pc"
46 # TODO: better test for 528m and 2gb BIOS limits
47 atadrv="$(cat /sys/bus/scsi/devices/host0/scsi_host/host0/proc_name 2>/dev/null)"
48 [ "$atadrv" = pata_legacy -o "$atadrv" = pata_isapnp ] &&
49 platform="$platform-legacy"
50 unset atadrv
53 platform=
55 esac
57 mapper2lvm() {
58 local x="${1//--/ }"
59 x="${x/-//}" x="${x// /-}"
60 echo "$x"
63 part_mounted_action() {
64 if gui_yesno "Do you want to unmount the filesystem on $1?"
65 then umount /dev/$1; fi
68 part_activepv_action() {
69 if gui_yesno "Do you want to remove physical LVM $1 from volume group $2?"
70 then vgreduce $2 /dev/$1; fi
73 part_swap_action() {
74 if gui_yesno "Do you want to deactivate the swap space on $1?"
75 then swapoff /dev/$1; fi
78 part_mount() {
79 local dev=$1 compress="$2" dir="$3"
81 if [ -z "$dir" ]; then
82 dir="/ /boot /home /srv /var"
83 [ -d /sys/firmware/efi ] && dir="${dir/boot/boot/efi}"
84 local d
85 for d in $dir; do
86 grep -q " /mnt${d%/} " /proc/mounts || break
87 done
89 gui_input "Mount device $dev on directory
90 (for example ${dir// /, }, ...)" "${d:-/}" dir
93 if [ "$dir" ]; then
94 dir="$(echo $dir | sed 's,^/*,,; s,/*$,,')"
95 # check if at least a rootfs / is already mounted
96 if [ -z "$dir" ] || grep -q " /mnt " /proc/mounts
97 then
98 mkdir -p /mnt/$dir
99 [ "$compress" ] && mount -o "$compress" $dev /mnt/$dir 2>/dev/null ||
100 mount $dev /mnt/$dir
101 else
102 gui_message "Please mount a root filesystem first."
107 part_mkswap() {
108 local dev=$1
109 mkswap -L swap $dev; swapon $dev
112 part_mkfs() {
113 local dev=$1 fs=$2 mnt=$3 label= opts=
114 cmd="gui_menu part_mkfs 'Create filesystem on $dev'"
116 case "$mnt" in
117 /) label="root" ;;
118 /home) label="home" ;;
119 /boot) label="swap" ;;
120 /boot/efi) label="efi" ;;
121 esac
123 maybe_add() {
124 local l=
125 [ "$label" -a "$5" ] && l="$5 $label"
126 [ $1 = $fs ] && opts="$3 $4 $l"
127 if type -p $3 >/dev/null; then
128 cmd="$cmd '$1 ($2 filesystem)' \
129 'type wipefs 2>/dev/null && wipefs -a $dev; $3 $4 $l $dev'"
133 maybe_add btrfs 'Better, b-tree, CoW journaling' 'mkfs.btrfs' '-f' '-L'
134 maybe_add bcachefs 'Bcache CoW file system' 'mkfs.bcachefs' '-f' '-l'
135 maybe_add ext4 'journaling, extents' 'mkfs.ext4' '' '-L'
136 maybe_add ext3 'journaling' 'mkfs.ext3' '' '-L'
137 maybe_add ext2 'non-journaling' 'mkfs.ext2' '' '-L'
138 maybe_add jfs 'IBM journaling' 'mkfs.jfs' '' '-L'
139 maybe_add reiserfs 'journaling' 'mkfs.reiserfs' '' '-l'
140 maybe_add xfs 'SGI journaling' 'mkfs.xfs' '-f' '-l'
141 maybe_add fat 'File Allocation Table' 'mkfs.fat' '' '-n'
143 [ "$fs" -a "$fs" != any ] && cmd="$opts $dev"
145 if eval "$cmd"; then
146 part_mount $dev "compress=zstd" $mnt
150 part_decrypt() {
151 local dev=$1
152 local dir=$2
154 if [ ! "$dir" ]; then
155 dir="root home swap"
156 local d
157 for d in $dir; do
158 [ -e /dev/mapper/$dir ] || break
159 done
160 gui_input "Mount device $dev on directory
161 (for example ${dir// /, }, ...)" "${d:-/}" dir
164 if [ "$dir" ]; then
165 # TBC
166 dir="$(echo $dir | sed 's,^/*,,; s,/*$,,')"
167 cryptsetup luksOpen --disable-locks $dev $dir
171 part_crypt() {
172 local dev=$1; shift
173 local mnt=$1; shift
175 # --pbkdf=pbkdf2
176 cryptsetup luksFormat --disable-locks "$@" $dev || return
178 part_decrypt $dev $mnt
181 vg_add_pv() {
182 vg="$2"
183 [ "$vg" ] || gui_input "Add physical volume $1 to logical volume group:" "vg0" vg
184 if [ "$vg" ]; then
185 if vgs $vg 2>/dev/null; then
186 vgextend $vg $1
187 else
188 vgcreate $vg $1
193 part_pvcreate() {
194 local dev=$1
195 pvcreate $dev
196 vg_add_pv $dev $2
199 part_unmounted_action() {
200 local dev=$1 stype=$2
202 type=$(blkid --match-tag TYPE /dev/$dev)
203 type=${type#*\"}; type=${type%\"*}
204 [ "$type" = swsuspend ] && type="swap"
206 local cmd="gui_menu part $dev"
207 local active=1
208 [[ "$stype" = "lv" && "$(lvs -o active --noheadings /dev/$dev)" != *active ]] && active=
210 if [ "$active" ]; then
211 [ "$type" -a "$type" != "swap" -a "$type" != "crypto_LUKS" ] &&
212 cmd="$cmd \"Mount existing $type filesystem\" \"part_mount /dev/$dev\""
213 if [ "$type" = "crypto_LUKS" ]; then
214 cmd="$cmd \"Activate encrypted LUKS\" \"part_decrypt /dev/$dev\""
215 #cmd="$cmd \"Deactivate encrypted LUKS\" \"part_decrypt /dev/$dev\""
218 [ "$type" = "swap" ] &&
219 cmd="$cmd \"Activate existing swap space\" \"swapon /dev/$dev\""
221 cmd="$cmd \"Create filesystem\" \"part_mkfs /dev/$dev\""
222 cmd="$cmd \"Create swap space\" \"part_mkswap /dev/$dev\""
223 cmd="$cmd \"Encrypt using LUKS cryptsetup\" \"part_crypt /dev/$dev '' --type luks1\""
224 cmd="$cmd \"Encrypt using LUKS2 cryptsetup\" \"part_crypt /dev/$dev\""
226 [ "$stype" != "lv" ] &&
227 cmd="$cmd \"Create physical LVM volume\" \"part_pvcreate /dev/$dev\""
230 if [ "$stype" = "lv" ]; then
231 [ "$active" ] &&
232 cmd="$cmd 'Deactivate logical LVM volume' 'lvchange -an $dev'" ||
233 cmd="$cmd 'Activate logical LVM volume' 'lvchange -ay $dev'"
234 cmd="$cmd \"Rename logical LVM volume\" \"lvm_rename $dev lv\""
235 cmd="$cmd \"Remove logical LVM volume\" \"lvremove $dev\""
236 elif [ "$type" = "LVM2_member" ]; then
237 cmd="$cmd 'Add physical LVM volume to volume group' 'vg_add_pv /dev/$dev'"
238 cmd="$cmd 'Remove physical LVM volume' 'pvremove /dev/$dev'"
241 eval $cmd
244 part_add() {
245 local dev
246 [ ! -L /dev/$1 ] && dev=/dev/$1 || dev=$(readlink /dev/$1)
248 local action="unmounted" location="currently not mounted"
249 if grep -q "^$dev " /proc/swaps; then
250 action=swap location="swap <no mount point>"
251 elif grep -q "^$dev " /proc/mounts; then
252 action=mounted
253 location="`grep "^$dev " /proc/mounts | cut -d ' ' -f 2 |
254 sed "s,^/mnt,," `"
255 [ "$location" ] || location="/"
258 # save volume information
259 disktype $dev > /tmp/stone-install 2>/dev/null
260 type="`grep /tmp/stone-install -v -e '^ ' -e '^Block device' \
261 -e '^Partition' -e '^---' |
262 sed -e 's/[,(].*//' -e '/^$/d' -e 's/ $//' | tail -n 1`"
263 size="`grep 'Block device, size' /tmp/stone-install |
264 sed 's/.* size \(.*\) (.*/\1/'`"
265 if [ -z "$type" ]; then
266 type=$(blkid --match-tag TYPE $dev)
267 type=${type#*\"}; type=${type%\"*}
270 # active LVM pv?
271 if [[ "$type" = *LVM2*volume* ]]; then
272 local vg=`pvs --noheadings -o vgname $dev`
273 vg="${vg##* }"
274 [ "$vg" ] && action=activepv && location="$vg" && set "$1" "$vg"
277 dev=${1#*/}; dev=${dev#mapper/}
278 cmd="$cmd '`printf "%-6s %-24s %-10s" $dev "$location" "$size"` ${type//_/ }' 'part_${action}_action $1 $2'"
281 function join() {
282 local IFS="$1"; shift
283 echo "$*"
286 disk_partition() {
287 local dev=$1
288 local typ=$2
290 # sizes in MB
291 local size=$(($(blockdev --getsz $dev) / 2 / 1024))
292 si=0
293 for p in $dev[0-9]*; do
294 [ -e $p ] || continue
295 size=$((size - $(blockdev --getsz $p) / 2 / 1024))
296 # determine last used partition, too
297 local i=${p#$dev}
298 [ $i -gt $si ] && si=$i
299 done
301 local cmd="gui_menu part 'Partition $dev bootable for this platform?'"
303 cmd="$cmd 'Erasing all data' 'si=0'"
304 # TODO: check patform is efi and type is GPT?
305 [ $si -gt 0 -a $size -gt 4096 ] &&
306 cmd="$cmd 'Adding partitions in free space' si=$si"
308 eval $cmd || return
310 # if re-partition: reset size to all
311 [ "$si" = 0 ] && size=$(($(blockdev --getsz $dev) / 2 / 1024))
312 local swap=$((size / 20))
313 local boot=512
315 local fdisk="sfdisk -W always"
316 local script=()
317 local postscript=()
318 local fs=()
319 local any=any
321 # dedicated swap partition or lvm?
322 local _swap=$swap
323 [[ "$typ" = *lvm* ]] && _swap=0 && any=lvm
325 case $platform in
326 alpha)
327 fdisk=parted
328 fs+=("${dev}2 $any /")
329 fs+=("${dev}1 ext3 /boot")
330 script+=("mklabel
333 mkpart 2048s ${boot}m
334 mkpart ${boot}m $((boot + _swap))m")
336 [ $_swap != 0 ] &&
337 script+=("$mkpart $((boot + _swap))m 100%") fs+=("${dev}3 swap")
339 *-efi)
340 script+=("label:gpt")
341 script+=("size=128m, type=uefi")
342 script+=("size=$((size - 128 - _swap))m, type=linux")
343 fs+=("${dev}$((si + 2)) $any /")
344 fs+=("${dev}$((si + 1)) fat /boot/efi")
346 [ $_swap != 0 ] &&
347 script+=("type=swap") fs+=("${dev}$((si + 3)) swap")
349 hppa*)
350 fs+=("${dev}3 $any /")
351 fs+=("${dev}2 ext3 /boot")
353 script+=("label:dos
354 size=32m, type=f0
355 size=${boot}m, type=83
356 size=$((size - _swap))m, type=83")
357 [ $_swap != 0 ] &&
358 script+=("type=82") fs+=("${dev}4 swap")
360 mips64)
361 boot=8 # volhdr
362 # TODO: if rootfs too modern, or lvm, we need a /boot part
363 fs+=("${dev}1 $any /")
364 script+=("label:sgi
365 start=${boot}m, size=$((size - _swap))m, type=83")
367 # the rounding is way off, so - 20m rounding safety :-/
368 [ $_swap != 0 ] &&
369 script+=("start=$((size - _swap + boot))m, size=$((_swap - boot - 20))m, type=82") &&
370 fs+=("${dev}2 swap")
372 script+=("9: size=8m, type=0
373 11: type=6")
375 ppc*CHRP)
376 # TODO: typ, luks, lvm, ...
377 fs+=("${dev}2 $any /")
378 script+=("label:dos
379 size=4m, type=41
380 size=$((size - _swap))m, type=83")
382 [ $_swap != 0 ] &&
383 script+=("type=82") fs+=("${dev}3 swap")
385 ppc*PowerMac)
386 fdisk=mac-fdisk
387 fs+=("${dev}3 $any /")
388 script+=("i
390 b 2p
391 c 3p $((size - _swap))m linux")
393 [ $_swap != 0 ] &&
394 script+=("c 4p 4p swap") fs+=("${dev}4 swap")
396 script+=("w
401 sparc*-gpt)
402 script+=("label:gpt")
403 script+=("size=2m, type=biosboot")
404 script+=("size=$((size - _swap))m, type=linux")
405 fs+=("${dev}$((si + 1)) $any /")
407 [ $_swap != 0 ] &&
408 script+=("type=swap") fs+=("${dev}$((si + 2)) swap")
410 sparc*)
411 # TODO: silo vs grub2 have different requirements
412 # TODO: support sun4v-gpt
413 script+=("label:sun
414 size=$((boot))m, type=83
415 type=82
416 start=0, type=W")
418 # sfdisk has a "hard" time creating more than 2 parts w/ whole-disk
419 local i=2
420 if [ $_swap != 0 ]; then
421 postscript+=("sfdisk --delete ${dev} 2")
422 postscript+=("echo 'size=${_swap}m, type=82' | sfdisk -N 2 ${dev}")
423 postscript+=("echo 'type=83' | sfdisk -N 4 ${dev}")
425 fs+=("${dev}2 swap")
428 fs+=("${dev}$i $any /")
429 fs+=("${dev}1 ext3 /boot")
432 script+=("label:dos")
433 local i=1
435 [[ "$platform" != ppc*PS3 && "$platform" != *86*-legacy ]] &&
436 boot=0
438 [ $boot != 0 ] && script+=("size=$((boot))m, type=83") && ((i++))
439 [ $_swap != 0 ] && fs+=("${dev}$((i++)) swap") script+=("size=${_swap}m, type=82")
441 script+=("type=83") fs+=("${dev}$((i++)) $any /")
443 [ $boot != 0 ] && fs+=("${dev}1 ext3 /boot")
445 esac
447 # re-partition or append?
448 if [ "$si" = 0 ]; then
449 # partition
450 wipefs --all $dev
451 dd if=/dev/zero of=$dev seek=1 count=1 # mostly for Apple PowerPac parts
452 else
453 fdisk="$fdisk -a"
454 script=("${script[@]:1}") # removed 1st "label:*"
457 join $'\n' "${script[@]}" | $fdisk $dev
459 # postscript fixup, due less than stellar sfdisk
460 for cmd in "${postscript[@]}"; do
461 eval "$cmd"
462 done
464 # create fs
465 for f in "${fs[@]}"; do
466 set $f
467 local d=$1
468 local fs=$2
469 local mnt=$3
471 # fix device partitions separated w/ p
472 [[ $dev = *[0-9] ]] && d=${dev}p${d#$dev}
474 if [[ "$typ" = *luks* && ("$mnt" = / || "$fs" = swap) ]]; then
475 local name=root
476 [ "$fs" = swap ] && name=swap
477 part_crypt $d $name
478 d=/dev/mapper/$name
481 case $fs in
482 lvm) part_pvcreate $d vg0
483 lv_create vg0 linear ${swap}m swap
484 lv_create vg0 linear 100%FREE root
485 part_mkswap /dev/vg0/swap
486 part_mkfs /dev/vg0/root any /
488 swap) part_mkswap $d
490 *) part_mkfs $d $fs $mnt
492 esac
493 done
496 disk_action() {
497 if grep -q "^/dev/$1 " /proc/swaps /proc/mounts; then
498 gui_message "Partitions from $1 are currently in use, so you
499 can't modify this partition table."
500 return
503 local cmd="gui_menu disk 'Edit partition table of $1'"
505 cmd="$cmd \"Automatically partition${platform:+ bootable for this platform ($platform)}:\" ''"
506 cmd="$cmd \"Classic partitions\" \"disk_partition /dev/$1\""
507 if [ "$platform" ]; then
508 case "$platform" in
509 #*efi|*CHRP|*86*-pc)
511 type -p cryptsetup >/dev/null &&
512 cmd="$cmd \"Encrypted partitions\" \"disk_partition /dev/$1 luks\""
513 type -p lvm >/dev/null &&
514 cmd="$cmd \"Logical Volumes\" \"disk_partition /dev/$1 lvm\""
515 type -p cryptsetup >/dev/null && type -p lvm >/dev/null &&
516 cmd="$cmd \"Encrypted Logical Volumes\" \"disk_partition /dev/$1 luks+lvm\""
518 esac
520 cmd="$cmd '' ''"
522 cmd="$cmd \"Edit partition table:\" ''"
523 for x in cfdisk fdisk pdisk mac-fdisk parted; do
524 type -p $x >/dev/null &&
525 cmd="$cmd \"$x\" \"$x /dev/$1\""
526 done
528 eval $cmd
531 lvm_rename() {
532 local dev=$1
533 echo $dev $type
534 gui_input "Rename $dev:" "${dev#*/}" name
536 if [ "$2" = vg ]; then
537 vgrename $dev $name
538 else
539 lvrename $dev $name
544 lv_create() {
545 local dev=$1 type=$2
546 size=$3 name=$4
547 stripes="--config allocation/raid_stripe_all_devices=1"
549 if [ ! "$size" ]; then
550 #size=$(vgdisplay $dev | grep Free | sed 's,.*/,,; s, <,,; s/ //g ')
551 size="100%FREE"
552 gui_input "Logical volume size:" "$size" size
555 if [ "$type" = "striped" ]; then
556 stripes=$(vgs --noheadings -o pv_count $dev)
557 stripes=${stripes:+-i $stripes}
560 if [ "$size" ]; then
561 [ "$name" ] || gui_input "Logical volume name:" "" name
562 [[ "$size" = *%* ]] && size="-l $size" || size="-L $size"
563 lvcreate $size --type $type $stripes $dev ${name:+-n $name}
567 vg_action() {
568 local cmd="gui_menu vg 'Volume Group $1'"
570 cmd="$cmd 'Create Linear logical volume' 'lv_create $1 linear'"
571 cmd="$cmd 'Create Striped logical volume' 'lv_create $1 striped'"
572 cmd="$cmd 'Create RAID 0 logical volume' 'lv_create $1 raid0'"
573 cmd="$cmd 'Create RAID 1 logical volume' 'lv_create $1 raid1'"
574 cmd="$cmd 'Create RAID 5 logical volume' 'lv_create $1 raid5'"
575 cmd="$cmd 'Create RAID 6 logical volume' 'lv_create $1 raid6'"
576 cmd="$cmd 'Create RAID 10 logical volume' 'lv_create $1 raid10'"
577 cmd="$cmd '' ''"
578 cmd="$cmd 'Activate all volumes in group' 'vgchange -ay $1'"
579 cmd="$cmd 'Deactivate all volumes in group' 'vgchange -an $1'"
580 cmd="$cmd 'Rename volume group' 'lvm_rename $1 vg'"
581 cmd="$cmd 'Remove volume group' 'vgremove $1'"
582 cmd="$cmd 'Display low-level information' 'gui_cmd \"display $1\" vgdisplay $1'"
584 eval $cmd
587 disk_add() {
588 local x found=0
590 local vendor model # read w/ whitespaces stripped:
591 read vendor < <(cat /sys/block/$1/device/vendor 2>/dev/null)
592 read model < <(cat /sys/block/$1/device/model 2>/dev/null)
593 read vendor <<< "$vendor $model"
595 cmd="$cmd 'Edit partition table of $1${vendor:+ ($vendor)}:' 'disk_action $1'"
597 local lbs=$(< /sys/block/$1/queue/logical_block_size)
598 local pbs=$(< /sys/block/$1/queue/physical_block_size)
600 if [ "$lbs" = 512 -a "$pbs" != 4096 ] && type -p nvme >/dev/null; then
601 nvme id-ns -H /dev/$1 2>/dev/null | grep -q "LBA Format.*4096" &&
602 pbs=4096
605 [ "$lbs" = 512 -a "$pbs" = 4096 ] &&
606 cmd="$cmd 'Warning: likely not formatted AF/4Kn for best performance!' ''"
607 [ "$lbs" != 512 -a "$lbs" != 4096 ] &&
608 cmd="$cmd 'Warning: formated w/ unsupported sector size ($lbs)!' ''"
610 # TODO: maybe better /sys/block/$1/$1* ?
611 for x in $(cd /dev; ls $1[0-9p]* 2> /dev/null); do
612 part_add $x
613 found=1
614 done
615 [ $found = 0 ] && cmd="$cmd 'Partition table is empty.' ''"
616 cmd="$cmd '' ''"
619 vg_add() {
620 local x= found=0
622 cmd="$cmd 'Logical volumes of $1:' 'vg_action $1'"
624 [ -x /sbin/lvs ] &&
625 for x in $(lvs --noheadings -o lv_path $1 2> /dev/null); do
626 x=${x#/dev/}
627 part_add $x lv
628 found=1
630 # remove from raw device-mapper list
631 x=$(readlink /dev/$x)
632 volumes="${volumes/ ${x#/dev/} /}"
633 done
634 if [ $found = 0 ]; then
635 cmd="$cmd 'No logical volumes.' ''"
638 cmd="$cmd '' ''"
641 main() {
642 $STONE general set_keymap
644 local install_now=0
645 while [ $install_now = 0 ]; do
646 cmd="gui_menu install 'Storage setup: Partitions and mount-points
648 Modify your storage layout: create file-systems, swap-space, encrypt and mount them. You can also use advanced low-level tools on the command line.'"
650 local found=0
651 volumes=""
652 for x in /sys/block/*; do
653 [ ! -e $x/device -a ! -e $x/dm ] && continue
654 x=${x#/sys/block/}
656 # media? udevadm info -q property --name=/dev/...
657 [[ "$x" = fd[0-9]* || "$x" = sr[0-9]* ]] && continue
659 # LVM Device Mapper?
660 if [ -e /sys/block/$x/dm ]; then
661 if [ -e /sys/block/$x/dm/name ]; then
662 x=$(< /sys/block/$x/dm/name)
663 [[ $x = *_rimage* || $x = *_rmeta* ]] && continue
665 volumes="${volumes} mapper/$x "
666 else
667 disk_add $x
669 found=1
670 done
672 [ -x /sbin/vgs ] &&
673 for x in $(vgs --noheadings -o name 2> /dev/null); do
674 vg_add "$x"
675 found=1
676 done
678 # any other remaining device-mapper, e.g. LUKS cryptosetup
679 if [ "$volumes" ]; then
680 for x in $volumes; do
681 part_add $x
682 done
683 cmd="$cmd '' ''"
686 if [ $found = 0 ]; then
687 cmd="$cmd 'No storage found!' ''"
690 cmd="$cmd 'Install the system ...' 'install_now=1'"
692 eval "$cmd" || break
694 if [ "$install_now" = 1 ] && ! grep -q " /mnt" /proc/mounts; then
695 gui_yesno "No storage mounted to /mnt, continue anyway?" ||
696 install_now=0
698 done
700 if [ "$install_now" -ne 0 ]; then
701 $STONE packages
703 mount -v --bind /dev /mnt/dev
704 cat > /mnt/tmp/stone_postinst.sh << EOT
705 #!/bin/bash
706 mount -v /proc
707 mount -v /sys
708 . /etc/profile
709 stone setup
710 umount -v /dev
711 umount -v /proc
712 umount -v /sys
714 chmod +x /mnt/tmp/stone_postinst.sh
715 rm -f /mnt/etc/mtab
716 # TODO: tr mapper2lvm
717 sed -n '/ \/mnt[/ ]/s,/mnt/\?,/,p' /proc/mounts |
718 # convert mapper to 1st class lvm names
719 while read dev x; do
720 if [[ "$dev" = *mapper* ]]; then
721 local y=/dev/$(mapper2lvm ${dev#/dev/mapper/})
722 [ -e $y ] && dev=$y
724 echo "$dev $x"
725 done > /mnt/etc/mtab
727 cd /mnt; chroot . ./tmp/stone_postinst.sh
728 rm -fv ./tmp/stone_postinst.sh
730 kexec=$(type -p kexec)
732 if gui_yesno "Do you want to un-mount the filesystems and reboot${kexec:+ (via kexec)} now?"
733 then
734 # try to re-boot via kexec, if available
735 if [ "$kexec" ]; then
736 cmdline=$(< /proc/cmdline)
737 # extract root=
738 if [ -e /mnt/boot/grub/grub.cfg ]; then
739 root=$(sed -n "/.*\(root=.*\)/{ s//\1/p; q}" /mnt/boot/grub/grub.cfg)
740 elif [ -e /mnt/boot/etc/kboot.conf ]; then
741 root=$(sed -n "/.*\(root=[^\"']*\).*/{ s//\1/p; q}" /mnt/boot/etc/kboot.conf)
742 else
743 root=$(grep ' / ' /mnt/etc/fstab | tail -n 1 | sed 's, .*,,')
744 root=${root:+root=$root}
746 # determine kernel image, from cmdline or installed files
747 kernel="BOOT_IMAGE= $cmdline" kernel=${kernel##*BOOT_IMAGE=} kernel=${kernel%% *}
748 kernel="${kernel//*\//}"
749 if [ "$kernel" ]; then
750 kernel="boot/$kernel"
751 else
752 # any vmlinu*
753 kernel="$(cd /mnt; echo boot/vmlinu[xz]-*)"
754 kernel="${kernel##* }" # last, compressed if both
756 kexec -l /mnt/$kernel --initrd="/mnt/${kernel/vmlinu?/initrd}" \
757 --command-line="$cmdline $root"
759 shutdown -r now
760 else
761 echo
762 echo "You might want to umount all filesystems now and reboot"
763 echo "the system now using the commands:"
764 echo
765 echo " shutdown -r now"
766 echo
767 echo "Or by executing 'shutdown -r now' which will run the above commands."
768 echo