Hi David,
I've attached the preliminary version of my script, which will give you
an idea about what I'm trying to do. (by no means is this touted to be
well-written!) I discovered that there's overflow errors with
calculations on disk sizes > 40G or so, but this could be fixed by doing
calculation in Megabytes, as opposed to 1k blocks like I am/was.
Anyways, the problem with this is that by the time this script has been
executed, anaconda has already read in the entire config script, and
hence already has it's partitioning information. My goal is to have the
script use 'sed' to shove in the new partition values, and then have
anaconda re-start itself ( hoping that it won't try and re-fetch the
config script from the server).
anyhow, here's the way things are curently set up for this script: a
directory on the kickstart server has my script, and the expr and sfdisk
binaries (and a link to device node that I make)
[erik@kickstart partition]$ ls -al
total 80
drwxr-xr-x 2 root daemon 4096 Mar 10 17:07 ./
drwxr-xr-x 6 root daemon 4096 Mar 10 00:37 ../
-rwxr-xr-x 1 root daemon 6115 Mar 10 13:44 disk-setup*
-rwxr-xr-x 1 root daemon 12908 Mar 9 19:23 expr*
lrwxrwxrwx 1 root daemon 6 Mar 9 19:56 hda -> ../hda
-rwxr-xr-x 1 root daemon 46780 Mar 9 19:23 sfdisk*
and here's the %pre section from my kickstart config:
%pre
mkdir /tmp/pre-install; mkdir /tmp/pre-install/mnt
cd /tmp/pre-install
# make device node for hda - for use by sfdisk to determine disk size
mknod hda
mount kickstart:/exports/custom/partition /tmp/pre-install/mnt
cd mnt
# Have to add the current dir so that expr and sfdisk will work.
export PATH=$PATH:.
sh ./disk-setup -t server > /tmp/disk-results
I'm spending the next few days getting cozy with python, going to see if
there's a better way!
Enjoy,
Erik.
PS - I hink that the switch that you're looking for is :
--grow
Tells the partition to grow to fill available space (if
any), or up to maximum size setting.
(from the redhat reference guide -
http://www.redhat.com/support/manuals/RHL-7-Manual/ref-guide/s1-kickstart2-commands.html)
David T-G wrote:
Hi, all --
...and then Taylor, ForrestX said...
%
...
% # partitions
% zerombr yes
% #clearpart --all
% clearpart --linux
% part swap --size 512
% part /boot --size 512
% part /home --size 3000
% part /multimedia --size 5000
% part / --size 5000 --grow
I have a somewhat related question... I'd like to specify certain
partitions (root, var, swap) and then have one more that uses whatever is
left. [Actually, I think it would be great to have Erik's script that
parses disk size and decideds based on that, since I come from a Sun
JumpStart environment and find kickstart, cool though it may be, somewhat
limiting.] I have't found the switch for "free" or "freehog" or "the
rest" or whatever. Is there one?
Speaking of which, I now recall a second question. I'd like for my
partition table to lay out as
sda1 - swap
sda2 - root
sda3 - var
sda4 - extended partition containing
sda5 - /drv1 (my "the rest" slice)
but I seem to always end up with swap down in the middle of the disk
somewhere and more extended partitions than I expect. Can I be more
specific in my layout?
TIA (twice) & HAND
:-D
#!/bin/bash
usage() {
echo "Usage:" $0 "-t ['workstation'/'server'] -s <disk size> -u ['M'/'K']"
echo " -t - type of build"
echo " -s - size of disk. If not specified, is fetched from the os."
echo " -u - units. either (M)egabytes or (K)ilobytes."
exit 1
}
echo
# If more than 6 arguments, or less than 2, something's definitely wrong.
if [ $# -gt 6 -o $# -lt 2 ]; then
usage
fi
while getopts s:t:u: opt
do
case $opt in
s) DISK_SIZE=$OPTARG
#let "DISK_SIZE = $OPTARG * 1024"
;;
t) OARG=$OPTARG
case $OARG in
workstation|WORKSTATION)
SCHEME="workstation";;
server|SERVER)
SCHEME="server";;
*) usage;;
esac
;;
u) case $OPTARG in
b|k|B|K)
UNITS="Blocks"
;;
m|M)
UNITS="Mb"
;;
*)usage
;;
esac
;;
*) usage
;;
esac
done
shift `expr $OPTIND - 1`
# Default (minimum) values, assuming a 4G disk.
MIN_DISK_SIZE=4194304 # 4096M * 1024
ROOT_SIZE=524288 # 512M * 1024
MIN_USR=1835008 # 1792M * 1024
MAX_USR=7340032 # 7168M * 1024
MIN_VAR=786432 # 768M * 1024
MIN_TMP=524288 # 512M * 1024
MIN_SWAP=524288 # 512M * 1024
MAX_SWAP=0 # 3x Physical memory
SWAP_LIMIT=2096128 # 2047M * 1024 - Swap partition can't be bigger'n this
# If unspecified, units are 1k-blocks.
if [ -z $UNITS ]; then
UNITS="Blocks"
fi
# If the size wasn't specified, go fetch it.
if [ -z $DISK_SIZE ]; then
if [ -b ./hda ]; then
# system in installation
DISK_SIZE=`sfdisk -s ./hda`
elif [ -b /dev/hda ]; then
# production system
DISK_SIZE=`sfdisk -s /dev/hda`
else
echo "I Couldn't find any info on the first hard disk."
exit 1
fi
else
if [ "$UNITS" = "Mb" ]; then
let "DISK_SIZE = $DISK_SIZE * 1024"
fi
fi
let "DISK_SIZE_M = $DISK_SIZE / 1024"
echo "Total Disk Size : "$DISK_SIZE" 1k blocks ("$DISK_SIZE_M"M)"
# Check to make sure this disk isn't too small.
if [ $DISK_SIZE -lt $MIN_DISK_SIZE ]; then
echo
echo "This utility has been set up to work with disks that are"
echo "a minimum of 4G in size. Sorry."
echo
exit 1
fi
# I've shaved off 50 Megs here to account for cylinder boundaries, etc.
# Assuming that kickstart is similar to the normal installer in that
# It tends to round up partition sizes to make them break on cylinders.
# This will be given back with the '--grow' option.
let "REMAINING_SPACE = $DISK_SIZE - 50000"
# Swap size Calculations - First, find how much memory we've got.
tempArray=(`grep MemTotal /proc/meminfo`)
PHYSICAL_MEM=${tempArray[1]}
# Linux has a swap partition size limit of 2047m. Since there's the
# chance that we'll actually make swap = mem * 3, make sure that doesn't
# break the rule.
let "MAX_SWAP = $PHYSICAL_MEM * 3"
if [ $MAX_SWAP -gt $SWAP_LIMIT ]; then
let "MAX_SWAP = $SWAP_LIMIT"
fi
echo "Total Physical Memory :" $PHYSICAL_MEM"k"
echo
if [ $SCHEME = "workstation" ]; then
echo "Workstation-Type Partitioning Scheme"
else
echo "Server-Type Partitioning Scheme"
fi
# First round. After / is taken care of, the leftover disk is distributed
# As follows:
# /usr - 50%
# <swap> - 14%
# tmp (workstation) - 21% (server) - 15%
# var (workstation) - 15% (server) - 21%
echo "------------------------------------"
echo
echo "First Round, without constraints:"
let "ROOT = ROOT_SIZE"
let "REMAINING_SPACE = $REMAINING_SPACE - $ROOT"
let "USR = (50 * $REMAINING_SPACE) / 100"
let "SWAP = (14 * $REMAINING_SPACE) / 100"
if [ $SCHEME = "workstation" ]; then
let "VAR = (15 * $REMAINING_SPACE) / 100"
let "TMP = (21 * $REMAINING_SPACE) / 100"
else
let "VAR = (21 * $REMAINING_SPACE) / 100"
let "TMP = (15 * $REMAINING_SPACE) / 100"
fi
let "REMAINING_SPACE = $REMAINING_SPACE - $USR"
let "REMAINING_SPACE = $REMAINING_SPACE - $SWAP"
let "REMAINING_SPACE = $REMAINING_SPACE - $VAR"
let "REMAINING_SPACE = $REMAINING_SPACE - $TMP"
echo "ROOT = "`expr $ROOT / 1024`
echo "USR = "`expr $USR / 1024`
echo "SWAP = "`expr $SWAP / 1024`
echo "VAR = "`expr $VAR / 1024`
echo "TMP = "`expr $TMP / 1024`
echo "Remaining Space: "`expr $REMAINING_SPACE / 1024`
echo
echo "Checking Contraints..."
if [ $USR -gt $MAX_USR ]; then
echo "/usr Greater than 7G"
let "SURPLUS = $USR - $MAX_USR"
echo "Adding back " `expr $SURPLUS / 1024` " To the pot"
let "REMAINING_SPACE = $REMAINING_SPACE + $SURPLUS"
let "USR = $MAX_USR"
fi
if [ $SWAP -gt $MAX_SWAP ]; then
echo
echo "<swap> Greater than 3 x PhysicalMem"
let "SURPLUS = $SWAP - $MAX_SWAP"
echo "Adding back " `expr $SURPLUS / 1024` " To the pot"
let "REMAINING_SPACE = $REMAINING_SPACE + $SURPLUS"
let "SWAP = $MAX_SWAP"
fi
echo
echo "the pot now has" `expr $REMAINING_SPACE / 1024`"m in it."
# Second round. The leftover disk is distributed as follows:
# tmp (workstation) - 60% (server) - 40%
# var (workstation) - 40% (server) - 60%
if [ $SCHEME = "workstation" ]; then
let "EXTRA_VAR = (40 * $REMAINING_SPACE) / 100"
let "EXTRA_TMP = (60 * $REMAINING_SPACE) / 100"
else
let "EXTRA_VAR = (60 * $REMAINING_SPACE) / 100"
let "EXTRA_TMP = (40 * $REMAINING_SPACE) / 100"
fi
let "REMAINING_SPACE = $REMAINING_SPACE - $EXTRA_VAR"
let "REMAINING_SPACE = $REMAINING_SPACE - $EXTRA_TMP"
let "VAR = $VAR + $EXTRA_VAR"
let "TMP = $TMP + $EXTRA_TMP"
echo
echo "Here's what I would generate:"
echo "-----------------------------"
#echo "ROOT = "`expr $ROOT / 1024`
#echo "USR = "`expr $USR / 1024`
#echo "SWAP = "`expr $SWAP / 1024`
#echo "VAR = "`expr $VAR / 1024`
#echo "TMP = "`expr $TMP / 1024`
let "ROOT = $ROOT / 1024"
let "USR = $USR / 1024"
let "SWAP = $SWAP / 1024"
let "VAR = $VAR / 1024"
let "TMP = $TMP / 1024"
echo "part / --size = "$ROOT
echo "part swap --size = "$SWAP
echo "part /usr --size = "$USR
if [ $SCHEME = "workstation" ]; then
echo "part /tmp --size = "$TMP "--grow"
echo "part /var --size = "$VAR
else
echo "part /tmp --size = "$TMP
echo "part /var --size = "$VAR "--grow"
fi
echo
echo "Remaining Space: "`expr $REMAINING_SPACE / 1024`