#!/bin/bash set -euo pipefail BASEDIR="$(dirname "${0}" | sed "s|^\.|${PWD}|")" source \ /etc/os-release source \ "${BASEDIR}/system.conf" if [[ ! "${DISK}" == **/dev/disk/by-id/** ]]; then if [[ "${DISK}" == **/dev/nvme** ]]; then PART3='p3' else PART3='3' fi else PART3='-part3' fi swapoff \ --all wipefs \ -a \ ${DISK} if [[ ! "${DISK_TYPE}" == 'HDD' ]]; then blkdiscard \ -f \ ${DISK} fi sgdisk \ --zap-all \ ${DISK} sgdisk \ -n1:0:+512M \ -t1:EF00 \ -c1:EFI \ ${DISK} if [[ "${ENABLE_SWAP}" == "yes" ]]; then SWAP_SIZE="$(((($(vmstat -sS M | grep 'total memory' | sed 's/ M total memory//') / 1024) + 1) * 2))" sgdisk \ -n2:0:+${SWAP_SIZE}G \ -t2:BF02 \ -c2:swap \ ${DISK} fi sgdisk \ -n3:0:0 \ -t3:BF00 \ -c3:${ID} \ ${DISK}