#---------------------------------------------------------------------------- # setup.part - partition hard disk # # Creation : 2001-10-15 fm # Last Update: $Id$ # # Copyright (c) 2001-2020 the eisfair team, team(at)eisfair(dot)org # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------- #---------------------------------------------------------------------------- # prepare partions #---------------------------------------------------------------------------- /busybox rm -f /tmp/gpt # If sfdisk is recognizing a gpt system, write /tmp/gpt. if `sfdisk -l /dev/$disk 2>/dev/null | grep -q ' gpt$'` then >/tmp/gpt fi size=`sfdisk -s /dev/$disk` if [ "$size" = "" ] then echo "Cannot determine size of disk /dev/$disk. Exit." sleep 100000 exit 1 fi if [ -f /tmp/gpt ] then echo "GPT detected." else echo "No GPT detected." fi swapsize=0 bootsize=0 rootsize=0 # 0 means: rest sgdisk_boot='' sgdisk_swap='' sgdisk_root='' sgdisk_data='' if [ $size -ge 256000 ] # bigger than 250 MB then boot=1 bootsize=48 # 48 MB swapsize=64 # 64 MB if [ $size -ge 1024000 ] # 1 GB then bootsize=96 # 96 MB swapsize=128 # 128 MB fi echo -e "Swap size in MB (0=no swap) [$swapsize]: \c" read a if [ "$a" != "" ] then if [ $a = 0 ] then swapsize=0 else sizeMB=`expr $size / 1024` if [ $a -le $sizeMB -a $a -gt 1 ] then swapsize=$a else colecho "Invalid entry '$a', setting Swap size to $swapsize MB ..." br x br fi fi fi else swapsize=0 fi bootsizeKB=`expr ${bootsize} \* 1024` swapsizeKB=`expr ${swapsize} \* 1024` if [ "${_raid_debug}" = "true" ] then echo "setup.part: swapsizeKB ist $swapsizeKB" fi if [ "${_raid_n_disk}" -gt "2" ] then # Gesamtkapazitaet ist (Anzahl der Festplatten - 1) x (Kapazitaet der kleinsten Festplatte) raidfaktor=`expr ${_raid_n_disk} - 1` swapsize_raid5="${swapsize}" # angezeigte groesse (nicht berechnete groesse pro platte) swapsize=`expr ${swapsize} / ${raidfaktor}` # berechnete groesse pro platte swapsizeKB=`expr ${swapsizeKB} / ${raidfaktor}` if [ "${_raid_debug}" = "true" ] then echo "setup.part: raidfaktor ist $raidfaktor" echo "setup.part: rechne durch $raidfaktor" echo "setup.part: swapsize ist nun $swapsize" echo "setup.part: swapsizeKB ist nun $swapsizeKB" fi fi restsize=`expr $size - $bootsizeKB - $swapsizeKB` if [ "${_raid_debug}" = "true" ] then echo "setup.part: restsize ist $restsize" fi if [ $restsize -ge 2097152 ] # groesser/gleich 2GB then ask "Create extra data partition /data" if [ "$a" = "y" ] then data_format=yes # format data partition: yes or no rootsize=1024 # Vorschlag Rootpartition 1GB in MB mindatasizeKB=1048576 # min. Datenpartition 1GB in KB if [ $restsize -ge 4194304 ] # groesser/gleich 4GB then rootsize=2048 # Vorschlag Roootpartition 2GB in MB mindatasizeKB=2097152 # min. Datenpartition 2GB in KB fi if [ $restsize -ge 8388608 ] # groesser/gleich 8GB then rootsize=4096 # Vorschlag Rootpartition 4GB in MB mindatasizeKB=4194304 # min. Datenpartition 4GB in KB fi if [ $restsize -ge 16777216 ] # groesser/gleich 16GB then rootsize=8192 # Vorschlag Rootpartition 8GB in MB mindatasizeKB=8388608 # min. Datenpartition 8GB in KB fi if [ $restsize -ge 33554432 ] # groesser/gleich 32GB then rootsize=16384 # Vorschlag Rootpartition 16GB in MB mindatasizeKB=16777216 # min. Datenpartition 16GB in KB fi if [ "${_raid_n_disk}" -gt "2" ] then mindatasizeKB=`expr ${mindatasizeKB} / ${raidfaktor}` # berechnete groesse pro platte fi maxrootsizeKB=`expr $restsize - $mindatasizeKB` # max. rootsize maxrootsize=`expr $maxrootsizeKB / 1024` if [ "${_raid_debug}" = "true" ] then echo "setup.part: mindatasizeKB ist $mindatasizeKB" echo "setup.part: maxrootsize ist $maxrootsize" fi echo -e "Root size in MB (max. $maxrootsize) [$rootsize]: \c" read a if [ "$a" != "" ] then if [ $a -le $maxrootsize -a $a -gt 1 ] then rootsize=$a else colecho "Invalid entry '$a', setting Root size to $rootsize MB ..." br x br fi fi if [ "${_raid_n_disk}" -gt "2" ] then rootsize_raid5="${rootsize}" # angezeigte groesse (nicht berechnete groesse pro platte) rootsize=`expr ${rootsize} / ${raidfaktor}` # berechnete groesse pro platte fi if [ "${_raid_debug}" = "true" ] then echo "setup.part: rootsize ist $rootsize" fi fi fi echo echo "Following partitions will be created:" echo #---------------------------------------------------------------------------- # prepare boot partition with 48 MB #---------------------------------------------------------------------------- if [ "$boot" != "" ] then boot_idx=1 # e.g. hda1, set 'legacy BIOS bootable' with -A ${boot_idx}:set:2 if [ -n "${_raid_level}" ] then echo " Boot /dev/md$boot_idx $bootsize MB" # boot geht in kompletter groesse auf alle Platten else if [ $cpqscsi_found = true ] then echo " Boot /dev/${disk}p$boot_idx $bootsize MB" else echo " Boot /dev/$disk$boot_idx $bootsize MB" fi fi sgdisk_boot="sgdisk --new=0:0:+${bootsize}M -t ${boot_idx}:8300 -c ${boot_idx}:boot -A ${boot_idx}:set:2 /dev/$disk" else bootsize=0 boot_idx=0 # no extra boot partition fi #---------------------------------------------------------------------------- # prepare swap partition #---------------------------------------------------------------------------- if [ $swapsize -gt 0 ] then swap_idx=`expr $boot_idx + 1` # e.g. hda2 root_idx=`expr $swap_idx + 1` # e.g. hda3 if [ -n "${_raid_level}" ] then if [ "${_raid_n_disk}" -gt "2" ] then echo " Swap /dev/md$swap_idx $swapsize_raid5 MB" # angezeigte groesse (nicht berechnete groesse pro platte) else echo " Swap /dev/md$swap_idx $swapsize MB" # bei spiegelung auf beiden platten identisch fi else if [ $cpqscsi_found = true ] then echo " Swap /dev/${disk}p$swap_idx $swapsize MB" else echo " Swap /dev/$disk$swap_idx $swapsize MB" fi fi sgdisk_swap="sgdisk --new=0:0:+${swapsize}M -t ${swap_idx}:8200 -c ${swap_idx}:swap /dev/$disk" else swap_idx=0 # no swap partition root_idx=`expr $boot_idx + 1` # e.g. hda2 fi #---------------------------------------------------------------------------- # prepare root partition #---------------------------------------------------------------------------- if [ $boot_idx = 0 ] # no boot partition, set 'legacy BIOS bootable' with -A ${root_idx}:set:2 then if [ -n "${_raid_level}" ] then echo " Root /dev/md$root_idx Complete disk" else if [ $cpqscsi_found = true ] then echo " Root /dev/${disk}p$root_idx Complete disk" else echo " Root /dev/$disk$root_idx Complete disk" fi fi sgdisk_root="sgdisk --new=0:0:-10M -t ${root_idx}:8300 -c ${root_idx}:root -A ${root_idx}:set:2 /dev/$disk" else if [ $rootsize -gt 0 ] # not the rest then if [ -n "${_raid_level}" ] then if [ "${_raid_n_disk}" -gt "2" ] then echo " Root /dev/md$root_idx $rootsize_raid5 MB" # angezeigte groesse (nicht berechnete groesse pro platte) else echo " Root /dev/md$root_idx $rootsize MB" # bei spiegelung auf beiden platten identisch fi else if [ $cpqscsi_found = true ] then echo " Root /dev/${disk}p$root_idx $rootsize MB" else echo " Root /dev/$disk$root_idx $rootsize MB" fi fi sgdisk_root="sgdisk --new=0:0:+${rootsize}M -t ${root_idx}:8300 -c ${root_idx}:root /dev/$disk" else if [ -n "${_raid_level}" ] then echo " Root /dev/md$root_idx Rest" else if [ $cpqscsi_found = true ] then echo " Root /dev/${disk}p$root_idx Rest" else echo " Root /dev/$disk$root_idx Rest" fi fi sgdisk_root="sgdisk --new=0:0:-10M -t ${root_idx}:8300 -c ${root_idx}:root /dev/$disk" fi fi #---------------------------------------------------------------------------- # prepare data partition #---------------------------------------------------------------------------- if [ $rootsize -gt 0 ] then data_idx=`expr $root_idx + 1` # 4 oder 3 ohne swap if [ -n "${_raid_level}" ] then echo " Data /dev/md$data_idx Rest" else if [ $cpqscsi_found = true ] then echo " Data /dev/${disk}p$data_idx Rest" else echo " Data /dev/$disk$data_idx Rest" fi fi sgdisk_data="sgdisk --new=0:0:-10M -t ${data_idx}:8300 -c ${data_idx}:data /dev/$disk" else data_idx=0 # no extra data partition fi #---------------------------------------------------------------------------- # create partitions now #---------------------------------------------------------------------------- echo colecho "WARNING: IF YOU ANSWER yes, COMPLETE DATA ON HARDDISK WILL BE ERASED." br x br echo ask "Create partitions as listed above" if [ "$a" != "y" ] then echo "Sorry. Exit." sleep 100000 exit 1 fi echo "Wiping out all partitions on disk /dev/$disk ..." sgdisk -Z /dev/$disk >/dev/null 2>&1 for gpt_action in "$sgdisk_boot" "$sgdisk_swap" "$sgdisk_root" "$sgdisk_data" do if [ -n "$gpt_action" ] then echo "Now running:" colecho "$gpt_action >/dev/null 2>&1" gn $gpt_action >/dev/null 2>&1 if [ $? -ne 0 ] then colecho " Running" rd colecho " ${gpt_action}" br x br colecho " failed!" rd fi fi done #echo #echo "Some buggy BIOSes only boot from GPT when the protective" #echo "MBR is marked as bootable. But other BIOSes normally" #echo "refuse such an bootable protective MBR." #echo #ask "Mark the protective MBR as bootable" #if [ "$a" = "y" ] #then # echo "Extracting fdisk from rootfs.tlz ..." # cd / # tar xpfa /mnt/rootfs.tlz sbin/fdisk usr/sbin/fdisk # echo "a #w" | fdisk -t mbr /dev/$disk >/dev/null 2>&1 # if [ $? -ne 0 ] # then # echo "Failed!" # else # sleep 1 # #echo "Running fdisk -t mbr -l /dev/$disk" # #fdisk -t mbr -l /dev/$disk # fi # # /busybox rm /sbin/fdisk # /busybox rm /usr/sbin/fdisk #fi echo colecho "If you have boot problems try converting GPT to MBR. If" gn colecho "this is your first installation or if you had no problems" gn colecho "booting the system after installing the last time or if" gn colecho "you are unsure what to do, then answer with 'no'." gn ask "Convert GPT partition scheme to MBR" if [ "$a" = "y" ] then if [ $size -gt 2199023252000 ] then echo "Sorry, cannot convert disk /dev/$disk to MBR!" echo "Disk is too big. Disk size = $size bytes." echo "Max size to convert to MBR is 2199023252000." else partnumbers='' for gpt_dev in "$boot_idx" "$swap_idx" "$root_idx" "$data_idx" do if [ "$gpt_dev" -gt "0" ] then if [ -z "$partnumbers" ] then partnumbers="$gpt_dev" else partnumbers="${partnumbers}:$gpt_dev" fi fi done echo "Now running:" colecho "sgdisk -m ${partnumbers} /dev/$disk >/dev/null 2>&1" gn sgdisk -m ${partnumbers} /dev/$disk >/dev/null 2>&1 if [ $? -ne 0 ] then colecho " Running" rd colecho " sgdisk -m $gpt_dev /dev/$disk >/dev/null 2>&1" br x br colecho " failed!" rd fi # make boot or root partition bootable sleep 1 if [ "$boot_idx" -gt "0" ] then echo "Now running:" colecho "sfdisk -q --no-reread --force -A /dev/$disk $boot_idx" gn sfdisk -q --no-reread --force -A /dev/$disk $boot_idx if [ $? -ne 0 ] then colecho " Running" rd colecho " sfdisk -q --no-reread --force -A /dev/$disk $boot_idx" br x br colecho " failed!" rd fi else echo "Now running:" colecho "sfdisk -q --no-reread --force -A /dev/$disk $root_idx" gn sfdisk -q --no-reread --force -A /dev/$disk $boot_idx if [ $? -ne 0 ] then colecho " Running" rd colecho " sfdisk -q --no-reread --force -A /dev/$disk $root_idx" br x br colecho " failed!" rd fi fi sleep 1 #echo "Running sfdisk -A /dev/$disk" #sfdisk -A /dev/$disk # Remove /tmp/gpt. We are using MBR. /busybox rm -f /tmp/gpt fi else # We stay with GPT partitions. The command below will overwrite the # second MBR partition slot and add a bootable partition there of type 0 # (i.e. unused), covering only the first sector of the device. It will # not interfere with the GPT or with the first MBR partition entry which # normally contains a protective MBR partition. printf '\200\0\0\0\0\0\0\0\0\0\0\0\001\0\0\0' | dd of=/dev/${disk} bs=1 seek=462 2>/dev/null # Write /tmp/gpt, we are using GPT. >/tmp/gpt fi #---------------------------------------------------------------------------- # adjust md devices #---------------------------------------------------------------------------- boot_mdx="$boot_idx" root_mdx="$root_idx" swap_mdx="$swap_idx" data_mdx="$data_idx" #---------------------------------------------------------------------------- # adjust cpqscsi devices #---------------------------------------------------------------------------- if [ "$cpqscsi_found" = "true" ] then if [ ! -f /tmp/gpt ] then dd if=/dev/zero of=/dev/${disk}p1 bs=512 count=1 2>/dev/null fi if [ "$boot_idx" != "0" ] then boot_idx=p$boot_idx fi if [ "$root_idx" != "0" ] then root_idx=p$root_idx fi if [ "$swap_idx" != "0" ] then swap_idx=p$swap_idx fi if [ "$data_idx" != "0" ] then data_idx=p$data_idx fi else if [ ! -f /tmp/gpt ] then dd if=/dev/zero of=/dev/${disk}1 bs=512 count=1 2>/dev/null fi fi