newdisk-automator 3.0 KB

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