newdisk-automator 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. DIR="."
  3. PROGRAM_NAME="$0"
  4. . "${DIR}/error.sh"
  5. . "${DIR}/parse-arguments.sh"
  6. . "${DIR}/conversion.sh"
  7. . "${DIR}/check-device.sh"
  8. if [ ${EUID} -ne 0 ]; then
  9. fatal $NOROOT_E "must be root to run this program"
  10. fi
  11. parse_arguments $@
  12. # removing lvm and other filesystem signatures
  13. if [ $LVM == 1 ]; then
  14. vgchange -an $(vgs --noheadings --select pv_name=~"${DEVICE}" -o vg_name) >${PROGRAM_OUTPUT} 2>&1
  15. fi
  16. # Erase all disk signatures form the device and - if they exist - from all its partitions
  17. echo "Erasing disk signatures..." >${SCRIPT_OUTPUT}
  18. if [ -e ${DEVICE}1 ]; then
  19. wipefs -a ${DEVICE}[[:digit:]]* >${PROGRAM_OUTPUT} 2>&1 || fatal ${PROG_E} "wipefs returned $?"
  20. fi
  21. wipefs -a ${DEVICE} >${PROGRAM_OUTPUT} 2>&1 || fatal ${PROG_E} "wipefs returned $%"
  22. # Partition the disk creating a gpt and a single partition occupying the whole remaining disk space
  23. echo "Partitioning the disk..." >${SCRIPT_OUTPUT}
  24. sfdisk "${DEVICE}" <<-sfdisk-script-end >${PROGRAM_OUTPUT} 2>&1 || fatal ${PROG_E} "sfdisk returned $?"
  25. # Create a new partition table on the specified disk, and create a new Linux LVM partition
  26. #
  27. # partition table info
  28. label: gpt
  29. #
  30. # partitions info
  31. #start size type bootable
  32. , ,31 ,
  33. sfdisk-script-end
  34. # Create physical volume on device and then volume group localDisk
  35. echo "Creating physical volume ${DEVICE}1..." >${SCRIPT_OUTPUT}
  36. pvcreate "${DEVICE}1" >${PROGRAM_OUTPUT} 2>&1 || fatal ${PROG_E} "pvcreate returned $?"
  37. echo "Creating volume group localDisk..." >${SCRIPT_OUTPUT}
  38. vgcreate localDisk "${DEVICE}1" >${PROGRAM_OUTPUT} 2>&1 || fatal ${PROG_E} "vgcreate returned $?"
  39. # Create local volumes and partition them.
  40. # If the specified size is 0, it means that the volume must not be created
  41. if [ "${SWAP_SIZE}" != 0 ] ; then
  42. echo "Creating logical volume swap..." >${SCRIPT_OUTPUT}
  43. lvcreate -W n -C y --size "${SWAP_SIZE}S" localDisk -n swap >${PROGRAM_OUTPUT} 2>&1 || fatal ${PROG_E} "lvcreate returned $? for swap lv"
  44. echo "Formatting swap lv..." >${SCRIPT_OUTPUT}
  45. mkswap /dev/localDisk/swap >${PROGRAM_OUTPUT} 2>&1 || fatal ${PROG_E} "mkswap returned $?"
  46. fi
  47. if [ "${CONDOR_SIZE}" != 0 ] ; then
  48. echo "Creating logical volume condor..." >${SCRIPT_OUTPUT}
  49. lvcreate -W n --size "${CONDOR_SIZE}S" localDisk -n condor >${PROGRAM_OUTPUT} 2>&1 || fatal ${PROG_E} "lvcreate returned $? for condor lv"
  50. echo "Formatting condor lv..." >${SCRIPT_OUTPUT}
  51. mkfs.ext4 /dev/localDisk/condor >${PROGRAM_OUTPUT} 2>&1 || fatal ${PROG_E} "mkfs returned $? for condor lv"
  52. fi
  53. if [ "${TEMP_SIZE}" != 0 ] ; then
  54. echo "Creating logical volume tempdir..." >${SCRIPT_OUTPUT}
  55. lvcreate -W n --size "${TEMP_SIZE}S" localDisk -n tempdir >${PROGRAM_OUTPUT} 2>&1|| fatal ${PROG_E} "lvcreate returned $? for tempdir lv"
  56. echo "Formatting tempdir lv..." >${SCRIPT_OUTPUT}
  57. mkfs.ext4 /dev/localDisk/tempdir >${PROGRAM_OUTPUT} 2>&1|| fatal ${PROG_E} "mkfs returned $? for tempdir lv"
  58. fi
  59. if [ "${VM_SIZE}" != 0 ] ; then
  60. echo "Creating logical volume calcolo..." >${SCRIPT_OUTPUT}
  61. lvcreate -W n --size "${VM_SIZE}S" localDisk -n calcolo >${PROGRAM_OUTPUT} 2>&1 || fatal ${PROG_E} "lvcreate returned $? for vm lv"
  62. # The vm logical volume is not partitioned
  63. fi