[TriLUG] RHEL kickstart LV/PV syntax question

Marc Wiatrowski mwia at iglass.net
Tue Apr 28 09:38:29 EDT 2009


Not sure on the VM stuff, but this may give you at least some ideas.
Excuse my python, this
is the one and only python script I've written.  There is no perl at %
pre !

Our setup PXE boots and grabs the kickstart config from a cgi script.
The disk setup is an %include
from /tmp.  This include config is created in the %pre section from
another script that basically checks
to see how many disks there are and then creates the logical volume
setup and dumps it to /tmp for
the include.  

-marc

Relevant ks.cfg:

%include /tmp/diskpart.cfg

...

%pre
wget -q -O - http://10.1.1.1/KickStart/cfg/diskpart.py | python
> /tmp/diskpart.cfg


diskpart.py:

#!/usr/bin/python

import re
import os

dev     = re.compile('^Host:\s+scsi0*(\d+)\s+Channel:\s+0*(\d+)\s+Id:\s
+0*(\d+)\s+Lun:\s+0*(\d+)')
type    = re.compile('^\s+Type:\s+Direct-Access')
block   = re.compile('^block:(\S+)')
hdreg   = re.compile('^(hd\w+)$')
diskreg = re.compile('^disk$')

hddevices = []
sddevices = []

try:
   SCSI=open("/proc/scsi/scsi", "r")

   for line in SCSI:
      if dev.match(line):
        s = dev.match(line).group(1)
        c = dev.match(line).group(2)
        i = dev.match(line).group(3)
        l = dev.match(line).group(4)
      if type.match(line):
         sddir = "/sys/bus/scsi/drivers/sd/%s:%s:%s:%s" % (s, c, i, l)
         for file in os.listdir(sddir):
            if block.match(file):
               sddevices = sddevices + [ block.match(file).group(1) ]
   if len(sddevices) > 1:
      sddevices.sort()

   SCSI.close()
except:
   pass

try:
   for file in os.listdir("/proc/ide"):
      if hdreg.match(file):
         HD = open("/proc/ide/%s/media" % (file) )
         media = HD.readline();
         if diskreg.match(media):
            hddevices = hddevices + [ hdreg.match(file).group(1) ]
   if len(hddevices) > 1:
      hddevices.sort()
except:
   pass

devices = sddevices + hddevices

if len(devices) > 0:
   print "# Found disks %s" % (devices)
   print ""
   print "clearpart --all";
   print "";
   print "part /boot --fstype ext3 --size=100 --ondisk=%s" %
(devices[0])
   print "part swap --size=512 --ondisk=%s" % (devices[0])
   print "part pv.11 --size=1 --grow --ondisk=%s" % (devices[0])
   if len(devices) > 1:
      print "part pv.21 --size=1 --grow --ondisk=%s" % (devices[1])
   print ""
   print "volgroup vga pv.11"
   if len(devices) > 1:
      print "volgroup vgb pv.21"
   print "";
   print "logvol swap --fstype swap --name=swapVol01 --vgname=vga
--size=4096"
   if len(devices) > 1:
      print "logvol swap --fstype swap --name=swapVol02 --vgname=vgb
--size=4096"
   print "logvol / --fstype ext3 --name=rootVol  --vgname=vga --size=1
--grow";
   if len(devices) > 1:
      print "logvol /export --fstype ext3 --name=localVol --vgname=vgb
--size=1 --grow"
      # print "logvol /usr/local --fstype ext3 --name=localVol
--vgname=vgb --size=1 --grow"
   print "";

else:
   print "# No disks found"




On Mon, 2009-04-27 at 19:05 -0400, Kevin Flanagan wrote: 

> All,
> 
> 
>    I'm working on automating installations of RHEL 5.2, and soon 5.3.  I'm
> currently doing Virtual Machines, but soon enough will be doing hardware
> servers, on HP Proliant X86 servers, as well.  I have had limited success
> with LVM config syntax, I've found so much info scattered about the net, and
> a lot of it contradictory, that I thought that I'd ask the good folks here.
> I think that the standard docs are decent, but not very helpful with some of
> the more of the conceptual stuff.  We do expect to build at least another
> hundred RHEL systems in the next several months, perhaps a lot more if we
> decide to do rebuilds of the older stuff.
> 
> 
> Here's what I'm looking to have a good solid handle on.
> 
> - Kickstart syntax for
>    - Physical and Logical Volume creation
>    - Disk controller differences
>       SD devices in VMs
>       CCISS devices on hardware
> 
> 
> - A way to sniff out hardware differences if it exists
> - A way to do some token substitution based on declarations in the first few
> lines, or if statements if that exists
> 
> 
> 
> I'm really looking to have a single unified process that starts with
> hardware builds to establish a new rev of the corporate build, then use that
> to build in a VM to make a VMWare template.  I'm open to the opposite
> direction if folks experience says that it's better/easier.
> 
> 
> 
> Of course, pointers to resources that you folks have found to be good in
> actual practice are always welcome.
> 
> 
> 
> Thanks in advance,
> 
> 
> 
>   Kevin
> --
> TriLUG mailing list        : http://www.trilug.org/mailman/listinfo/trilug
> TriLUG FAQ  : http://www.trilug.org/wiki/Frequently_Asked_Questions



More information about the TriLUG mailing list