Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #!/bin/bash
  2.  
  3. ################################################################################
  4. # Helper for an easier crypt setup with (K)Ubuntu Linux and LUKS/LVM
  5. #
  6. # Tested on the following Ubuntu versions:
  7. # - Ubuntu 9.04 Jaunty (32bit and 64bit)
  8. # - Ubuntu 9.10 Karmic (32bit and 64bit)
  9. # - Ubuntu 10.04 Lucid (32bit and 64bit)
  10. # - Ubuntu 10.10 Maverick (32bit and 64bit)
  11. # - Ubuntu 11.04 Natty (32bit and 64bit)
  12. # - Ubuntu 11.10 Oneiric (32bit and 64bit)
  13. #
  14. # Tested on the following Kubuntu versions:
  15. # - Kubuntu 10.04 Lucid (32bit and 64bit)
  16. # - Kubuntu 11.04 Natty (32bit and 64bit)
  17. #
  18. # I don't have the time to test *every* version out there. Therefore it does not
  19. # mean that this script does not work if your version is not listed above. Just
  20. # try it out and check for an update of this script after a new version of
  21. # (K)Ubuntu is released:
  22. # <http://blog.andreas-haerter.com/2011/06/18/ubuntu-full-disk-encryption-lvm-luks.sh>
  23. #
  24. # Usage:
  25. # 1) Boot a (K)Ubuntu live session
  26. #    ATTENTION: Choose the language you are going to install right from the
  27. #               start! This prevents trouble regarding different keyboard
  28. #               layouts and your entered encryption password!
  29. # 2) Call this script with SUPERUSER privileges (->sudo)
  30. # 3) If you made an error or something like that, REBOOT the Live CD and try it
  31. #    again!
  32. #
  33. #
  34. # LICENSE: This file is open source software (OSS) and may be copied under
  35. #          certain conditions. See the links below for details or try to contact
  36. #          the author(s) of this file in doubt.
  37. #
  38. # @author Andreas Haerter <development@andreas-haerter.com>
  39. # @copyright 2009-2011, Andreas Haerter
  40. # @license GPLv2 (http://www.gnu.org/licenses/gpl2.html)
  41. # @license New/3-clause BSD (http://opensource.org/licenses/bsd-license.php)
  42. # @link http://blog.andreas-haerter.com/2011/06/18/ubuntu-full-disk-encryption-lvm-luks
  43. # @link http://blog.andreas-haerter.com/2011/06/18/ubuntu-festplattenvollverschluesselung-lvm-luks
  44. # @link http://blog.andreas-haerter.com/2011/06/18/ubuntu-full-disk-encryption-lvm-luks.sh
  45. # @link http://andreas-haerter.com
  46. # @version 2011-12-06
  47. ################################################################################
  48. ################################################################################
  49. # Minor changes made to work on Linux Mint 14:
  50. #  - parted with optimal alignment
  51. #  - logical volume names
  52. #  - message about Mint's Ubiquity option for partitioning disk(s)
  53. # @author David Chin <david.w.h.chin@gmail.com>
  54. # @version 2012-11-28
  55. ################################################################################
  56.  
  57. ################################################################################
  58. # DO NOT TOUCH ANYTHING BELOW THIS LINE WITHOUT KNOWING WHAT YOU ARE DOING!
  59. ################################################################################
  60.  
  61. ################################################################################
  62. # Process
  63. ################################################################################
  64. URL_ARTICLE="http://blog.andreas-haerter.com/2011/06/18/ubuntu-full-disk-encryption-lvm-luks"
  65.  
  66. #welcome user
  67. clear
  68. echo "###############################################################################"
  69. echo "# Helper script to install an encrypted (K)Ubuntu Linux (full disk encryption"
  70. echo "# using LUKS/LVM)"
  71. echo "# Found system: $(lsb_release -rs) $(lsb_release -cs)"
  72. echo "#"
  73. echo "# Note: internet connection is mandatory!"
  74. echo "#"
  75. echo "# ATTENTION: THIS SCRIPT MAY ERASE ALL YOUR DATA ON THE CHOSEN DEVICE!"
  76. echo "#            MAKE SURE YOU GOT A BACKUP OF ALL YOUR IMPORTANT DATA OR USE/TRY"
  77. echo "#            AN EMPTY DISK! USE AT YOUR OWN RISK! YOU HAVE BEEN WARNED!"
  78. echo "###############################################################################"
  79.  
  80. #check: are we root?
  81. if [ $(id -u) -ne 0 ]
  82. then
  83.     echo ""
  84.     echo "Superuser privileges needed. Please call this script using 'sudo'/as root." 1>&2
  85.     exit 1
  86. fi
  87.  
  88. #article read? start reading now?
  89. echo ""
  90. echo ""
  91. echo "###############################################################################"
  92. echo "# Article read?"
  93. echo "###############################################################################"
  94. echo "Everything is better if you know what you are doing. All important information"
  95. echo "can be found at:"
  96. echo ${URL_ARTICLE}
  97. echo ""
  98. echo -n "Have you read and understand the article? [y|n]: "
  99. read INPUT
  100. if [ ! "${INPUT}" == "y" ] &&
  101.    [ ! "${INPUT}" == "Y" ] &&
  102.    [ ! "${INPUT}" == "j" ] && #German keyboard
  103.    [ ! "${INPUT}" == "J" ]
  104. then
  105.     echo "Starting browser..."
  106.     hash firefox > /dev/null 2>&1
  107.     if [ $? -ne 0 ]
  108.     then
  109.         echo ""
  110.         echo "Firefox error... maybe Kubuntu instead of Ubuntu is running here."
  111.         echo "Let's try to start konqueror or rekonq...."
  112.         echo ""
  113.         hash konqueror > /dev/null 2>&1
  114.         if [ $? -ne 0 ]
  115.         then
  116.             killall rekonq > /dev/null 2>&1 #default since Kubuntu 11.04
  117.             rekonq "${URL_ARTICLE}" > /dev/null 2>&1 &
  118.         else
  119.             killall konqueror > /dev/null 2>&1
  120.             konqueror "${URL_ARTICLE}" > /dev/null 2>&1 &
  121.         fi
  122.     else
  123.         killall firefox-bin > /dev/null 2>&1
  124.         firefox "${URL_ARTICLE}" > /dev/null 2>&1 &
  125.     fi
  126. fi
  127. echo ""
  128. echo "Note: Before all data on your disk will be erased, you will be asked AGAIN."
  129. echo -n "Start work now? [y|n]: "
  130. read INPUT
  131. if [ ! "${INPUT}" == "y" ] &&
  132.    [ ! "${INPUT}" == "Y" ] &&
  133.    [ ! "${INPUT}" == "j" ] && #German keyboard
  134.    [ ! "${INPUT}" == "J" ]
  135. then
  136.     echo "Operation cancelled by user. Recall this script to setup an encrypted system."
  137.     exit 0
  138. fi
  139.  
  140. #keyboard layout check
  141. echo ""
  142. echo ""
  143. echo "###############################################################################"
  144. echo "# Correct keyboard layout?"
  145. echo "###############################################################################"
  146. echo "Please double check if your keyboard layout is the one you will finally use!"
  147. echo "This is ESSENTIAL because you have to define a password."
  148. echo ""
  149. echo "Example: If you are typing a password containing 'z' or 'y' and you are using a"
  150. echo "         US keyboard layout during this setup but going to install Ubuntu in "
  151. echo "         German, your probably set another password as you may thought,"
  152. echo "         wondering why your password is not working ;-) (hint: on German"
  153. echo "         keyboards 'y' and 'z' are interchanged compared to an U.S. keyboard)"
  154. echo ""
  155. echo "Starting keyboard settings. Please check the 'Layouts' tab."
  156. hash gnome-keyboard-properties > /dev/null 2>&1
  157. if [ $? -ne 0 ]
  158. then
  159.     echo ""
  160.     echo "gnome-keyboard-properties error... maybe Kubuntu instead of Ubuntu"
  161.     echo "is running here. Let's try to start the KDE system settings"
  162.     echo ""
  163.     systemsettings > /dev/null 2>&1
  164. else
  165.     gnome-keyboard-properties > /dev/null 2>&1
  166. fi
  167. read -sp "Press [Enter] to continue."
  168. echo ""
  169.  
  170. echo ""
  171. echo ""
  172. echo "###############################################################################"
  173. echo "# Define your values: target device"
  174. echo "###############################################################################"
  175. echo "Please enter the device we have to use (ALL DATA WILL BE ERASED ON THIS ONE!)"
  176. echo ""
  177. echo "Hints:"
  178. echo "- In common, IDE disk are adressed via '/dev/hd[a-z]' ('/dev/hda'=1st disk,"
  179. echo "  '/dev/hdb'=2nd disk, '/dev/hdc'=3rd disk and so on...)."
  180. echo "- In common, SATA disk are adressed via '/dev/sd[a-z]' ('/dev/sda'=1st disk,"
  181. echo "  '/dev/sdb'=2nd, '/dev/sdc'=3rd disk disk and so on...)."
  182. echo ""
  183. echo -n "Which device should be used? "
  184. read DEVICE_TARGET
  185. DEVICE_TARGET_OK="n"
  186. while [ ! "${DEVICE_TARGET_OK}" == "y" ] &&
  187.       [ ! "${DEVICE_TARGET_OK}" == "Y" ] &&
  188.       [ ! "${DEVICE_TARGET_OK}" == "j" ] && #German keyboard
  189.       [ ! "${DEVICE_TARGET_OK}" == "J" ]
  190. do
  191.     if [ "${DEVICE_TARGET}" != "" ]
  192.     then
  193.         echo -n "You typed '${DEVICE_TARGET}'. Is this correct? [y|n]: "
  194.         read DEVICE_TARGET_OK
  195.     fi
  196.     if [ "${DEVICE_TARGET_OK}" == "y" ] ||
  197.        [ "${DEVICE_TARGET_OK}" == "Y" ] ||
  198.        [ "${DEVICE_TARGET_OK}" == "j" ] || #German keyboard
  199.        [ "${DEVICE_TARGET_OK}" == "J" ]
  200.     then
  201.         break 1
  202.     else
  203.         echo -n "Which device should be used? "
  204.         read DEVICE_TARGET
  205.         continue 1
  206.     fi
  207. done
  208.  
  209. echo ""
  210. echo ""
  211. echo "###############################################################################"
  212. echo "# Define your values: size of your boot partition (-> '/boot')"
  213. echo "###############################################################################"
  214. echo "Please enter the size you wish to be used for your boot partition '/boot'. This"
  215. echo "partition should be at least 100MB big. 200MB should be enough to be on the"
  216. echo "safe side."
  217. echo "This script defines a minimal value of 50MB for '/boot', everything below will"
  218. echo "not be accepted."
  219. echo "Please enter the size in MB, digits only. (e.g. enter 200 for 200MB)."
  220. echo ""
  221. echo "NOTE: remaining free space (=space not allocated by '/', '/boot' and swap) will"
  222. echo "      be used for '/home'. A summary will be shown after all needed values are"
  223. echo "      defined."
  224. echo ""
  225. echo -n "Size (in MB) of your boot partition '/boot' (200 is recommended)? "
  226. read SIZE_BOOT
  227. SIZE_BOOT_OK="n"
  228. while [ ! "${SIZE_BOOT_OK}" == "y" ] &&
  229.       [ ! "${SIZE_BOOT_OK}" == "Y" ] &&
  230.       [ ! "${SIZE_BOOT_OK}" == "j" ] && #German keyboard
  231.       [ ! "${SIZE_BOOT_OK}" == "J" ]
  232. do
  233.     if [ "${SIZE_BOOT}" != "" ] &&
  234.        [ ${SIZE_BOOT} -gt 49 ]
  235.     then
  236.         echo -n "You typed '${SIZE_BOOT}'. Is this correct? [y|n]: "
  237.         read SIZE_BOOT_OK
  238.     fi
  239.     if [ "${SIZE_BOOT_OK}" == "y" ] ||
  240.        [ "${SIZE_BOOT_OK}" == "Y" ] ||
  241.        [ "${SIZE_BOOT_OK}" == "j" ] || #German keyboard
  242.        [ "${SIZE_BOOT_OK}" == "J" ]
  243.     then
  244.         break 1
  245.     else
  246.         echo -n "Size (in MB) of your boot partition '/boot' (200 is recommended)? "
  247.         read SIZE_BOOT
  248.         continue 1
  249.     fi
  250. done
  251. unset SIZE_BOOT_OK
  252.  
  253. echo ""
  254. echo ""
  255. echo "###############################################################################"
  256. echo "# Define your values: size of '/'"
  257. echo "###############################################################################"
  258. echo "Please enter the size you wish to be used for your root partition '/'. This"
  259. echo "partition should be at least 8000M big. 25000M should be enough for nearly"
  260. echo "everybody."
  261. echo "This script defines a minimal value of 2500MB for '/', everything below will"
  262. echo "not be accepted."
  263. echo "Please enter the size in MB, digits only. (e.g. enter 8000 for 8000MB)."
  264. echo ""
  265. echo "NOTE: remaining free space (=space not allocated by '/', '/boot' and swap) will"
  266. echo "      be used for '/home'. A summary will be shown after all needed values are"
  267. echo "      defined."
  268. echo ""
  269. echo -n "Size (in MB) of your root partition '/'? "
  270. read SIZE_ROOT
  271. SIZE_ROOT_OK="n"
  272. while [ ! "${SIZE_ROOT_OK}" == "y" ] &&
  273.       [ ! "${SIZE_ROOT_OK}" == "Y" ] &&
  274.       [ ! "${SIZE_ROOT_OK}" == "j" ] && #German keyboard
  275.       [ ! "${SIZE_ROOT_OK}" == "J" ]
  276. do
  277.     if [ "${SIZE_ROOT}" != "" ] &&
  278.        [ ${SIZE_ROOT} -gt 2499 ]
  279.     then
  280.         echo -n "You typed '${SIZE_ROOT}'. Is this correct? [y|n]: "
  281.         read SIZE_ROOT_OK
  282.     fi
  283.     if [ "${SIZE_ROOT_OK}" == "y" ] ||
  284.        [ "${SIZE_ROOT_OK}" == "Y" ] ||
  285.        [ "${SIZE_ROOT_OK}" == "j" ] || #German keyboard
  286.        [ "${SIZE_ROOT_OK}" == "J" ]
  287.     then
  288.         break 1
  289.     else
  290.         echo -n "Size (in MB) of your root partition '/'? "
  291.         read SIZE_ROOT
  292.         continue 1
  293.     fi
  294. done
  295. unset SIZE_ROOT_OK
  296.  
  297. echo ""
  298. echo ""
  299. echo "###############################################################################"
  300. echo "# Define your values: size of swap"
  301. echo "###############################################################################"
  302. echo "Please enter the size you wish to be used for your swap partition. It should"
  303. echo "be 1/3 bigger as your installed RAM to prevent problems using hibernation."
  304. echo "This script defines a minimal value of 256MB for swap, everything below will"
  305. echo "not be accepted."
  306. echo "Please enter the size in MB, digits only (e.g. enter 5200 for 5200MB)."
  307. echo ""
  308. echo "Hints:"
  309. echo "- 1GB RAM  ->  1000MB*1.3 -> 1300MB swap"
  310. echo "- 2GB RAM  ->  2000MB*1.3 -> 2600MB swap"
  311. echo "- 3GB RAM  ->  3000MB*1.3 -> 3900MB swap"
  312. echo "- 4GB RAM  ->  4000MB*1.3 -> 5200MB swap"
  313. echo "- 6GB RAM  ->  6000MB*1.3 -> 7800MB swap"
  314. echo "- 8GB RAM  ->  8000MB*1.3 -> 10400MB swap"
  315. echo "- 10GB RAM -> 10000MB*1.3 -> 13000MB swap"
  316. echo "- 12GB RAM -> 12000MB*1.3 -> 15600MB swap"
  317. echo ""
  318. echo "NOTE: remaining free space (=space not allocated by '/', '/boot' and swap) will"
  319. echo "      be used for '/home'. A summary will be shown after all needed values are"
  320. echo "      defined."
  321. echo ""
  322. echo -n "Size (in MB) of your swap partition? "
  323. read SIZE_SWAP
  324. SIZE_SWAP_OK="n"
  325. while [ ! "${SIZE_SWAP_OK}" == "y" ] &&
  326.       [ ! "${SIZE_SWAP_OK}" == "Y" ] &&
  327.       [ ! "${SIZE_SWAP_OK}" == "j" ] && #German keyboard
  328.       [ ! "${SIZE_SWAP_OK}" == "J" ]
  329. do
  330.     if [ "${SIZE_SWAP}" != "" ] &&
  331.        [ ${SIZE_SWAP} -gt 255 ]
  332.     then
  333.         echo -n "You typed '${SIZE_SWAP}'. Is this correct? [y|n]: "
  334.         read SIZE_SWAP_OK
  335.     fi
  336.     if [ "${SIZE_SWAP_OK}" == "y" ] ||
  337.        [ "${SIZE_SWAP_OK}" == "Y" ] ||
  338.        [ "${SIZE_SWAP_OK}" == "j" ] || #German keyboard
  339.        [ "${SIZE_SWAP_OK}" == "J" ]
  340.     then
  341.         break 1
  342.     else
  343.         echo -n "Size (in MB) of your swap partition? "
  344.         read SIZE_SWAP
  345.         continue 1
  346.     fi
  347. done
  348. unset SIZE_SWAP_OK
  349.  
  350. echo ""
  351. echo ""
  352. echo "###############################################################################"
  353. echo "# Encryption strength"
  354. echo "###############################################################################"
  355. echo "Using 'aes-xts-plain' with a key size of 256bit for XTS and AES is recommended"
  356. echo "on newer machines. However, if you got an older PC (single core), a 128bit key"
  357. echo "is the better choice - and is still *very* secure."
  358. echo "Please enter the size in bit, digits only (e.g. enter 256 for 256bit)."
  359. echo ""
  360. echo "Recommended:"
  361. echo "- Single core/slower machine: 128bit"
  362. echo "- Dualcore and above: 256bit"
  363. echo ""
  364. echo -n "XTS/AES key size (128 or 256)? "
  365. read KEYSIZE
  366. KEYSIZE_OK="n"
  367. while [ ! "${KEYSIZE_OK}" == "y" ] &&
  368.       [ ! "${KEYSIZE_OK}" == "Y" ] &&
  369.       [ ! "${KEYSIZE_OK}" == "j" ] && #German keyboard
  370.       [ ! "${KEYSIZE_OK}" == "J" ]
  371. do
  372.     if [ "${KEYSIZE}" == "128" ] ||
  373.        [ "${KEYSIZE}" == "256" ]
  374.     then
  375.         echo -n "You typed '${KEYSIZE}'. Is this correct? [y|n]: "
  376.         read KEYSIZE_OK
  377.     fi
  378.     if [ "${KEYSIZE_OK}" == "y" ] ||
  379.        [ "${KEYSIZE_OK}" == "Y" ] ||
  380.        [ "${KEYSIZE_OK}" == "j" ] || #German keyboard
  381.        [ "${KEYSIZE_OK}" == "J" ]
  382.     then
  383.         break 1
  384.     else
  385.         echo -n "XTS/AES key size (128 or 256)? "
  386.         read KEYSIZE
  387.         continue 1
  388.     fi
  389. done
  390. unset KEYSIZE_OK
  391.  
  392. echo ""
  393. echo ""
  394. echo "###############################################################################"
  395. echo "# Start now?"
  396. echo "###############################################################################"
  397. echo "Target device:   ${DEVICE_TARGET}"
  398. echo "Key size:        ${KEYSIZE}bit (for each XTS and AES)"
  399. echo "Size of '/':     ${SIZE_ROOT}MB"
  400. echo "Size of '/boot': ${SIZE_BOOT}MB"
  401. echo "Size of 'swap':  ${SIZE_SWAP}MB"
  402. echo "Size of '/home': 100% of the remaining space not used by '/', '/boot' and swap."
  403. echo ""
  404. echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  405. echo "! ATTENTION: ALL DATA ON '${DEVICE_TARGET}' WILL BE ERASED!"
  406. echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  407. echo -n "Start work now? [y|n]: "
  408. read INPUT
  409. if [ ! "${INPUT}" == "y" ] &&
  410.    [ ! "${INPUT}" == "Y" ] &&
  411.    [ ! "${INPUT}" == "j" ] && #German keyboard
  412.    [ ! "${INPUT}" == "J" ]
  413. then
  414.     echo "Operation cancelled by user"
  415.     exit 0
  416. fi
  417.  
  418. echo ""
  419. echo ""
  420. echo "###############################################################################"
  421. echo "# Write random data to '${DEVICE_TARGET}'?"
  422. echo "###############################################################################"
  423. echo "It is recommended to completely fill up your target device with random data"
  424. echo "if it is a common harddisk and was storing unencrypted, personal data until"
  425. echo "now. Additionally, this is a good HDD reliability test for new drives."
  426. echo ""
  427. echo "Note: This may take VERY long (e.g. ~24h for a slower 500GB harddisk using a"
  428. echo "      Celeron M@1.7GHz)."
  429. echo ""
  430. echo -n "Fill '${DEVICE_TARGET}' with random data before encrypting it? [y|n]: "
  431. read INPUT
  432. if [ "${INPUT}" == "y" ] ||
  433.    [ "${INPUT}" == "Y" ] ||
  434.    [ "${INPUT}" == "j" ] || #German keyboard
  435.    [ "${INPUT}" == "J" ]
  436. then
  437.     echo "Start filling up disk with random data... THIS MAY TAKE SEVERAL HOURS!"
  438.     echo ""
  439.     sudo shred -vn 1 ${DEVICE_TARGET}
  440.     if [ $? -ne 0 ]
  441.     then
  442.         echo -e "Filling up disk with random data failed! Please check:\n1) is '${DEVICE_TARGET}' correct? 2) your hardware\nReboot and try it again afterwards!" 1>&2
  443.         exit 1
  444.     fi
  445.     read -sp "Filling up disk with random data done. Press [Enter] to continue."
  446. fi
  447.  
  448. echo ""
  449. echo ""
  450. echo "###############################################################################"
  451. echo "# LiveCD: Install needed packages and load needed kernel modules"
  452. echo "###############################################################################"
  453. #install needed packages
  454. sudo apt-get install --yes lvm2 cryptsetup
  455. if [ $? -ne 0 ]
  456. then
  457.     echo "Could not install needed packages - please check your internet connection, reboot and try it again!" 1>&2
  458.     exit 1
  459. fi
  460. #load needed kernel modules
  461. sudo modprobe dm-crypt
  462. if [ $? -ne 0 ]
  463. then
  464.     echo "Could not load needed kernel modules?! Please reboot and try it again!" 1>&2
  465.     exit 1
  466. fi
  467. echo "Done."
  468.  
  469. echo ""
  470. echo ""
  471. echo "###############################################################################"
  472. echo "# Target system: create needed partitions on '${DEVICE_TARGET}'"
  473. echo "###############################################################################"
  474. # Old way using fdisk. Replaced through parted cause fdsik is using a msdos partition
  475. # table with a built-in 2TiB partition limit. parted is able to use GPT and therefore
  476. # you can create partitions >2TiB.
  477. #
  478. # Old code for documentary reasons follows:
  479. #sudo fdisk ${DEVICE_TARGET} << EOF
  480. #o
  481. #n
  482. #p
  483. #1
  484. #
  485. #+${SIZE_BOOT}M
  486. #n
  487. #p
  488. #2
  489. #
  490. #
  491. #p
  492. #w
  493. #EOF
  494. #if [ $? -ne 0 ]
  495. #then
  496. #   echo "Could not create needed partitions! Please reboot and try it again!" 1>&2
  497. #   exit 1
  498. #fi
  499. sudo parted --script ${DEVICE_TARGET} mklabel gpt
  500. if [ $? -ne 0 ]
  501. then
  502.     echo "Could not create partition label! Please reboot and try it again!" 1>&2
  503.     exit 1
  504. fi
  505. sudo parted --script --align optimal ${DEVICE_TARGET} mkpart primary 0 ${SIZE_BOOT}
  506. if [ $? -ne 0 ]
  507. then
  508.     echo "Could not create first partition! Please reboot and try it again!" 1>&2
  509.     exit 1
  510. fi
  511. sudo parted --script --align optimal ${DEVICE_TARGET} mkpart primary ${SIZE_BOOT} 100%
  512. if [ $? -ne 0 ]
  513. then
  514.     echo "Could not create second partition! Please reboot and try it again!" 1>&2
  515.     exit 1
  516. fi
  517. echo "Done."
  518.  
  519. echo ""
  520. echo ""
  521. echo "###############################################################################"
  522. echo "# Target system: init encryption on '${DEVICE_TARGET}2'"
  523. echo "###############################################################################"
  524. echo "Please follow the instructions..."
  525. echo ""
  526. #XTS is supporting key size of 128 or 256bit. "--key-size 512" means, both
  527. #AES and XTS are using the maximum key size of 256bit. For slower systems
  528. #"--key-size 256" may be an option, resulting in a 128bit encryption.
  529. let LUKSKEYSIZE=${KEYSIZE}+${KEYSIZE}
  530. #using while loops because the user may enter long, complicated passwords...
  531. DO=1
  532. while [ $? -ne 0 ] ||
  533.       [ ${DO} -ne 0 ]
  534. do
  535.     DO=0
  536.     sudo cryptsetup --cipher aes-xts-plain --key-size ${LUKSKEYSIZE} --verify-passphrase luksFormat ${DEVICE_TARGET}2
  537. done
  538. echo "cryptsetup was succesful, crypto-device '${DEVICE_TARGET}2' was created."
  539. echo ""
  540. echo "Unlocking the freshly created crypto-device for the upcoming actions."
  541. echo "Therefore, please type your pwd."
  542. echo ""
  543. DO=1
  544. while [ $? -ne 0 ] ||
  545.       [ ${DO} -ne 0 ]
  546. do
  547.     DO=0
  548.     sudo cryptsetup luksOpen ${DEVICE_TARGET}2 lvm_crypt
  549. done
  550. unset DO
  551. echo ""
  552. echo "Done."
  553.  
  554. echo ""
  555. echo ""
  556. echo "###############################################################################"
  557. echo "# Target system: setup LVM (Logical Volume Manager) within '${DEVICE_TARGET}2'"
  558. echo "###############################################################################"
  559. sudo pvcreate /dev/mapper/lvm_crypt
  560. if [ $? -ne 0 ]
  561. then
  562.     echo "Could not create physical volume '/dev/mapper/lvm_crypt'! Please reboot and try it again!" 1>&2
  563.     exit 1
  564. fi
  565.  
  566. sudo vgcreate mint /dev/mapper/lvm_crypt
  567. if [ $? -ne 0 ]
  568. then
  569.     echo "Could not create volume group 'mint'! Please reboot and try it again!" 1>&2
  570.     exit 1
  571. fi
  572.  
  573. sudo lvcreate -L ${SIZE_SWAP}M -n swap mint
  574. if [ $? -ne 0 ]
  575. then
  576.     echo "Could not create logical volume 'swap' in volume group 'mint'! Please reboot and try it again!" 1>&2
  577.     exit 1
  578. fi
  579.  
  580. sudo lvcreate -L ${SIZE_ROOT}M -n root mint
  581. if [ $? -ne 0 ]
  582. then
  583.     echo "Could not create logical volume 'root' in volume group 'mint'! Please reboot and try it again!" 1>&2
  584.     exit 1
  585. fi
  586.  
  587. sudo lvcreate -l 100%FREE -n home mint
  588. if [ $? -ne 0 ]
  589. then
  590.     echo "Could not create logical volume 'home' in volume group 'mint'! Please reboot and try it again!" 1>&2
  591.     exit 1
  592. fi
  593. echo ""
  594. echo "Done."
  595.  
  596. echo ""
  597. echo ""
  598. echo "###############################################################################"
  599. echo "# Target system: preparing partitions to prevent problems with the installer"
  600. echo "###############################################################################"
  601. echo "NOTE: you can choose other filesystems later. These mkfs calls are just done to"
  602. echo "      prevent problems with the graphical Ubuntu installer."
  603. echo ""
  604. sudo mkswap /dev/mapper/mint-swap
  605. if [ $? -ne 0 ]
  606. then
  607.     echo "Could not create filesystem on '/dev/mapper/mint-swap'! Please reboot and try it again!" 1>&2
  608.     exit 1
  609. fi
  610. sudo mkfs.ext4 /dev/mapper/mint-root
  611. if [ $? -ne 0 ]
  612. then
  613.     echo "Could not create filesystem on '/dev/mapper/mint-root'! Please reboot and try it again!" 1>&2
  614.     exit 1
  615. fi
  616. sudo mkfs.ext4 /dev/mapper/mint-home
  617. if [ $? -ne 0 ]
  618. then
  619.     echo "Could not create filesystem on '/dev/mapper/mint-home'! Please reboot and try it again!" 1>&2
  620.     exit 1
  621. fi
  622. echo ""
  623. echo "Done."
  624.  
  625. clear
  626. echo "###############################################################################"
  627. echo "# LiveCD: starting the graphical installer"
  628. echo "###############################################################################"
  629. echo "The graphical Ubuntu installer will be launched now. Please follow the"
  630. echo "instructions the installer prints out (but do NOT reboot after installation was"
  631. echo "finished)."
  632. echo ""
  633. echo "You have to choose 'Something else' and make sure:"
  634. echo "- '${DEVICE_TARGET}1' is attached to the mount point '/boot'"
  635. echo "  and will be formatted as EXT3 (recommended) or EXT2"
  636. echo ""
  637. echo "- '/dev/mapper/mint-root' is attached to the mount point '/'"
  638. echo "  and will be formatted as EXT4 (recommended) or another fs you like"
  639. echo ""
  640. echo "- '/dev/mapper/mint-home' is attached to the mount point '/home'"
  641. echo "  and will be formatted as EXT4 (recommended) or another fs you like"
  642. echo ""
  643. echo "If you need a detailed description with screenshots, have a look at:"
  644. echo ${URL_ARTICLE}
  645. echo ""
  646. echo ""
  647. echo "ATTENTION: DO **NOT REBOOT** AFTER THE INSTALLATION HAS FINISHED! CHOOSE"
  648. echo "           'Continue tryout'!"
  649. read -sp "Press [Enter] to continue."
  650. echo ""
  651. echo ""
  652. echo "Starting the installer 'ubiquity'..."
  653. echo "NOTE: Do NOT close this window/terminal!"
  654. ubiquity --desktop %k gtk_ui > /dev/null 2>&1 #command copied from the properties of the GNOME starter on the Live CD's Desktop
  655. if [ $? -ne 0 ]
  656. then
  657.     echo ""
  658.     echo "ubiquity with GNOME UI exited with an error... maybe Kubuntu instead"
  659.     echo "of Ubuntu is running here. Let's try to start ubiquity with KDE interface."
  660.     echo ""
  661.     ubiquity kde_ui > /dev/null 2>&1 #command copied from the properties of the KDE starter on the Live CD's Desktop
  662.     if [ $? -ne 0 ]
  663.     then
  664.         echo "Installer exited with an error! Please reboot and try it again!" 1>&2
  665.         exit 1
  666.     fi
  667. fi
  668. echo ""
  669. sleep 2 #give system some time...
  670. echo "Done. Please wait a few seconds..."
  671. sleep 8 #give system some time...
  672.  
  673. echo ""
  674. echo ""
  675. echo "###############################################################################"
  676. echo "# Target system: post installation actions"
  677. echo "###############################################################################"
  678. echo "Installing the needed software into the freshly installed Ubuntu to get a"
  679. echo "bootable system"
  680. echo ""
  681. echo "NOTE: You can ignore Openpty()- and /etc/crypttab warnings as long as the"
  682. echo "      software was installed."
  683. echo ""
  684. sudo mount /dev/mapper/mint-root /mnt
  685. if [ $? -ne 0 ]
  686. then
  687.     echo "Could not mount: mount /dev/mapper/mint-root /mnt! Please reboot and try it again!" 1>&2
  688.     exit 1
  689. fi
  690.  
  691. sudo mount ${DEVICE_TARGET}1 /mnt/boot
  692. if [ $? -ne 0 ]
  693. then
  694.     echo "Could not mount: ${DEVICE_TARGET}1 /mnt/boot! Please reboot and try it again!" 1>&2
  695.     exit 1
  696. fi
  697.  
  698. sudo mount -o bind /dev /mnt/dev
  699. if [ $? -ne 0 ]
  700. then
  701.     echo "Could not mount: mount -o bind /dev /mnt/dev! Please reboot and try it again!" 1>&2
  702.     exit 1
  703. fi
  704.  
  705. sudo mount -t proc proc /mnt/proc
  706. if [ $? -ne 0 ]
  707. then
  708.     echo "Could not mount: mount -t proc proc /mnt/proc! Please reboot and try it again!" 1>&2
  709.     exit 1
  710. fi
  711.  
  712. sudo mount -t sysfs sys /mnt/sys
  713. if [ $? -ne 0 ]
  714. then
  715.     echo "Could not mount: mount -t sysfs sys /mnt/sys! Please reboot and try it again!" 1>&2
  716.     exit 1
  717. fi
  718.  
  719. sudo cp /etc/resolv.conf /mnt/etc/resolv.conf #not everyone got a router...
  720. if [ $? -ne 0 ]
  721. then
  722.     echo "Could not copy /etc/resolv.conf to /mnt/etc/resolv.conf! Please reboot and try it again!" 1>&2
  723.     exit 1
  724. fi
  725.  
  726. sudo chroot /mnt /bin/bash  << EOF
  727. apt-get install --yes cryptsetup lvm2
  728. echo "lvm_crypt UUID=$(ls -la /dev/disk/by-uuid | grep $(basename ${DEVICE_TARGET}2) | cut -d ' ' -f 9) none luks" >> /etc/crypttab
  729. update-initramfs -u -k all
  730. exit
  731. EOF
  732. if [ $? -ne 0 ]
  733. then
  734.     echo "Something regarding chroot failed! Please reboot and try it again!" 1>&2
  735.     exit 1
  736. fi
  737. echo ""
  738. echo "Success, work done :-)"
  739. read -sp "Press [Enter] to reboot now."
  740. echo ""
  741. sudo reboot
  742. exit 0