Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.41 KB | None | 0 0
  1. #start here: https://help.ubuntu.com/community/ManualFullSystemEncryption
  2. # This is a butchering of the script the guide gets you to run.
  3. # Made to be exactly what I want without any extras or prompts.
  4.  
  5.  
  6. #findPartitions # The various partitions.
  7. # I'm just manually entering what I want
  8. declare -gr DATA_PARTITION_CHOSEN=false
  9. declare -gr SWAP_PARTITION_CHOSEN=false
  10. declare -gr HIBERNATION_CHOSEN=${SWAP_PARTITION_CHOSEN}
  11. #declare -gr SWAP_PARTITION_SIZE=65536
  12. declare -gr PARTITION_SYSTEM=/dev/sdc1
  13. #PARTITION_ESP= this is EFI and so I don't need this
  14. # findBootloader # The bootloader.
  15. #declare -gr BOOTLOADER=/dev/??? #not sure I need this either
  16. # findPassphrases # The passphrases (and password note).
  17. declare -gr PASSPHRASE_SYSTEM=""
  18.  
  19. #preInstallationProcess # Do the pre-installation
  20. # Encrypt the system partition.
  21. encryptPartition System ${PARTITION_SYSTEM} "${PASSPHRASE_SYSTEM}"
  22.  
  23. # Unlock the system partition.
  24. unlockPartition System system ${PARTITION_SYSTEM} "${PASSPHRASE_SYSTEM}"
  25.  
  26. setUpLvm System system # Set up the system LVM.
  27.  
  28. setUpLogicalVolume Boot boot system 512M # Create /boot.
  29. formatVolume Boot system-boot ext4 boot # Format /boot.
  30.  
  31. setUpLogicalVolume Root root system '100%FREE' # Create root.
  32. formatVolume Root system-root ext4 root # Format root.
  33.  
  34. #runInstaller # Run the installer.
  35. echo "just manually run the installer and follow the guide"
  36. echo "https://help.ubuntu.com/community/ManualFullSystemEncryption/DetailedProcessInstallUbuntu"
  37. read -rp 'Press Enter to continue once installer finished, or press Ctrl+C to cancel: '
  38.  
  39.  
  40. #---------------------------------------------------------------------------------------------------
  41. #-------- Functions --------------------------------------------------------------------------------
  42. #---------------------------------------------------------------------------------------------------
  43.  
  44. function inputSummary ()
  45. {
  46. cat <<-END
  47.  
  48. $Summary
  49.  
  50. Partition ${PARTITION_SYSTEM} will be used for your System partition (root).
  51. Passphrase: ${PASSPHRASE_SYSTEM}
  52.  
  53.  
  54. Please check the details carefully before deciding whether or not to proceed.
  55.  
  56.  
  57. Are you sure that these details are correct?
  58.  
  59. END
  60.  
  61. # Confirm permission.
  62. local ANSWER=''
  63. read -rp "Type Y to proceed, or anything else to cancel, and press Enter: " ANSWER
  64.  
  65. if [[ "${ANSWER,}" != 'y' ]]
  66. then
  67. echo
  68. echo 'Terminated. I did nothing.'
  69. echo
  70. exit 3 # Terminate if incorrect.
  71. fi
  72. } #inputSummary
  73.  
  74. #---------------------------------------------------------------------------------------------------
  75. # Encrypt a partition
  76. #
  77. # Parameters
  78. # 1 Human-readable name for the partition
  79. # 2 The partition, e.g. /dev/sda2, nvme0n1p2
  80. # 3 The passphrase
  81. #---------------------------------------------------------------------------------------------------
  82.  
  83.  
  84. function encryptPartition ()
  85. {
  86. local -r HUMAN_NAME=${1}
  87. local -r PARTITION=${2}
  88. local -r PASSPHRASE="${3}"
  89.  
  90. echo
  91. echo "Encrypting the ${HUMAN_NAME} partition..."
  92.  
  93. # Encrypt the partition.
  94. echo -n "${PASSPHRASE}" | sudo cryptsetup luksFormat --hash=sha512 --key-size=512 --key-file=- ${PARTITION}
  95.  
  96. local -ir RET=${?} # Catch the return code.
  97.  
  98. (( RET )) && error "There was an error encrypting the ${HUMAN_NAME} partition." ${RET}
  99.  
  100. } # encryptPartition
  101.  
  102.  
  103. #---------------------------------------------------------------------------------------------------
  104. # Unlock a partition
  105. #
  106. # Parameters
  107. # 1 Human-readable name for the partition
  108. # 2 Partition label
  109. # 3 The partition, e.g. /dev/sda2, /dev/nvme0n1p2
  110. # 4 The passphrase
  111. #---------------------------------------------------------------------------------------------------
  112.  
  113.  
  114. function unlockPartition ()
  115. {
  116. local -r HUMAN_NAME=${1}
  117. local -r LABEL=${2}
  118. local -r PARTITION=${3}
  119. local -r PASSPHRASE="${4}"
  120.  
  121. echo
  122. echo "Unlocking the ${HUMAN_NAME} partition..."
  123.  
  124. # Unlock the partition.
  125. echo -n "${PASSPHRASE}" | sudo cryptsetup open --type=luks --key-file=- ${PARTITION} ${LABEL}
  126.  
  127. local -ir RET=${?} # Catch the return code.
  128.  
  129. (( RET )) && error "There was an error unlocking the ${HUMAN_NAME} partition." ${RET}
  130.  
  131. } # unlockPartition
  132.  
  133.  
  134. #---------------------------------------------------------------------------------------------------
  135. # Set up LVM for the partition.
  136. #
  137. # Parameters
  138. # 1 Human-readable name for the partition
  139. # 2 Partition label
  140. #---------------------------------------------------------------------------------------------------
  141.  
  142.  
  143. function setUpLvm ()
  144. {
  145. local -r HUMAN_NAME=${1}
  146. local -r LABEL=${2}
  147.  
  148. echo
  149. echo "Set up ${HUMAN_NAME} physical volume for ${LABEL}..."
  150.  
  151. sudo pvcreate /dev/mapper/${LABEL} # Initialise the physical volume.
  152.  
  153. local -i RET=${?} # Catch the return code.
  154.  
  155. (( RET )) && error "There was an error initialising the physical volume for LVM on the ${HUMAN_NAME} partition." ${RET}
  156.  
  157. echo
  158. echo "Set up ${HUMAN_NAME} volume group for ${LABEL}..."
  159.  
  160. sudo vgcreate ${LABEL} /dev/mapper/${LABEL} # Set up the volume group.
  161.  
  162. RET=${?} # Catch the return code.
  163.  
  164. (( RET )) && error "There was an error setting up the volume group for LVM on the ${HUMAN_NAME} partition." ${RET}
  165.  
  166. } # setUpLvm
  167.  
  168.  
  169. #---------------------------------------------------------------------------------------------------
  170. # Set up the logical volume for a partition.
  171. #
  172. # Parameters
  173. # 1 Human-readable name for the partition
  174. # 2 Partition label
  175. # 3 Partition to set up
  176. # 4 Size, including the modifier, e.g. 512M and 100%FREE
  177. #---------------------------------------------------------------------------------------------------
  178.  
  179.  
  180. function setUpLogicalVolume ()
  181. {
  182. local -r HUMAN_NAME=${1} # Human-readable name.
  183. local -r LABEL=${2} # The logical volumne name.
  184. local -r PARTITION=${3} # The partition where to create it.
  185. local -r SIZE=${4} # The required size.
  186.  
  187. echo
  188. echo "Set up logical volume ${HUMAN_NAME} for ${LABEL} in ${PARTITION} size ${SIZE}..."
  189.  
  190. if [[ ${SIZE} == '100%FREE' ]]
  191. then
  192. local -r OPTION=extents
  193. else
  194. local -r OPTION=size
  195. fi
  196.  
  197. sudo lvcreate --${OPTION}=${SIZE} --name=${LABEL} ${PARTITION}
  198.  
  199. local -i RET=${?} # Catch the return code.
  200.  
  201. (( RET )) && error "There was an error initialising the logical volume for LVM on the ${HUMAN_NAME} partition." ${RET}
  202.  
  203. } # setUpLogicalVolume
  204.  
  205.  
  206. #---------------------------------------------------------------------------------------------------
  207. # Format a volume.
  208. #
  209. # Parameters
  210. # 1 Human-readable name for the partition
  211. # 2 Partition to be formatted
  212. # 3 Type of format, specifically swap or ext4
  213. # 4 Lbel for the partition
  214. #---------------------------------------------------------------------------------------------------
  215.  
  216.  
  217. function formatVolume ()
  218. {
  219. local -r HUMAN_NAME="${1}"
  220. local -r PARTITION=${2}
  221. local -r TYPE=${3}
  222. local -r LABEL="${4}"
  223.  
  224. echo
  225. echo "Format ${HUMAN_NAME} partition ${PARTITION} (${LABEL}) as ${TYPE}..."
  226.  
  227. # Format the partition.
  228. if [[ ${TYPE} == 'swap' ]]
  229. then
  230. sudo mkswap --label=${LABEL} /dev/mapper/${PARTITION}
  231. else
  232. sudo mkfs.ext4 -L ${LABEL} /dev/mapper/${PARTITION}
  233. fi
  234.  
  235. local -ir RET=${?} # Catch the return code.
  236.  
  237. (( RET )) && error "Error formatting the ${HUMAN_NAME} partition in ${PARTITION}." ${RET}
  238.  
  239. } # formatVolume
  240.  
  241.  
  242.  
  243.  
  244.  
  245. postInstallationProcess # Do the post-installation work.
  246. go to https://help.ubuntu.com/community/ManualFullSystemEncryption/DetailedProcessCheckAndFinalise
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement