12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- #!/bin/sh
- 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
- LVMUSED_E=5
- LVMPV_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 | grep --quiet "${DEVICE}" ; then
- if [ $(lvs --noheadings --select vg_name="$(pvs --noheadings --select pv_name=~"${DEVICE}" -o vg_name)" --select lv_device_open!=0 | wc -l) -ne 0 ] ; then
- printf "$0: error: ${DEVICE} is part of a used lvm volume.\n" >&2
- exit ${LVMUSED_E}
- fi
- if [ $(vgs --noheadings --select pv_name=~"${DEVICE}" -o pv_count | uniq) -gt $(vgs --noheadings --select pv_name=~"${DEVICE}" | wc -l) ] ; then
- printf "$0: error: ${DEVICE} is part of a lvm volume group shared with others physical volumes.\n" >&2
- exit ${LVMPV_E}
- fi
- # removing lvm and other filesystem signatures)
- echo "Eresing disk signatures..."
- vgchange -an $(vgs --noheadings --select pv_name=~"${DEVICE}" -o vg_name)
- wipefs -a ${DEVICE}[[:digit:]]*
- wipefs -a ${DEVICE}
- 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 -W n -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 -W n -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 -W n -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 -W n -L "${VM_SIZE}G" localDisk -n calcolo
- fi
|