Re: Disk detection with kickstart

Jason Edgecombe <[email protected]>
Newsgroups gmane.linux.redhat.kickstart.general
Message-ID <[email protected]>
On 10/22/2012 06:20 AM, Moray Henderson wrote:
> From: kk s [mailto:[email protected]]
> Sent: 21 October 2012 22:51
>
>
>
> Hi,
>
>   
>
> I have to provision the servers and all the servers are different disk types
> like hda, sda, xvda. So I have issue to detect the disk type itself with
> kickstart and make partitions. Does anyone have pre installation script that
> will do this job?
>
>   
>
> There was something about this earlier in the year - I can't remember now if
> it was on kickstart-list or anaconda-devel.  Someone was saying that if you
> try to create partitions in %pre anaconda gets confused and can't find them.
> Does anyone else remember that thread?  You always need to write the
> partition instructions to a file and %include them back into your kickstart
> file.  You used to detect hard drives in %pre with list-harddrives although
> things change in anaconda so frequently it is difficult to give precise
> instructions.  With a kickstart file on USB drive for example, you could end
> up with the USB drive wiped and included in the Linux logical volume group
> if you were not careful.  As a first step, create a kickstart that just
> writes the output of list-harddrives to a file and see if it gives you
> anything you can use.
>
>   
>

I have something similar, which checks for sda, sdb, hda, hda, etc. 
Tested on RHEL5

code below:
#-----------------------------------------------cut-----------------------------------------
# main part of kickstart

# include the partitioning logic from the pre section.
%include /tmp/part-include

%pre
# pre section
#----- partitioning logic below--------------
# pick the first drive that is not removable and is over MINSIZE
DIR="/sys/block"

# minimum size of hard drive needed specified in GIGABYTES
MINSIZE=60

ROOTDRIVE=""

# /sys/block/*/size is in 512 byte chunks

for DEV in sda sdb sdc sdd hda hdb; do
   if [ -d $DIR/$DEV ]; then
     REMOVABLE=`cat $DIR/$DEV/removable`
     if (( $REMOVABLE == 0 )); then
       echo $DEV
       SIZE=`cat $DIR/$DEV/size`
       GB=$(($SIZE/2**21))
       if [ $GB -gt $MINSIZE ]; then
         echo "$(($SIZE/2**21))"
         if [ -z $ROOTDRIVE ]; then
           ROOTDRIVE=$DEV
         fi
       fi
     fi
   fi
done

echo "ROOTDRIVE=$ROOTDRIVE"

# drives smaller than 240GB use fixed-size partions
# drives larger than 240GB use percentage-based partition sizes

if [ $GB -lt 240 ]; then

# drives smaller than 240GB
cat << EOF > /tmp/part-include
zerombr
clearpart --all --drives=$ROOTDRIVE --initlabel
#clearpart --all --drives=$ROOTDRIVE
bootloader --location=mbr --driveorder=$ROOTDRIVE
part /boot --fstype ext3 --size=300 --ondisk=$ROOTDRIVE
part pv.8 --size=100 --grow --ondisk=$ROOTDRIVE
volgroup VolGroup00 --pesize=65536 pv.8
logvol / --fstype ext3 --name=root --vgname=VolGroup00 --size=30000
logvol swap --fstype swap --name=swap --vgname=VolGroup00 --size=8000
logvol /tmp --fstype ext3 --name=tmp --vgname=VolGroup00 --size=10000
logvol /var/log --fstype ext3 --name=varlog --vgname=VolGroup00 --size=1000
logvol /usr/vice/cache --fstype ext3 --name=usrvicecache 
--vgname=VolGroup00 --size=17000
EOF

else
# drives 240GB and larger

cat << EOF > /tmp/part-include
zerombr
clearpart --all --drives=$ROOTDRIVE --initlabel
#clearpart --all --drives=$ROOTDRIVE
bootloader --location=mbr --driveorder=$ROOTDRIVE
part /boot --fstype ext3 --size=300 --ondisk=$ROOTDRIVE
part pv.8 --size=100 --grow --ondisk=$ROOTDRIVE
volgroup VolGroup00 --pesize=65536 pv.8
logvol / --fstype ext3 --name=root --vgname=VolGroup00 --percent=12
logvol swap --fstype swap --name=swap --vgname=VolGroup00 --percent=4
logvol /tmp --fstype ext3 --name=tmp --vgname=VolGroup00 --percent=4
logvol /var/log --fstype ext3 --name=varlog --vgname=VolGroup00 --percent=1
logvol /usr/vice/cache --fstype ext3 --name=usrvicecache 
--vgname=VolGroup00 --percent=7
EOF

fi
#-----------------------------------------------cut-----------------------------------------


Jason
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.