newdisk-automator 2.1 KB

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