#### begin configuration
-bootn=1
+bootn=3
+rootn=1
swapn=2
-rootn=3
bios_grubn=4
-boot_end=804
+boot_mib=750
lastn=$bios_grubn
if ifclass VM; then
crypt=/dev/mapper/crypt_dev_${d##/dev/}a$rootn
-
-if ifclass frodo; then
- # next upgrade is prolly 16 gigs of memory, across ~8 devices
- swap_end=$((3500 + boot_end))
-else
- # 1.5 x based on https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Installation_Guide/sect-disk-partitioning-setup-x86.html#sect-custom-partitioning-x86
- swap_end=$(( $(grep ^MemTotal: /proc/meminfo| awk '{print $2}') * 3/(${#devs[@]} * 2 ) / 1000 + boot_end ))
-fi
+bios_grub_end=4
+# 1.5 x based on https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Installation_Guide/sect-disk-partitioning-setup-x86.html#sect-custom-partitioning-x86
+swap_mib=$(( $(grep ^MemTotal: /proc/meminfo | \
+ awk '{print $2}') * 3/(${#devs[@]} * 2 ) / 1024 ))
+# parted will round up the disk size. Do -1 so we can have
+# fully 1MiB unit partitions for easy resizing of the last partition.
+# Otherwise we would pass in -0 for the end argument for the last partition.
+disk_mib=$(( $(parted -m ${devs[0]} unit MiB print | \
+ sed -nr "s#^${devs[0]}:([0-9]+).*#\1#p") - 1))
+root_end=$(( disk_mib - swap_mib - boot_mib ))
+swap_end=$(( root_end + swap_mib))
mkdir -p /tmp/fai
shopt -s nullglob
done
for dev in ${devs[@]}; do
parted -s $dev mklabel gpt
- # gpt ubuntu cloud image uses ~4. fai uses 1 MiB. ehh, i'll do 4.
- # also, using MB instead of MiB causes complains about alignment.
+ # gpt ubuntu cloud image uses ~4. fai uses 1 MiB.
+ # I read something in the parted manual saying cheap flash media
+ # likes to start at 4.
+ # MiB because parted complains about alignment otherwise.
pcmd="parted -a optimal -s -- $dev"
- $pcmd mkpart primary "ext3" 4MB ${boot_end}MiB
- $pcmd mkpart primary "linux-swap" ${boot_end}MiB ${swap_end}MiB
- $pcmd mkpart primary "" ${swap_end}MiB -0
+ $pcmd mkpart primary "ext3" 4MiB ${root_end}MiB
+ $pcmd mkpart primary "linux-swap" ${root_end}MiB ${swap_end}MiB
+ $pcmd mkpart primary "" ${swap_end}MiB ${disk_mib}MiB
$pcmd mkpart primary "" 1MiB 4MiB
$pcmd set $bios_grubn bios_grub on
$pcmd set $bootn boot on # generally not needed on modern systems
# the mkfs failed randomly on a vm, so I threw a sleep in here.
sleep .1
-
luks_dev=$dev$rootn
yes YES | cryptsetup luksFormat $luks_dev $luks_dir/host-$HOSTNAME \
-c aes-cbc-essiv:sha256 -s 256 || [[ $? == 141 ]]