fuel-library/deployment/puppet/cobbler/templates/snippets/pre_install_partition_lvm.erb

239 lines
12 KiB
Plaintext

echo > /tmp/partition.ks
#import json
#if $getVar("ks_spaces","{}") != "{}"
#######################################
## Initializing variables
#######################################
#set $j = $getVar("ks_spaces","[]")
#set $spaces = $json.loads($j)
#set $clearpart_drives = []
#set $physical_volumes = []
#set $grub_drives = []
#set $custom_grub_drives = []
#set $partitions = []
#set $volume_groups = {}
#set $raid_volumes = {}
#set $logical_volumes = []
#set $post_logical_volumes = []
#set $parted_commands = []
#set $pvnum = 0
#set $raidnum = 0
#set $mdnum = 0
#for $space in $spaces
#set $space_id = $space.get("id")
#set $space_type = $space.get("type")
#set $space_volumes = $space.get("volumes")
#######################################
## Cleaning drives
#######################################
#if $space_type == "disk"
$clearpart_drives.append($space_id)
#end if
#######################################
## Labeling gpt
#######################################
#if $space_type == "disk"
$parted_commands.append("parted -s /dev/%s mklabel gpt" % $space_id)
#end if
#######################################
## Configuring space volumes
#######################################
#for $volume in $space_volumes
#set $volume_id = $volume.get("id")
#set $volume_type = $volume.get("type")
#######################################
## Configuring not boot partitions
#######################################
#if $space_type == "disk" and $volume_type == "boot"
## Create and mark Bios Boot partition to which grub will
## embed its code later, useable for legacy boot.
## May be way smaller, but be aware that the parted may
## shrink 1M partition to zero at some disks and versions.
## The following two lines are for future.
## $parted_commands.append("parted -a minimal -s /dev/%s unit MB mkpart primary 0 24M" % $space_id)
## $parted_commands.append("parted -s /dev/%s set 1 bios_grub on" % $space_id)
## Create partition for the EFI boot, minimum size is 100M,
## recommended is 200M, with fat32 and future mountpoint in
## the /boot/efi
## There is also '/usr/sbin/parted -s /dev/sda set 2 boot on'
## which is strictly needed for EFI boot itself.
## The following two lines are for future.
## $parted_commands.append("parted -a minimal -s /dev/%s unit MB mkpart primary fat32 24M 300M" % $space_id)
## $parted_commands.append("parted -s /dev/%s set 2 boot on" % $space_id)
#######################################
## Installing bootloader
#######################################
$grub_drives.append("\$(basename `readlink -f /dev/%s`)" % $space_id)
$custom_grub_drives.append("`readlink -f /dev/%s`" % $space_id)
#end if
#######################################
## Configuring plain partitions
#######################################
#if $space_type == "disk" and $volume_type == "partition"
#set $volume_mount = $volume.get("mount")
#set $volume_size = $int($volume.get("size") or 0)
#if $volume_size > 0
$partitions.append("partition %s --size=%s --ondisk=%s" % ($volume_mount, $volume_size, $space_id))
#end if
#end if
#######################################
## Configuring raid partitions
#######################################
#if $space_type == "disk" and $volume_type == "raid"
#set $volume_mount = $volume.get("mount")
#set $volume_size = $int($volume.get("size") or 0)
#set $volume_name = "raid.%03d" % $raidnum
#if $volume_size > 0
#if not $raid_volumes.get($volume_mount)
#set $raid_volumes[$volume_mount] = [{'size': $volume_size, 'name': $volume_name, 'ondisk': $space_id}]
#else
$raid_volumes[$volume_mount].append({'size': $volume_size, 'name': $volume_name, 'ondisk': $space_id})
#end if
#set $raidnum += 1
#end if
#end if
#######################################
## Configuring physical volumes
#######################################
#if $space_type == "disk" and $volume_type == "pv"
#set $volume_vg = $volume.get("vg")
#set $volume_size = $int($volume.get("size") or 0)
#set $volume_name = "pv.%03d" % $pvnum
#if $volume_size > 0
$physical_volumes.append("partition %s --size=%s --ondisk=%s" % ($volume_name, $volume_size, $space_id))
#if not $volume_groups.get($volume_vg)
#set $volume_groups[$volume_vg] = [$volume_name]
#else
$volume_groups[$volume_vg].append($volume_name)
#end if
#set $pvnum += 1
#end if
#end if
#######################################
## Configuring logical volumes
#######################################
#if $space_type == "vg" and $volume_type == "lv"
#set $volume_mount = $volume.get("mount")
## getting volume size in MB
#set $volume_size = $int($volume.get("size") or 0)
#set $volume_name = $volume.get("name")
##
## Anaconda has hard coded limitation of 16TB for ext3/4 and xfs filesystems (the only filesystems we are supposed to use).
## Besides there is no stable 64-bit ext4 implementation at the moment, so the limitation of 16TB is not only anaconda limitation.
## Root partition can not be located on xfs filesystem therefore we check if root filesystem is larger
## than 16TB and set it size into 16TB if it is. It is necessary to note that to format 16TB volume on ext4 it is needed about 1G memory.
#if $volume_size > 16777216 and $volume_mount == "/"
#set $volume_size = 16777216
#end if
## volume_size is less than or equal to 16TB
#if $volume_size > 0 and $volume_size <= 16777216
$logical_volumes.append("logvol %s --vgname=%s --size=%s --name=%s" % ($volume_mount, $space_id, $volume_size, $volume_name))
## volume_size is more than 16TB, use xfs file system
#else
$post_logical_volumes.append("lvcreate --size %s --name %s %s" % ($volume_size, $volume_name, $space_id))
$post_logical_volumes.append("mkfs.xfs /dev/mapper/%s-%s" % ($space_id, $volume_name))
$post_logical_volumes.append("mkdir -p /mnt/sysimage%s" % $volume_mount)
$post_logical_volumes.append("echo '/dev/mapper/%s-%s %s xfs defaults 0 0' >> /mnt/sysimage/etc/fstab" % ($space_id, $volume_name, $volume_mount))
#end if
#end if
#######################################
#end for
#end for
##
##
#######################################
## Actual cleaning drives
#######################################
#for $d in $clearpart_drives
test -e $d && dd if=/dev/zero of=/dev/$d bs=1M count=10
#end for
#######################################
## Actual configuring boot partitions
#######################################
#for $parted in $parted_commands
$parted
#end for
#######################################
## Actual creating plain partitions
#######################################
#for $partition in $partitions
echo "$partition" >> /tmp/partition.ks
#end for
#######################################
## Actual creating raid volumes
#######################################
#for $raid_mount in $raid_volumes.keys()
#if $len($raid_volumes[$raid_mount]) < 2
#set $size = $raid_volumes[$raid_mount][0]['size']
#set $ondisk = $raid_volumes[$raid_mount][0]['ondisk']
echo "partition $raid_mount --size=$size --ondisk=$ondisk" >> /tmp/partition.ks
#continue
#else
#set $ks_raids = ""
#for $p in $raid_volumes[$raid_mount]
echo "partition $p['name'] --size=$p['size'] --ondisk=$p['ondisk']" >> /tmp/partition.ks
#set $ks_raids = "%s %s" % ($ks_raids, $p['name'])
#end for
#set $num_spares = $len($raid_volumes[$raid_mount]) - 2
#set $md_name = "md%d" % $mdnum
## #if $num_spares > 0
##echo "raid $raid_mount --device $md_name --spares=$num_spares --fstype ext2 --level=RAID1 $ks_raids" >> /tmp/partition.ks
## #else
echo "raid $raid_mount --device $md_name --fstype ext2 --level=RAID1 $ks_raids" >> /tmp/partition.ks
## #end if
#end if
#set $mdnum += 1
#end for
#######################################
## Actual creating physical volumes
#######################################
#for $pv in $physical_volumes
echo "$pv" >> /tmp/partition.ks
#end for
#######################################
## Actual creating volume groups
#######################################
#for $volgroup in $volume_groups.keys()
#set $ks_pvs = " ".join($volume_groups.get($volgroup))
echo "volgroup $volgroup $ks_pvs" >> /tmp/partition.ks
#end for
#######################################
## Actual creating logical volumes
#######################################
#for $lv in $logical_volumes
echo "$lv" >> /tmp/partition.ks
#end for
#######################################
## Actual creating logical volumes in %post section
#######################################
echo "%post --nochroot" > /tmp/post_partition.ks
echo "set -x -v" >> /tmp/post_partition.ks
echo "exec 1>/mnt/sysimage/root/post_partition.log 2>&1" >> /tmp/post_partition.ks
#for $lv in $post_logical_volumes
echo "$lv" >> /tmp/post_partition.ks
#end for
#######################################
## Actual bootloader installing
#######################################
#set $drives = ",".join($grub_drives)
echo "bootloader --location=mbr --driveorder=$drives --append=' biosdevname=0 crashkernel=none'" > /tmp/bootloader.ks
##
#######################################
## Actual custom bootloader installing
#######################################
#set $num = 0
#for $drive in $custom_grub_drives
echo "stage2_devnum=\\$((\\$(fdisk -l $drive | grep -E '^\/.+\*' | awk '{print \\$1}' | sed s/[^0-9]//g) - 1))" >> /tmp/post_partition.ks
echo "chroot /mnt/sysimage /bin/cp /boot/grub/grub.conf /boot/grub/grub${num}.conf" >> /tmp/post_partition.ks
echo "chroot /mnt/sysimage /bin/sed -i -re \"s/\(hd[0-9]+\,[0-9]+\)/\(hd0\,\\${stage2_devnum}\)/g\" /boot/grub/grub${num}.conf" >> /tmp/post_partition.ks
echo "echo -n > /tmp/grub.script" >> /tmp/post_partition.ks
echo "echo \"device (hd0) $drive\" >> /tmp/grub.script" >> /tmp/post_partition.ks
echo "echo \"root (hd0,\\${stage2_devnum})\" >> /tmp/grub.script" >> /tmp/post_partition.ks
echo "echo \"install /grub/stage1 (hd0) /grub/stage2 p /grub/grub${num}.conf\" >> /tmp/grub.script" >> /tmp/post_partition.ks
echo "echo quit >> /tmp/grub.script" >> /tmp/post_partition.ks
echo "cat /tmp/grub.script | chroot /mnt/sysimage /sbin/grub --batch" >> /tmp/post_partition.ks
#set $num += 1
#end for
echo "cp /tmp/post_partition.ks /mnt/sysimage/root/post_partition.ks" >> /tmp/post_partition.ks
#end if