Disk configuration / auto detection script
Joseph Glass
jglass at liquidweb.com
Tue Jun 1 14:48:08 UTC 2004
After a couple of requests I decided to post this. Attached is my whole
kickstart file. Below are the sections that automatically configure the
disks.
The drives are configured like so:
100MB /boot on first disk
1GB / on first disk
1GB /tmp on first disk
($drive_size / 15) /usr on first disk
($drive_size / 15) /var on first disk
Recommended swap size on first disk
Anything left on first disk is configured as /home
If there is a second disk, partition the whole thing as /backup
If there is a scsi disk (/dev/sda exists):
- use it as the first drive
- if a second scsi disk exists use it as the second drive (/dev/sdb)
- or if an ide disk exists, use it as the second drive
If there are no scsi disks (/dev/sda is absent):
- use /dev/hda as first drive
- if /dev/hdb exists, use it as the second drive
It is a somwhat static configuration, however this is our standard
configuration for machines and it can be easily changed when needed.
The script can't be 100% flexible without user intervention.
Email me with any questions.
Joe Glass
-------
# I believe %include has to be before the %pre section
# (Somewhat confusing in this context)
%include /tmp/part-include
%pre --interpreter /usr/bin/python
import commands
import os
import string
import sys
import re
script_name = sys.argv[0]
output = commands.getoutput('fdisk -l')
pattern = "sda"
matchobj = re.search(pattern, output)
if matchobj:
scsi = "yes"
else:
scsi = "no"
pattern = "sdb"
matchobj = re.search(pattern, output)
if matchobj:
scsi2 = "yes"
else:
scsi2 = "no"
pattern = "hda"
matchobj = re.search(pattern, output)
if matchobj:
ide = "yes"
else:
ide = "no"
pattern = "hdb"
matchobj = re.search(pattern, output)
if matchobj:
ide2 = "yes"
else:
ide2 = "no"
if scsi == "yes":
drive1 = "sda"
drive1_size = commands.getoutput('fdisk -l').strip()
pattern = "sda: (\d+)"
matchobj = re.search(pattern, drive1_size)
if matchobj:
drive1_size = matchobj.group(1)
if scsi2 == "yes":
drive2 = "sdb"
elif ide == "yes":
drive2 = "hda"
if scsi == "no":
if ide == "yes":
drive1 = "hda"
drive1_size = commands.getoutput('fdisk -l').strip()
pattern = "hda: (\d+)"
matchobj = re.search(pattern, drive1_size)
if matchobj:
drive1_size = matchobj.group(1)
if ide2 == "yes":
drive2 = "hdb"
drive1_size = float(drive1_size)
drive_size_m = int(drive1_size) * 1024
boot_size = 100;
var_size = int(drive_size_m)/15
usr_size = int(drive_size_m)/15
root_size = 1024
tmp_size = 1024
f = open('/tmp/part-include', 'w')
f.write("""# Drive partitioning information determined from %s
clearpart --all --initlabel
part /boot --fstype ext3 --size=%s --ondisk=%s --asprimary
part /var --fstype ext3 --size=%s --ondisk=%s
part /usr --fstype ext3 --size=%s --ondisk=%s --asprimary
part / --fstype ext3 --size=%s --ondisk=%s
part swap --recommended --ondisk=%s --asprimary
part /tmp --fstype ext3 --size=%s --ondisk=%s
part /home --fstype ext3 --size=1 --grow --ondisk=%s
""" %(script_name, boot_size, drive1, var_size, drive1, usr_size,
drive1, root_size, drive1, drive1, tmp_size, drive1, drive1) )
try: drive2
except NameError:
f.write('# no backup selected\n')
else:
f.write('part /backup --fstype ext3 --size=1 --grow --ondisk=%s' %
drive2)
f.close()
On Tue, 2004-06-01 at 09:30, Joseph Glass wrote:
> Hi David,
>
> I run a python script in the %pre section to detect what type/sizes of
> drives the machine has and create partitioning based on the results.
>
> A file with partitioning information is saved in the /tmp directory.
> This file is called from the ks.cfg from %include. If you'd like I can
> send you what I use and you can modify it to your needs.
--
Joseph Glass
Systems Administrator
Liquid Web Inc.
800.580.4985 x227
-------------- next part --------------
# Next two lines must be consecutive
install
nfs --server 192.168.0.1 --dir /home/kickstart/FC1
lang en_US
langsupport --default en_US.UTF-8 en_US.UTF-8
timezone America/Detroit
keyboard us
mouse none
skipx
text
#reboot #reboot after install
network --device eth0 --bootproto dhcp --hostname tempds1-1.liquidweb.com
rootpw --iscrypted [ChangeThisHere}
authconfig --enableshadow --enablemd5
bootloader --location=mbr
# zerombr yes
firewall --disabled
%include /tmp/part-include
%packages --resolvedeps
@ Development Tools
@ Editors
@ Kernel Development
@ System Tools
@ Text-based Internet
-irda-utils
-network-server
-gpm
-gpm-devel
%pre --interpreter /usr/bin/python
import commands
import os
import string
import sys
import re
script_name = sys.argv[0]
output = commands.getoutput('fdisk -l')
pattern = "sda"
matchobj = re.search(pattern, output)
if matchobj:
scsi = "yes"
else:
scsi = "no"
pattern = "sdb"
matchobj = re.search(pattern, output)
if matchobj:
scsi2 = "yes"
else:
scsi2 = "no"
pattern = "hda"
matchobj = re.search(pattern, output)
if matchobj:
ide = "yes"
else:
ide = "no"
pattern = "hdb"
matchobj = re.search(pattern, output)
if matchobj:
ide2 = "yes"
else:
ide2 = "no"
if scsi == "yes":
drive1 = "sda"
drive1_size = commands.getoutput('fdisk -l').strip()
pattern = "sda: (\d+)"
matchobj = re.search(pattern, drive1_size)
if matchobj:
drive1_size = matchobj.group(1)
if scsi2 == "yes":
drive2 = "sdb"
elif ide == "yes":
drive2 = "hda"
if scsi == "no":
if ide == "yes":
drive1 = "hda"
drive1_size = commands.getoutput('fdisk -l').strip()
pattern = "hda: (\d+)"
matchobj = re.search(pattern, drive1_size)
if matchobj:
drive1_size = matchobj.group(1)
if ide2 == "yes":
drive2 = "hdb"
drive1_size = float(drive1_size)
drive_size_m = int(drive1_size) * 1024
boot_size = 100;
var_size = int(drive_size_m)/15
usr_size = int(drive_size_m)/15
root_size = 1024
tmp_size = 1024
f = open('/tmp/part-include', 'w')
f.write("""# Drive partitioning information determined from %s
clearpart --all --initlabel
part /boot --fstype ext3 --size=%s --ondisk=%s --asprimary
part /var --fstype ext3 --size=%s --ondisk=%s
part /usr --fstype ext3 --size=%s --ondisk=%s --asprimary
part / --fstype ext3 --size=%s --ondisk=%s
part swap --recommended --ondisk=%s --asprimary
part /tmp --fstype ext3 --size=%s --ondisk=%s
part /home --fstype ext3 --size=1 --grow --ondisk=%s
""" %(script_name, boot_size, drive1, var_size, drive1, usr_size, drive1, root_size, drive1, drive1, tmp_size, drive1, drive1) )
try: drive2
except NameError:
f.write('# no backup selected\n')
else:
f.write('part /backup --fstype ext3 --size=1 --grow --ondisk=%s' % drive2)
f.close()
%post
cat << EOF > /etc/resolv.conf
domain liquidweb.com
search liquidweb.com
nameserver 198.172.239.5
nameserver 198.172.239.6
EOF
/sbin/chkconfig portmap --level 345 off
/sbin/chkconfig nfslock --level 345 off
/sbin/chkconfig nfs --level 345 off
/sbin/chkconfig isdn --level 345 off
/sbin/chkconfig sendmail --level 345 off
/sbin/chkconfig pcmcia --level 345 off
rm -rf /root/anaconda-ks.cfg
More information about the Kickstart-list
mailing list