A few things, mostly technical notes...

Tuesday, February 22, 2005

Auto-finding your hard drives for Linux Kickstart



With different hardware, the device names are to change, and thus one will have to edit the ks.cfg for Linux Kickstarts everytime you are dealing with a different hardware.

Starting with RHEL 3.0, you could include a python script in your kickstart file and derive the list of your harddrives into a file. You could later include that file to define your drives.


%pre --interpreter /usr/bin/python
import os, sys
sys.path.append('/usr/lib/anaconda')
import isys

# get a sorted list of drives
drives = isys.hardDriveDict().keys()
drives.sort()

# write the include file to /tmp/kspart, drives[0] is the first drive,
# drives[1] is the second, etc. To get the filet to be used, put
# '%include /tmp/partitions' in your kickstart configuration.
print "Writing partition details"
f = open("/tmp/partitions", "w")
f.write("part /boot --size 400 --ondisk %s\n" % drives[0])
f.write("part / --size 6144 --ondisk %s\n" % drives[0])
f.write("part swap --size 2048 --ondisk %s\n" % drives[0])
f.write("part /var --size 3072 --ondisk %s\n" % drives[0])
f.write("part /home --size 2048 --ondisk %s\n" % drives[0])
f.write("part /tmp --size 4096 --ondisk %s\n" % drives[0])
f.write("part /data --size 6144 --ondisk %s\n" % drives[0])

f.close()



Of course, add this to your kickstart file:
%include /tmp/partitions
Original posting here.


AFAIK, this does not work with RHEL 2.1, as its anaconda is still retarded. Still working on RHEL 4.0 to confirm....

1 comment:

LordMerlin said...

Hey.

This is a nice tutorial, but how to I check how many drives are actually in the system?

Or rather, how do I write an if statement, like {if %drives == 3) then
.......
elseif(%drives == 2)
then
......

Followers


Creative Commons License
This work is licensed under a Creative Commons License.