void-bash-installer/step2/10-disk
2021-08-18 10:23:53 +02:00

169 lines
4.4 KiB
Plaintext

if ! yesno "nun gehts los, sicher?" y; then
exit
fi
module start "disk" "Partition disk"
sleep=4
diskid="${cfg[diskid]//-/_}"
dodiskid="/dev/disk/by-id/${cfg[diskid]}"
index=1
echo "Formatting disk"
if test -d /sys/firmware/efi; then
echo "UEFI Partition"
(echo "g";
echo "n";
echo "1";
echo "";
echo "+1G";
echo "t";
echo "1";
sleep $sleep;
echo "w";
echo "q") | fdisk "${dodiskid}" > /dev/null
sync
efipart="${dodiskid}-part${index}"
index=$(( index + 1 ))
mkfs.vfat "${efipart}"
else
echo "BIOS Partition"
(echo "o";
sleep $sleep;
echo "w";
echo "q") | fdisk -w always -W always "${dodiskid}" > /dev/null
fi
sleep $sleep
sync
echo "create bootpartition"
target_boot="${dodiskid}-part${index}"
index=$(( index + 1 ))
(echo "n";
echo "p";
echo "1";
echo "";
echo "+${cfg[bootsize]}G";
echo "a";
sleep $sleep;
echo "w";
echo "q") | fdisk -w always -W always "${dodiskid}" > /dev/null
sleep $sleep
sync
if [[ "${cfg[rootfssize]}" == "rest" ]]; then
target_partition_tmp="${dodiskid}-part${index}"
echo "create rootfs"
if test -d /sys/firmware/efi; then
(echo "n";
echo "";
echo "";
echo "";
sleep $sleep;
echo "w") | fdisk -w always -W always "${dodiskid}"
else
(echo "n";
echo "p";
echo "2";
echo "";
echo "";
sleep $sleep;
echo "w";
echo "q") | fdisk -w always -W always "${dodiskid}" > /dev/null
fi
elif [[ ! "${cfg[rootfssize]}" == "rest" ]]; then
target_partition_tmp="${dodiskid}-part${index}"
echo "create rootfs with a specific size"
if test -d /sys/firmware/efi; then
(echo "n";
echo "";
echo "";
echo "+${rootfssize}G";
sleep $sleep;
echo "w";
echo "q") | fdisk -w always -W always "${dodiskid}" > /dev/null
else
(echo "n";
echo "p";
echo "2";
echo "";
echo "+${rootfssize}G";
sleep $sleep;
echo "w";
echo "q") | fdisk -w always -W always "${dodiskid}" > /dev/null
fi
fi
sleep $sleep
sync
target_partition="${target_partition_tmp}"
if [[ ! "${cfg[fde_key_store]}" == "none" ]]; then
echo -n "${cfg[diskpw]}" | cryptsetup luksFormat --type luks1 "${target_partition}" -d -
sleep $sleep
sync
echo -n "${cfg[diskpw]}" | cryptsetup luksOpen "${target_partition}" "voidluks-${diskid}" -d -
sleep $sleep
sync
#echo -n "oem" | cryptsetup luksFormat --type luks1 "${target_partition}" -d -
#echo -n "oem" | cryptsetup luksOpen "${target_partition}" "voidluks-${diskid}" -d -
target_partition="/dev/mapper/voidluks-${diskid}"
fi
mkswap "${target_partition}" || exit 1
sleep $sleep
sync
vgcreate -q -f "voidvg.${diskid}" "${target_partition}" || exit 1
sleep $sleep
sync
lvcreate -q -y --name swap -L "${cfg[swapsize]}"G "voidvg.${diskid}" || exit 1
sleep $sleep
sync
lvcreate -q -y --name root -l 100%FREE "voidvg.${diskid}" || exit 1
sleep $sleep
sync
mkfs.btrfs -q -f "/dev/mapper/voidvg.${diskid}-root" || exit 1
mkswap "/dev/mapper/voidvg.${diskid}-swap" || exit 1
mount "/dev/mapper/voidvg.${diskid}-root" "${dest}" || exit 1
btrfs subvol create "${dest}/rootfs"
btrfs subvol create "${dest}/homefs"
mkdir -p "${dest}/system/snapshots/update" "${dest}/system/snapshots/regular" "${dest}/system/backup"
umount "${dest}"
mount "/dev/mapper/voidvg.${diskid}-root" "${dest}" -o subvol=rootfs
for i in boot home dev proc sys tmp etc var/lib/backup/quelle/rootfs var/lib/backup/ziel var/db; do mkdir -p "${dest}/${i}"; done
mount "/dev/mapper/voidvg.${diskid}-root" "${dest}"/home -o subvol=homefs
mkdir -p "${dest}/var/lib/backup/quelle/bootfs"
mkfs.btrfs -q -f "${target_boot}"
mount "${target_boot}" "${dest}/boot"
btrfs subvol create "${dest}/boot/bootfs"
mkdir -p "${dest}/boot/system/snapshots/update" "${dest}/boot/system/snapshots/regular" "${dest}/boot/system/backup"
umount "${dest}/boot"
if [[ "${cfg[fde_key_store]}" == "once" ]]; then
mount "${target_boot}" "${dest}/boot" -o subvol=bootfs
fi
if test -d /sys/firmware/efi; then
mkdir -p "${dest}/boot/efi"
mkfs.vfat -F32 "${efipart}"
mount "${efipart}" "${dest}/boot/efi"
fi
for dir in dev proc sys run; do mkdir -p "${dest}"/$dir ; mount --rbind /$dir "${dest}"/$dir ; mount --make-rslave "${dest}"/$dir ; done
setconf add rootuuid "$(blkid -o value -s UUID ${target_partition})"
setconf add partuuid "$(blkid -o value -s UUID ${cfg[diskname]}${cfg[target_part]})"
[[ "${cfg[fde_key_store]}" == "once" ]] && setconf "add" "bootuuid" "$(blkid -o value -s UUID ${target_boot})"
setconf add swapuuid "$(blkid -o value -s UUID /dev/mapper/voidvg.${diskid}-swap)"
mount -t tmpfs -o size=512m tmpfs "${dest}"/tmp
module end