newdisk-automator.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/bash
  2. DIR="/home/ravioli/newdisk-automator"
  3. . "${DIR}/error.sh"
  4. . "${DIR}/parse-arguments.sh"
  5. . "${DIR}/utils.sh"
  6. . "${DIR}/check-device.sh"
  7. PROGRAM_NAME="$0"
  8. parse_arguments $@
  9. # removing lvm and other filesystem signatures)
  10. if [ $LVM == 1]
  11. echo "Erasing disk signatures..."
  12. vgchange -an $(vgs --noheadings --select pv_name=~"${DEVICE}" -o vg_name)
  13. fi
  14. wipefs -a ${DEVICE}[[:digit:]]*
  15. wipefs -a ${DEVICE}
  16. echo "SFDISK ----------------------------------------------------"
  17. # partitioning the disk
  18. sfdisk "${DEVICE}" <<-sfdisk-script-end
  19. # Create a new partition table on the specified disk, and create a new Linux LVM partition
  20. #
  21. # partition table info
  22. label: gpt
  23. #
  24. # partitions info
  25. #start size type bootable
  26. , ,31 ,
  27. sfdisk-script-end
  28. # LVM
  29. echo "PVCREATE --------------------------------------------------"
  30. pvcreate "${DEVICE}1"
  31. echo "VGCREATE --------------------------------------------------"
  32. vgcreate localDisk "${DEVICE}1"
  33. if [ "${SWAP_SIZE}" != 0 ] ; then
  34. echo "LVCREATE SWAP --------------------------------------------------"
  35. lvcreate -W n -C y -L "${SWAP_SIZE}B" localDisk -n swap
  36. echo "MKSWAP --------------------------------------------------"
  37. mkswap /dev/localDisk/swap
  38. fi
  39. if [ "${CONDOR_SIZE}" != 0 ] ; then
  40. echo "LVCREATE CONDOR --------------------------------------------------"
  41. lvcreate -W n -L "${CONDOR_SIZE}B" localDisk -n condor
  42. echo "MKFS CONDOR --------------------------------------------------"
  43. mkfs.ext4 /dev/localDisk/condor
  44. fi
  45. if [ "${TEMP_SIZE}" != 0 ] ; then
  46. echo "LVCREATE TEMP --------------------------------------------------"
  47. lvcreate -W n -L "${TEMP_SIZE}B" localDisk -n tempdir
  48. echo "MKFS TEMP --------------------------------------------------"
  49. mkfs.ext4 /dev/localDisk/tempdir
  50. fi
  51. if [ "${VM_SIZE}" != 0 ] ; then
  52. echo "LVCREATE CALCOLO --------------------------------------------------"
  53. lvcreate -W n -L "${VM_SIZE}B" localDisk -n calcolo
  54. fi