#!/bin/bash # Varidate whether script is executed as sourced or not (return 0 2>/dev/null) && sourced=1 || sourced=0 if [ $sourced -eq 0 ] ; then cat <&2 ***** ERROR : Must execute as source ***** Execute as following : source 1-pre-install.sh Installation terminates. HEREDOC exit fi # ----- Set Passphrase ----- # Input passphrase echo "Type passphrase for the disk encryption." read -sr PASSPHRASE echo "Type passphrase again, to confirm." read -sr PASSPHRASE_C # Validate whether both are indentical or not if [ ${PASSPHRASE} = ${PASSPHRASE_C} ] ; then export PASSPHRASE else cat <&2 ***** ERROR : Passphrase doesn't match ***** Installation terminates. HEREDOC return fi # ----- Configuration Parameter ----- # Load the configuration parameter source config.sh # ----- Format the disk and encrypt the LUKS partition ----- if [ ${ERASEALL} -eq 1 ] ; then # For sure ask ready to erase. echo "Are you sure you want to erase entire ${DEV}? [Y/N]" read YESNO if [ YESNO != "Y" -a YESNO != "y" ] ; then cat <&2 Check config.sh. The ERASEALL is ${ERASEALL}. Installation terminates. HEREDOC return fi # Assign specified space and rest of disk to the EFI and LUKS partition, respectively. if [ ${ISEFI} -eq 1 ] ; then # Zap existing partition table and create new GPT sgdisk --zap-all "${DEV}" # Create EFI partition and format it sgdisk --new=${EFIPARTITION}:0:+${EFISIZE} --change-name=${EFIPARTITION}:"EFI System" --typecode=${EFIPARTITION}:ef00 "${DEV}" mkfs.vfat -F 32 -n EFI-SP "${DEV}${EFIPARTITION}" # Create Linux partition sgdisk --new=${CRYPTPARTITION}:0:0 --change-name=${CRYPTPARTITION}:"Linux LUKS" --typecode=${CRYPTPARTITION}:8309 "${DEV}" # Then print them sgdisk --print "${DEV}" else # Zap existing partition table dd if=/dev/zero of=${DEV} bs=512 count=1 # Create MBR and allocate max storage for Linux partition sfdisk ${DEV} <&2 ***** ERROR : Cannot open LUKS volume ${CRYPTPARTNAME} on ${DEV}${CRYPTPARTITION}. ***** Check the passphrase Installation terminates. HEREDOC return fi # ----- Configure the LVM in LUKS volume ----- # The swap volume and / volume is created here, based on the given parameters. # Create a Physical Volume and Volume Group. pvcreate /dev/mapper/${CRYPTPARTNAME} vgcreate ${VGNAME} /dev/mapper/${CRYPTPARTNAME} # Create a SWAP Logical Volume on VG, if it doesn't exist if [ ! -d /dev/mapper/${VGNAME}-${LVSWAPNAME} ] ; then lvcreate -L ${LVSWAPSIZE} -n ${LVSWAPNAME} ${VGNAME} else echo "Swap volume already exist. Skipped to create" 1>&2 fi # Create a ROOT Logical Volume on VG. if [ ! -d /dev/mapper/${VGNAME}-${LVROOTNAME} ] ; then lvcreate -l ${LVROOTSIZE} -n ${LVROOTNAME} ${VGNAME} else cat <&2 ***** ERROR : Logical volume ${VGNAME}-${LVROOTNAME} already exists. ***** Check LVROOTNAME environment variable. Installation terminates. HEREDOC return fi cat <