Project

General

Profile

Dynamic disk partitioning » History » Version 6

Charles Gomes, 03/15/2013 03:18 PM

1 2 Paul Kelly
h1. Dynamic disk partitioning
2 1 Paul Kelly
3 1 Paul Kelly
h2. Overview
4 1 Paul Kelly
5 5 Corey Osman
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.) 
6 1 Paul Kelly
7 1 Paul Kelly
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. 
8 1 Paul Kelly
9 1 Paul Kelly
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.
10 1 Paul Kelly
11 1 Paul Kelly
h2. Examples
12 1 Paul Kelly
13 4 Ohad Levy
<pre><code class="c">
14 3 Ohad Levy
#Dynamic - this line tells Foreman this is a script rather then a static layout
15 3 Ohad Levy
#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
16 3 Ohad Levy
#or will create a swap partition with your memory size + 2GB.
17 3 Ohad Levy
18 3 Ohad Levy
#get the actual memory installed on the system and divide by 1024 to get it in MB
19 3 Ohad Levy
act_mem=$((`grep MemTotal: /proc/meminfo | sed 's/^MemTotal: *//'|sed 's/ .*//'` / 1024))
20 3 Ohad Levy
21 3 Ohad Levy
#check if the memory is less than 2GB then swap is double the memory else it is memory plus 2 GB
22 3 Ohad Levy
if [ "$act_mem" -gt 2048 ]; then
23 3 Ohad Levy
    vir_mem=$(($act_mem + 2048))
24 3 Ohad Levy
else
25 3 Ohad Levy
    vir_mem=$(($act_mem * 2))
26 3 Ohad Levy
fi
27 3 Ohad Levy
28 3 Ohad Levy
#copy all the HDD partitions to the temp file for execution
29 3 Ohad Levy
cat <<EOF > /tmp/diskpart.cfg
30 3 Ohad Levy
zerombr yes
31 3 Ohad Levy
clearpart --all --initlabel
32 3 Ohad Levy
part swap --size "$vir_mem"
33 3 Ohad Levy
part /boot --fstype ext3 --size 100 --asprimary
34 3 Ohad Levy
part / --fstype ext3 --size 1024 --grow
35 3 Ohad Levy
EOF
36 3 Ohad Levy
</pre>
37 6 Charles Gomes
38 6 Charles Gomes
This next example sets 4GB for real hardware and 0 for virtual machines:
39 6 Charles Gomes
40 6 Charles Gomes
<pre><code class="c">
41 6 Charles Gomes
#Dynamic - this line tells Foreman this is a script rather then a static layout
42 6 Charles Gomes
#This snippets define the swap partition size and if a /boot should be used.
43 6 Charles Gomes
#4GB for real hardware or nothing for VM's
44 6 Charles Gomes
virtual=0
45 6 Charles Gomes
46 6 Charles Gomes
#test if it's KVM or QEMU
47 6 Charles Gomes
dmidecode | egrep -i 'vendor' |grep QEMU && virtual=1
48 6 Charles Gomes
cat /proc/cpuinfo |grep QEMU && virtual=1
49 6 Charles Gomes
dmesg |grep "Booting paravirtualized kernel on KVM" && virtual=1
50 6 Charles Gomes
#test if it's vmware
51 6 Charles Gomes
dmidecode | grep -i 'manufacturer' |grep VMware && virtual=1
52 6 Charles Gomes
53 6 Charles Gomes
if [ "$virtual" -eq 1 ]; then
54 6 Charles Gomes
    part_swap=""
55 6 Charles Gomes
	part_boot=""
56 6 Charles Gomes
else
57 6 Charles Gomes
    part_swap="part swap --size 4096"
58 6 Charles Gomes
	part_boot="part /boot --fstype ext3 --size 100 --asprimary"
59 6 Charles Gomes
fi
60 6 Charles Gomes
61 6 Charles Gomes
#copy all the HDD partitions to the temp file for execution
62 6 Charles Gomes
cat <<EOF > /tmp/diskpart.cfg
63 6 Charles Gomes
zerombr yes
64 6 Charles Gomes
clearpart --all --initlabel
65 6 Charles Gomes
$part_swap
66 6 Charles Gomes
$part_boot
67 6 Charles Gomes
part / --fstype ext3 --size 2048 --grow
68 6 Charles Gomes
EOF
69 6 Charles Gomes
</code>
70 6 Charles Gomes
</pre>