On 01/13/2016 02:42 PM, Graham Allan wrote:
On 01/13/2016 01:30 PM, Konstantin Olchanski wrote:

and the same "you *must* use the disk partition tool designed by
dummies for dummies".

likewise solved by kickstart.


The kickstart disk partitioning tool is even dumber than they new GUI tool, only useful for "one-size-fits-all" cases where you also do not mind accidentally deleting the contents of all disks. (yes, open the machine, disconnect disks,
install, reconnect disks, close the machine, thanks, but no thanks).

Using %pre in the kickstart file is the way to fix this, but you do need
to do all the work yourself. I suppose I could share our %pre section which examines disks and decides which to install on (it waits for confirmation if it can't determine the drive itself). The logic is simply to look for the first drive which either has no partition table or has a /boot directory (ie reinstall). No claims that this is perfect in any way, we hacked it together over the years and it works for us (with SL6).

For the post-config stuff we use %post to set our configuration management system (cfengine) to run after reboot.

##################
# Figure out where to install to

# make sure USB storage devices are GONE
modprobe -r usb_storage

mkdir /mnt/tmp

for i in `ls /dev/sd?`; do
    CANDIDATE_DISK="$i"

echo "Checking $CANDIDATE_DISK for partition table" | tee -a /tmp/ks.log >> /dev/tty3

    if parted -s "$CANDIDATE_DISK" print >/dev/null; then
echo "parted found a partition table" | tee -a /tmp/ks.log >> /dev/tty3
        if mount "${CANDIDATE_DISK}1" /mnt/tmp; then
            if [ -d /mnt/tmp/boot ]; then
                INSTALL_DISK=$CANDIDATE_DISK
echo "Found /boot on ${CANDIDATE_DISK}1, using $CANDIDATE_DISK as system disk" | tee -a /tmp/ks.log >> /dev/tty3
                umount /mnt/tmp
                break
            else
echo "Couldn't find /boot on ${CANDIDATE_DISK}1, moving on to next disk..." | tee -a /tmp/ks.log >> /dev/tty3
                umount /mnt/tmp
            fi
        else
echo "Failed to mount ${CANDIDATE_DISK}1, moving on to next disk..." | tee -a /tmp/ks.log >> /dev/tty3
        fi
    else
echo "parted found no partition table, using $CANDIDATE_DISK as system disk" | tee -a /tmp/ks.log >> /dev/tty3
        INSTALL_DISK="$CANDIDATE_DISK"
        break
    fi
done

if [ "${INSTALL_DISK}x" = "x" ]; then
echo "****************************************************" >> /dev/tty1 echo "Initial check failed to find a suitable system disk!" >> /dev/tty1 echo "****************************************************" >> /dev/tty1
    for i in `ls /dev/sd?`; do
        CANDIDATE_DISK="$i"
        if mount "${CANDIDATE_DISK}1" /mnt/tmp; then
            if ! [ -d /mnt/tmp/boot ]; then
echo -e "\n\nCouldn't find /boot on ${CANDIDATE_DISK}1" >> /dev/tty1 echo -n "Partition table for ${CANDIDATE_DISK}:" >> /dev/tty1
                fdisk -l ${CANDIDATE_DISK} >> /dev/tty1
                doit="default"
while ! echo "$doit" | grep -P "([Y|y]es|[N|n]o)" > /dev/null 2>&1; do echo -n "Install linux on ${CANDIDATE_DISK}? [Yes/No] " >> /dev/tty1
                    read doit
                done
if echo "$doit" | grep -P "[Y|y]es" > /dev/null 2>&1; then
                    INSTALL_DISK="$CANDIDATE_DISK"
                    umount /mnt/tmp
                    break
                else
                    echo "moving on to next disk..." >> /dev/tty1
                fi
                umount /mnt/tmp
            fi
        else
echo -ne "\n\nPartition table for ${CANDIDATE_DISK}:" >> /dev/tty1
            fdisk -l ${CANDIDATE_DISK} >> /dev/tty1
            doit="default"
while ! echo "$doit" | grep -P "([Y|y]es|[N|n]o)" > /dev/null 2>&1; do echo -n "Install linux on ${CANDIDATE_DISK}? [Yes/No] " >> /dev/tty1
                read doit
            done
            if echo "$doit" | grep -P "[Y|y]es" > /dev/null 2>&1; then
                INSTALL_DISK="$CANDIDATE_DISK"
                break
            else
                echo "moving on to next disk..." >> /dev/tty1
            fi
        fi
    done

    if [ "${INSTALL_DISK}x" = "x" ]; then
echo -e "\n****************************************************" >> /dev/tty1
        echo "Failed to find a suitable system disk" >> /dev/tty1
echo "The system will be rebooted when you press Ctrl-C or Ctrl-Alt-Delete." >> /dev/tty1 echo "****************************************************" >> /dev/tty1
        while true; do
            sleep 1
        done
>     fi
> fi

echo "Installing linux to $INSTALL_DISK" | tee -a /tmp/ks.log >> /dev/tty3
echo "Installing linux to $INSTALL_DISK" >> /dev/tty1
echo "****************************************************" >> /dev/tty1
# Done figuring out where to install
###################


#Write a file out to be included below for disk config
cat << EOF > /tmp/partitions
clearpart --drives=$INSTALL_DISK --initlabel --all
zerombr yes
part swap --recommended --ondisk=$INSTALL_DISK
part /    --size=25600 --ondisk=$INSTALL_DISK
part /var --size=4096   --ondisk=$INSTALL_DISK
part /export/scratch --size=128 --grow --ondisk=$INSTALL_DISK
EOF


Graham
Good idea! Here's ours. Our constraints (swap, disk sizes, etc.) may of course be completely different for someone else's setups. We use this across everything from desktops to servers, with slightly different layouts for each. This has evolved as we moved from 5 to 6 (we are now on 6.5).

### Disk partitioning is handled in a pre script.
%include /tmp/disk-parts

%pre
### Determine physical RAM; we hope to have that much swap.
### Need to use /proc/meminfo since free was removed from install.img
SYSTYPE='DESKTOP'
MEM=$(grep ^MemTotal /proc/meminfo | awk '{print $2}')
GB=$(($MEM / 1000000))
if [ $GB -lt 24 ] ; then
        GB=24
fi
MSIZE=$(($GB * 1024))

### Determine the style of disk labels used. Based on that,
### determine the number and size of the physical disks. For now
### assume no more than two disks
grep 'cciss/c[0-9]d[0-9]' /proc/partitions > /dev/null 2>&1
if [ $? == 0 ] ; then
DISKS=(`grep 'cciss/c[0-9]d[0-9]$' /proc/partitions | awk '{print $3 " " $4}'`)
else
DISKS=(`grep '[shv]d[a-z]$' /proc/partitions | awk '{print $3 " " $4}'`)
fi
NDISKS=$((${#DISKS[@]} / 2))
SIZE=${DISKS[0]}
D1SIZE=$((SIZE / 1024))
D1NAME=${DISKS[1]}
### First disk is always system disk.
SYSDISK=$D1NAME
if [ $NDISKS -gt 1 ] ; then
        SIZE=${DISKS[2]}
        D2SIZE=$((SIZE / 1024))
        ### Allow for X4170 tiny second disk.
        if [ $D2SIZE -lt 10240 ] ; then
                NDISKS=1
        else
                D2NAME=${DISKS[3]}
        fi
fi

### Default sizes for all non-swap partitions
SLASH=4096
USR=20480
VAR=10240
TMP=10240
EXPORT=10240
if [ $SYSTYPE == 'SERVER' ] ; then
        BIGPART='/tmp'
        SMALLPART='/export'
else
        BIGPART='/export'
        SMALLPART='/tmp'
fi

### If one disk, make sure swap doesn't consume too much of it.
### If two disks, give second disk to swap and assume disks are equal in size.
### /var only grows to consume its disk if we have two disks.
MAXSWAP=$(($D1SIZE - $SLASH - $USR - $VAR - $TMP - $EXPORT - 100))
#--echo DSIZE = $D1SIZE MAXSWAP = $MAXSWAP MSIZE = $MSIZE
if [ $NDISKS == 1 ] ; then
        if [ $MSIZE -gt $MAXSWAP ] ; then
                MSIZE=$MAXSWAP          ### swap has to fit on the disk.
        fi
        SWAPDISK=$D1NAME
        GROWVAR=""
        TMPDISK=$D1NAME
else
        ### If swap would overflow disk 1, put it on disk 2.
        ### Don't use more than half of disk 2.
        if [ $MSIZE -gt  $MAXSWAP ] ; then
                SWAPDISK=$D2NAME
                if [ $MSIZE -gt $(($D2SIZE / 2)) ] ; then
                        MSIZE=$(($D2SIZE / 2))
                else
                        MSIZE=$D2SIZE
                fi
        else
                SWAPDISK=$D1NAME
        fi
        GROWVAR="--grow"
        TMPDISK=$D2NAME
fi

### Finally, swap can't exceed 64GB on EL6
if (( $MSIZE > 64000 )); then MSIZE=64000; fi

### Output the partition tables
cat > /tmp/disk-parts <<__EOD__
part / --bytes-per-inode=4096 --fstype="ext4" --size=$SLASH --ondisk $SYSDISK
part swap --bytes-per-inode=4096 --size=$MSIZE --ondisk $SWAPDISK
part /usr --bytes-per-inode=4096 --fstype="ext4" --size=$USR --ondisk $SYSDISK part /var --bytes-per-inode=4096 --fstype="ext4" --size=$VAR --ondisk $SYSDISK $GROWVAR part $BIGPART --bytes-per-inode=4096 --fstype="ext4" --size=$TMP --ondisk $TMPDISK --grow part $SMALLPART --bytes-per-inode=4096 --fstype="ext4" --size=$EXPORT --ondisk $SYSDISK
__EOD__


--
Miles O'Neal
CAD Systems Engineer
Cirrus Logic | cirrus.com | 1.512.851.4659

Reply via email to