From 54e1e9a73ad91fd5ba8ec1a3c7429a46c6846e07 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 13 Oct 2016 21:56:40 -0300 Subject: Provision: RAID support --- share/hydractl/provision | 61 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 18 deletions(-) (limited to 'share/hydractl') diff --git a/share/hydractl/provision b/share/hydractl/provision index 04838b7..415c0c0 100755 --- a/share/hydractl/provision +++ b/share/hydractl/provision @@ -93,12 +93,12 @@ function hydra_provision_config { fi hydra_user_config interactive y "Interactive mode? (y/n)" - hydra_user_config device /dev/sdb "Destination device" + hydra_user_config device /dev/sdb "Physical device(s) (more than one auto sets RAID mode)" hydra_user_config swap_size 2000 "Swap size (in MB, 0 to not create it)" hydra_user_config root_size 20G "Size of root partition (-1 for all free space)" hydra_user_config home_size 20G "Size of home partition (0 to not create it, -1 for all free space)" hydra_user_config var_size 20G "Size of var partition (0 to not create it, -1 for all free space)" - hydra_user_config encrypt y "Encrypt volumes? (y/n)" + hydra_user_config encrypt y "Encrypt volumes? (if RAID, then encryption is default) (y/n)" hydra_user_config garbage y "Pre-fill volumes with garbage? (y/n)" hydra_user_config random_swap y "Random swap? (y/n)" hydra_user_config disable_zeroing n "Disable zeroing of LVM volumes? (y/n)" @@ -142,27 +142,52 @@ if [ "$interactive" == "y" ]; then read answer fi -# Disk partitioning. -hydra_sudo_run parted -s -- $device mklabel gpt -hydra_sudo_run parted -s -- $device unit MB mkpart non-fs 2 3 -hydra_sudo_run parted -s -- $device set 1 bios_grub on +# Check number of devices +num_devices="`echo $device | wc -w`" -if [ "$encrypt" == "y" ]; then - hydra_sudo_run parted -s -- $device unit MB mkpart ext2 3 -1 - hydra_sudo_run parted -s -- $device set 2 lvm on +# RAID: do this instead of regular partitioning. +if [ "$num_devices" != "1" ]; then + # Force encryption and fix device name. + encrypt="y" + physical_devices="$device" + device="/dev/md/$hostname" + + for dev in $physical_devices; do + hydra_sudo_run parted -s -- $dev mklabel gpt + hydra_sudo_run parted -s -- $dev mkpart ext4 1M 100% + hydra_sudo_run parted -s -- $dev set 1 raid on + done + + mdadm --create --verbose $device --level=1 --raid-devices=$num_devices $physical_devices + + # See https://bbs.archlinux.org/viewtopic.php?id=148250 + hydra_sudo_run dd if=/dev/zero of=$device bs=1M count=32 - boot_device="$device"2 - syst_device="$device"2 + boot_device="$device" + syst_device="$device" else - hydra_sudo_run parted -s -- $device unit MB mkpart ext2 3 200 - hydra_sudo_run parted -s -- $device unit MB mkpart ext2 200 -1 - hydra_sudo_run parted -s -- $device set 3 lvm on + # Regular disk partitioning. + hydra_sudo_run parted -s -- $device mklabel gpt + hydra_sudo_run parted -s -- $device unit MB mkpart non-fs 2 3 + hydra_sudo_run parted -s -- $device set 1 bios_grub on - boot_device="$device"2 - syst_device="$device"3 + if [ "$encrypt" == "y" ]; then + hydra_sudo_run parted -s -- $device unit MB mkpart ext2 3 -1 + hydra_sudo_run parted -s -- $device set 2 lvm on + + boot_device="$device"2 + syst_device="$device"2 + else + hydra_sudo_run parted -s -- $device unit MB mkpart ext2 3 200 + hydra_sudo_run parted -s -- $device unit MB mkpart ext2 200 -1 + hydra_sudo_run parted -s -- $device set 3 lvm on - # Use absolute path - reboot_device="`blkid | grep ^$boot_device: | cut -d ' ' -f 2 | sed -e 's/"//g'`" + boot_device="$device"2 + syst_device="$device"3 + + # Use absolute path + reboot_device="`blkid | grep ^$boot_device: | cut -d ' ' -f 2 | sed -e 's/"//g'`" + fi fi hydra_sudo_run parted -s -- $device set 2 boot on -- cgit v1.2.3