123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- DEVICE=$1
- SWAP_SIZE=$2
- CONDOR_SIZE=$3
- TEMP_SIZE=$4
- VM_SIZE=$5
- NOTEX_E=1
- NOTBLK_E=2
- ISMOUNT_E=3
- ISSWAP_E=4
- ISLVM_E=5
- # checking if the disk is used
- if [ ! -e ${DEVICE} ] ; then
- printf "$0: error: ${DEVICE} does not exist.\n" >&2
- exit ${NOTEX_E}
- fi
- if [ ! -b ${DEVICE} ] ; then
- printf "$0: error: ${DEVICE} is not a block file.\n" >&2
- exit ${NOTBLK_E}
- fi
- if grep --quiet "${DEVICE}" /proc/mounts ; then
- printf "$0: error: ${DEVICE} is mounted. Unmount it first.\n" >&2
- exit ${ISMOUNT_E}
- fi
- if grep --quiet "${DEVICE}" /proc/swaps ; then
- printf "$0: error: ${DEVICE} is used as swap. Swapoff it first.\n" >&2
- exit ${ISSWAP_E}
- fi
- if pvs --select pv_in_use=1 | grep --quiet "${DEVICE}" ; then
- printf "$0: error: ${DEVICE} is part of a LVM volume group.\n" >&2
- exit ${ISLVM_E}
- fi
- echo "SFDISK ----------------------------------------------------"
- # partitioning the disk
- sfdisk "${DEVICE}" <<-sfdisk-script-end
- # 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
- # LVM
- echo "PVCREATE --------------------------------------------------"
- pvcreate "${DEVICE}1"
- echo "VGCREATE --------------------------------------------------"
- vgcreate localDisk "${DEVICE}1"
- if [ "${SWAP_SIZE}" != 0 ] ; then
- echo "LVCREATE SWAP --------------------------------------------------"
- lvcreate -C y -L "${SWAP_SIZE}G" localDisk -n swap
- echo "MKSWAP --------------------------------------------------"
- mkswap /dev/localDisk/swap
- fi
- if [ "${CONDOR_SIZE}" != 0 ] ; then
- echo "LVCREATE CONDOR --------------------------------------------------"
- lvcreate -L "${CONDOR_SIZE}G" localDisk -n condor
- echo "MKFS CONDOR --------------------------------------------------"
- mkfs.ext4 /dev/localDisk/condor
- fi
- if [ "${TEMP_SIZE}" != 0 ] ; then
- echo "LVCREATE TEMP --------------------------------------------------"
- lvcreate -L "${TEMP_SIZE}G" localDisk -n tempdir
- echo "MKFS TEMP --------------------------------------------------"
- mkfs.ext4 /dev/localDisk/tempdir
- fi
- if [ "${VM_SIZE}" != 0 ] ; then
- echo "LVCREATE CALCOLO --------------------------------------------------"
- lvcreate -L "${VM_SIZE}G" localDisk -n calcolo
- fi
|