Project

General

Profile

Dynamic disk partitioning » History » Version 7

« Previous - Version 7/11 (diff) - Next » - Current version
Charles Gomes, 03/15/2013 03:20 PM


Dynamic disk partitioning

Overview

When configuring a host for an unattended kickstart build. It is possible to specify the host's disk layout as an explicit sequence of partions or use a pre-exec dynamic disk layout script. In either case enter the explict partition list or the pre-exec script into the host's disk layout text area, (or choose a predefined configuration.)

If the text is to be interpreted as a dynamic disk layout then please ensure that the pre-exec shell script contains a comment line starting with "#Dynamic" and that your script writes a static partition table into /tmp/diskpart.cfg.

If a disk partition table contains /^#Dynamic/ then the kickstart process will execute the text as a bourne shell script as its very first step and will then include the file /tmp/diskpart.cfg into the downloaded kickstart file.

Examples

#Dynamic - this line tells Foreman this is a script rather then a static layout
#This snippets define the swap partition size, it would generate a partition twice the size of the memory if your physical memory is up to 2GB
#or will create a swap partition with your memory size + 2GB.

#get the actual memory installed on the system and divide by 1024 to get it in MB
act_mem=$((`grep MemTotal: /proc/meminfo | sed 's/^MemTotal: *//'|sed 's/ .*//'` / 1024))

#check if the memory is less than 2GB then swap is double the memory else it is memory plus 2 GB
if [ "$act_mem" -gt 2048 ]; then
    vir_mem=$(($act_mem + 2048))
else
    vir_mem=$(($act_mem * 2))
fi

#copy all the HDD partitions to the temp file for execution
cat <<EOF > /tmp/diskpart.cfg
zerombr yes
clearpart --all --initlabel
part swap --size "$vir_mem" 
part /boot --fstype ext3 --size 100 --asprimary
part / --fstype ext3 --size 1024 --grow
EOF

This next example sets 4GB for real hardware and 0 for virtual machines:

#Dynamic - this line tells Foreman this is a script rather then a static layout
#This snippets define the swap partition size and if a /boot should be used.
#4GB for real hardware or nothing for VM's
virtual=0

#test if it's KVM or QEMU
dmidecode | egrep -i 'vendor' |grep QEMU && virtual=1
cat /proc/cpuinfo |grep QEMU && virtual=1
dmesg |grep "Booting paravirtualized kernel on KVM" && virtual=1
#test if it's vmware
dmidecode | grep -i 'manufacturer' |grep VMware && virtual=1

if [ "$virtual" -eq 1 ]; then
    part_swap="" 
    part_boot="" 
else
    part_swap="part swap --size 4096" 
    part_boot="part /boot --fstype ext3 --size 100 --asprimary" 
fi

#copy all the HDD partitions to the temp file for execution
cat <<EOF > /tmp/diskpart.cfg
zerombr yes
clearpart --all --initlabel
$part_swap
$part_boot
part / --fstype ext3 --size 2048 --grow
EOF