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
6 # This Copyright note is generated by scripts/Create-CopyPatch,
7 # more information can be found in the files COPYING and README.
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 ---
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
19 platform2
=$
(grep '\(platform\|type\)' /proc
/cpuinfo
) platform2
=${platform2##*: }
20 [ -e /sys
/firmware
/efi
] && platform
="$platform-efi" ||
32 # TODO: prep, ps3, opal, ...
35 platform
="$platform-$platform2" ;;
40 platform
="$platform-$platform2"
41 grep -q gpt
/sys
/firmware
/devicetree
/base
/packages
/disk-label
/supported-labels
2>/dev
/null
&&
42 platform
="$platform-gpt"
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"
59 x
="${x/-//}" x
="${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
74 if gui_yesno
"Do you want to deactivate the swap space on $1?"
75 then swapoff
/dev
/$1; fi
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}"
86 grep -q " /mnt${d%/} " /proc
/mounts ||
break
89 gui_input
"Mount device $dev on directory
90 (for example ${dir// /, }, ...)" "${d:-/}" dir
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
99 [ "$compress" ] && mount
-o "$compress" $dev /mnt
/$dir 2>/dev
/null ||
102 gui_message
"Please mount a root filesystem first."
109 mkswap
-L swap
$dev; swapon
$dev
113 local dev
=$1 fs
=$2 mnt
=$3 label
= opts
=
114 cmd
="gui_menu part_mkfs 'Create filesystem on $dev'"
118 /home
) label
="home" ;;
119 /boot
) label
="swap" ;;
120 /boot
/efi
) label
="efi" ;;
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"
146 part_mount
$dev "compress=zstd" $mnt
154 if [ ! "$dir" ]; then
158 [ -e /dev
/mapper
/$dir ] ||
break
160 gui_input
"Mount device $dev on directory
161 (for example ${dir// /, }, ...)" "${d:-/}" dir
166 dir
="$(echo $dir | sed 's,^/*,,; s,/*$,,')"
167 cryptsetup luksOpen
--disable-locks $dev $dir
176 cryptsetup luksFormat
--disable-locks "$@" $dev ||
return
178 part_decrypt
$dev $mnt
183 [ "$vg" ] || gui_input
"Add physical volume $1 to logical volume group:" "vg0" vg
185 if vgs
$vg 2>/dev
/null
; then
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"
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
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'"
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
253 location
="`grep "^
$dev " /proc/mounts | cut -d ' ' -f 2 |
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%\"*}
271 if [[ "$type" = *LVM2
*volume
* ]]; then
272 local vg
=`pvs --noheadings -o vgname $dev`
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'"
282 local IFS
="$1"; shift
291 local size
=$
(($
(blockdev
--getsz $dev) / 2 / 1024))
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
298 [ $i -gt $si ] && si
=$i
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"
310 # if re-partition: reset size to all
311 [ "$si" = 0 ] && size
=$
(($
(blockdev
--getsz $dev) / 2 / 1024))
312 local swap
=$
((size
/ 20))
315 local fdisk
="sfdisk -W always"
321 # dedicated swap partition or lvm?
323 [[ "$typ" = *lvm
* ]] && _swap
=0 && any
=lvm
328 fs
+=("${dev}2 $any /")
329 fs
+=("${dev}1 ext3 /boot")
333 mkpart 2048s ${boot}m
334 mkpart ${boot}m $((boot + _swap))m")
337 script+=("$mkpart $((boot + _swap))m 100%") fs
+=("${dev}3 swap")
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")
347 script+=("type=swap") fs
+=("${dev}$((si + 3)) swap")
350 fs
+=("${dev}3 $any /")
351 fs
+=("${dev}2 ext3 /boot")
355 size=${boot}m, type=83
356 size=$((size - _swap))m, type=83")
358 script+=("type=82") fs
+=("${dev}4 swap")
362 # TODO: if rootfs too modern, or lvm, we need a /boot part
363 fs
+=("${dev}1 $any /")
365 start=${boot}m, size=$((size - _swap))m, type=83")
367 # the rounding is way off, so - 20m rounding safety :-/
369 script+=("start=$((size - _swap + boot))m, size=$((_swap - boot - 20))m, type=82") &&
372 script+=("9: size=8m, type=0
376 # TODO: typ, luks, lvm, ...
377 fs
+=("${dev}2 $any /")
380 size=$((size - _swap))m, type=83")
383 script+=("type=82") fs
+=("${dev}3 swap")
387 fs
+=("${dev}3 $any /")
391 c 3p $((size - _swap))m linux")
394 script+=("c 4p 4p swap") fs
+=("${dev}4 swap")
402 script+=("label:gpt")
403 script+=("size=2m, type=biosboot")
404 script+=("size=$((size - _swap))m, type=linux")
405 fs
+=("${dev}$((si + 1)) $any /")
408 script+=("type=swap") fs
+=("${dev}$((si + 2)) swap")
411 # TODO: silo vs grub2 have different requirements
412 # TODO: support sun4v-gpt
414 size=$((boot))m, type=83
418 # sfdisk has a "hard" time creating more than 2 parts w/ whole-disk
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}")
428 fs
+=("${dev}$i $any /")
429 fs
+=("${dev}1 ext3 /boot")
432 script+=("label:dos")
435 [[ "$platform" != ppc
*PS3
&& "$platform" != *86*-legacy ]] &&
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")
447 # re-partition or append?
448 if [ "$si" = 0 ]; then
451 dd if=/dev
/zero of
=$dev seek
=1 count
=1 # mostly for Apple PowerPac parts
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
465 for f
in "${fs[@]}"; do
471 # fix device partitions separated w/ p
472 [[ $dev = *[0-9] ]] && d
=${dev}p
${d#$dev}
474 if [[ "$typ" = *luks
* && ("$mnt" = / ||
"$fs" = swap
) ]]; then
476 [ "$fs" = swap
] && name
=swap
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
/vg
0/swap
486 part_mkfs
/dev
/vg
0/root any
/
490 *) part_mkfs
$d $fs $mnt
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."
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
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\""
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\""
534 gui_input
"Rename $dev:" "${dev#*/}" name
536 if [ "$2" = vg
]; then
547 stripes
="--config allocation/raid_stripe_all_devices=1"
549 if [ ! "$size" ]; then
550 #size=$(vgdisplay $dev | grep Free | sed 's,.*/,,; s, <,,; s/ //g ')
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}
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}
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'"
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'"
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" &&
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
615 [ $found = 0 ] && cmd
="$cmd 'Partition table is empty.' ''"
622 cmd
="$cmd 'Logical volumes of $1:' 'vg_action $1'"
625 for x
in $
(lvs
--noheadings -o lv_path
$1 2> /dev
/null
); do
630 # remove from raw device-mapper list
631 x
=$
(readlink
/dev
/$x)
632 volumes
="${volumes/ ${x#/dev/} /}"
634 if [ $found = 0 ]; then
635 cmd
="$cmd 'No logical volumes.' ''"
642 $STONE general set_keymap
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.'"
652 for x
in /sys
/block
/*; do
653 [ ! -e $x/device
-a ! -e $x/dm
] && continue
656 # media? udevadm info -q property --name=/dev/...
657 [[ "$x" = fd
[0-9]* ||
"$x" = sr
[0-9]* ]] && continue
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 "
673 for x
in $
(vgs
--noheadings -o name
2> /dev
/null
); do
678 # any other remaining device-mapper, e.g. LUKS cryptosetup
679 if [ "$volumes" ]; then
680 for x
in $volumes; do
686 if [ $found = 0 ]; then
687 cmd
="$cmd 'No storage found!' ''"
690 cmd
="$cmd 'Install the system ...' 'install_now=1'"
694 if [ "$install_now" = 1 ] && ! grep -q " /mnt" /proc
/mounts
; then
695 gui_yesno
"No storage mounted to /mnt, continue anyway?" ||
700 if [ "$install_now" -ne 0 ]; then
703 mount
-v --bind /dev
/mnt
/dev
704 cat > /mnt
/tmp
/stone_postinst.sh
<< EOT
714 chmod +x
/mnt
/tmp
/stone_postinst.sh
716 # TODO: tr mapper2lvm
717 sed -n '/ \/mnt[/ ]/s,/mnt/\?,/,p' /proc
/mounts |
718 # convert mapper to 1st class lvm names
720 if [[ "$dev" = *mapper
* ]]; then
721 local y
=/dev
/$
(mapper2lvm
${dev#/dev/mapper/})
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?"
734 # try to re-boot via kexec, if available
735 if [ "$kexec" ]; then
736 cmdline
=$
(< /proc
/cmdline
)
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
)
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"
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"
762 echo "You might want to umount all filesystems now and reboot"
763 echo "the system now using the commands:"
765 echo " shutdown -r now"
767 echo "Or by executing 'shutdown -r now' which will run the above commands."