newdisk-automator.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. DEVICE=$1
  2. SWAP_SIZE=$2
  3. CONDOR_SIZE=$3
  4. TEMP_SIZE=$4
  5. VM_SIZE=$5
  6. NOTEX_E=1
  7. NOTBLK_E=2
  8. ISMOUNT_E=3
  9. ISSWAP_E=4
  10. ISLVM_E=5
  11. # checking if the disk is used
  12. if [ ! -e ${DEVICE} ] ; then
  13. printf "$0: error: ${DEVICE} does not exist.\n" >&2
  14. exit ${NOTEX_E}
  15. fi
  16. if [ ! -b ${DEVICE} ] ; then
  17. printf "$0: error: ${DEVICE} is not a block file.\n" >&2
  18. exit ${NOTBLK_E}
  19. fi
  20. if grep --quiet "${DEVICE}" /proc/mounts ; then
  21. printf "$0: error: ${DEVICE} is mounted. Unmount it first.\n" >&2
  22. exit ${ISMOUNT_E}
  23. fi
  24. if grep --quiet "${DEVICE}" /proc/swaps ; then
  25. printf "$0: error: ${DEVICE} is used as swap. Swapoff it first.\n" >&2
  26. exit ${ISSWAP_E}
  27. fi
  28. if pvs --select pv_in_use=1 | grep --quiet "${DEVICE}" ; then
  29. printf "$0: error: ${DEVICE} is part of a LVM volume group.\n" >&2
  30. exit ${ISLVM_E}
  31. fi
  32. echo "SFDISK ----------------------------------------------------"
  33. # partitioning the disk
  34. sfdisk "${DEVICE}" <<-sfdisk-script-end
  35. # Create a new partition table on the specified disk, and create a new Linux LVM partition
  36. #
  37. # partition table info
  38. label: gpt
  39. #
  40. # partitions info
  41. #start size type bootable
  42. , ,31 ,
  43. sfdisk-script-end
  44. # LVM
  45. echo "PVCREATE --------------------------------------------------"
  46. pvcreate "${DEVICE}1"
  47. echo "VGCREATE --------------------------------------------------"
  48. vgcreate localDisk "${DEVICE}1"
  49. if [ "${SWAP_SIZE}" != 0 ] ; then
  50. echo "LVCREATE SWAP --------------------------------------------------"
  51. lvcreate -C y -L "${SWAP_SIZE}G" localDisk -n swap
  52. echo "MKSWAP --------------------------------------------------"
  53. mkswap /dev/localDisk/swap
  54. fi
  55. if [ "${CONDOR_SIZE}" != 0 ] ; then
  56. echo "LVCREATE CONDOR --------------------------------------------------"
  57. lvcreate -L "${CONDOR_SIZE}G" localDisk -n condor
  58. echo "MKFS CONDOR --------------------------------------------------"
  59. mkfs.ext4 /dev/localDisk/condor
  60. fi
  61. if [ "${TEMP_SIZE}" != 0 ] ; then
  62. echo "LVCREATE TEMP --------------------------------------------------"
  63. lvcreate -L "${TEMP_SIZE}G" localDisk -n tempdir
  64. echo "MKFS TEMP --------------------------------------------------"
  65. mkfs.ext4 /dev/localDisk/tempdir
  66. fi
  67. if [ "${VM_SIZE}" != 0 ] ; then
  68. echo "LVCREATE CALCOLO --------------------------------------------------"
  69. lvcreate -L "${VM_SIZE}G" localDisk -n calcolo
  70. fi