#!/bin/bash DIR="." PROGRAM_NAME="$0" . "${DIR}/error.sh" . "${DIR}/parse-arguments.sh" . "${DIR}/conversion.sh" . "${DIR}/check-device.sh" if [ ${EUID} -ne 0 ]; then fatal $NOROOT_E "must be root to run this program" fi parse_arguments $@ # removing lvm and other filesystem signatures if [ $LVM == 1 ]; then vgchange -an $(vgs --noheadings --select pv_name=~"${DEVICE}" -o vg_name) >${PROGRAM_OUTPUT} 2>&1 fi # Erase all disk signatures form the device and - if they exist - from all its partitions echo "Erasing disk signatures..." >${SCRIPT_OUTPUT} if [ -e ${DEVICE}1 ]; then wipefs -a ${DEVICE}[[:digit:]]* >${PROGRAM_OUTPUT} 2>&1 || fatal ${PROG_E} "wipefs returned $?" fi wipefs -a ${DEVICE} >${PROGRAM_OUTPUT} 2>&1 || fatal ${PROG_E} "wipefs returned $%" # Partition the disk creating a gpt and a single partition occupying the whole remaining disk space echo "Partitioning the disk..." >${SCRIPT_OUTPUT} sfdisk "${DEVICE}" <<-sfdisk-script-end >${PROGRAM_OUTPUT} 2>&1 || fatal ${PROG_E} "sfdisk returned $?" # Create a new partition table on the specified disk, and create a new Linux LVM partition # # partition table info label: gpt # # partitions info #start size type bootable , ,31 , sfdisk-script-end # Create physical volume on device and then volume group localDisk echo "Creating physical volume ${DEVICE}1..." >${SCRIPT_OUTPUT} pvcreate "${DEVICE}1" >${PROGRAM_OUTPUT} 2>&1 || fatal ${PROG_E} "pvcreate returned $?" echo "Creating volume group localDisk..." >${SCRIPT_OUTPUT} vgcreate localDisk "${DEVICE}1" >${PROGRAM_OUTPUT} 2>&1 || fatal ${PROG_E} "vgcreate returned $?" # Create local volumes and partition them. # If the specified size is 0, it means that the volume must not be created if [ "${SWAP_SIZE}" != 0 ] ; then echo "Creating logical volume swap..." >${SCRIPT_OUTPUT} lvcreate -W n -C y --size "${SWAP_SIZE}S" localDisk -n swap >${PROGRAM_OUTPUT} 2>&1 || fatal ${PROG_E} "lvcreate returned $? for swap lv" echo "Formatting swap lv..." >${SCRIPT_OUTPUT} mkswap /dev/localDisk/swap >${PROGRAM_OUTPUT} 2>&1 || fatal ${PROG_E} "mkswap returned $?" fi if [ "${CONDOR_SIZE}" != 0 ] ; then echo "Creating logical volume condor..." >${SCRIPT_OUTPUT} lvcreate -W n --size "${CONDOR_SIZE}S" localDisk -n condor >${PROGRAM_OUTPUT} 2>&1 || fatal ${PROG_E} "lvcreate returned $? for condor lv" echo "Formatting condor lv..." >${SCRIPT_OUTPUT} mkfs.ext4 /dev/localDisk/condor >${PROGRAM_OUTPUT} 2>&1 || fatal ${PROG_E} "mkfs returned $? for condor lv" fi if [ "${TEMP_SIZE}" != 0 ] ; then echo "Creating logical volume tempdir..." >${SCRIPT_OUTPUT} lvcreate -W n --size "${TEMP_SIZE}S" localDisk -n tempdir >${PROGRAM_OUTPUT} 2>&1|| fatal ${PROG_E} "lvcreate returned $? for tempdir lv" echo "Formatting tempdir lv..." >${SCRIPT_OUTPUT} mkfs.ext4 /dev/localDisk/tempdir >${PROGRAM_OUTPUT} 2>&1|| fatal ${PROG_E} "mkfs returned $? for tempdir lv" fi if [ "${VM_SIZE}" != 0 ] ; then echo "Creating logical volume calcolo..." >${SCRIPT_OUTPUT} lvcreate -W n --size "${VM_SIZE}S" localDisk -n calcolo >${PROGRAM_OUTPUT} 2>&1 || fatal ${PROG_E} "lvcreate returned $? for vm lv" # The vm logical volume is not partitioned fi