setup-usl-mm 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. #!/bin/bash
  2. pre_reboot_script () {
  3. pass_var=$(dialog --passwordbox "Enter password to crypted partition for containers:" 25 25 --output-fd 1)
  4. pass_var2=$(dialog --passwordbox "Enter password to crypted partition for containers again:" 25 25 --output-fd 1)
  5. if [ "$pass_var" == "$pass_var2" ]; then
  6. echo "Passwords match!"
  7. else
  8. echo "Passwords not match!"
  9. exit 1
  10. fi
  11. echo "Install net-tools"
  12. apt install net-tools -y
  13. echo "Exec ifconfig"
  14. ifconfig
  15. read -p "Enter interface for configure bridge:" NET_IF
  16. echo "Starting lsblk"
  17. lsblk
  18. read -p "Enter partition to encrypt:" PARTITION
  19. echo "Installing requirements"
  20. apt install cryptsetup ecryptfs-utils zfsutils-linux lzop -y
  21. echo "Setting timezone to Prague"
  22. timedatectl set-timezone Europe/Prague
  23. echo "Starting ecryptfs-setup-swap"
  24. ecryptfs-setup-swap -f
  25. echo "Starting luksFormat"
  26. echo -n "$pass_var" | cryptsetup luksFormat $PARTITION -
  27. echo "Opening crypted partition"
  28. echo "$pass_var" | cryptsetup open $PARTITION crypt -c -
  29. echo "Creating zpool"
  30. zpool create crypt /dev/mapper/crypt -o ashift=12
  31. echo "Enabling compression on zpool"
  32. zfs set compression=on crypt
  33. echo "Creating datasets crypt/lxd/dir crypt/lxd/storage"
  34. zfs create crypt/lxd
  35. zfs create crypt/lxd/dir
  36. zfs create crypt/lxd/storage
  37. echo "Switch to 6.1 LXD version"
  38. snap switch --channel 6.1/stable lxd
  39. snap refresh
  40. echo "Disabling lxd snap"
  41. snap disable lxd
  42. echo "Deleting everything in /var/snap/lxd/common/lxd/*"
  43. rm /var/snap/lxd/common/lxd/* -r
  44. echo "Creating mountpoint /var/snap/lxd/common/lxd to crypt/lxd/dir"
  45. zfs set mountpoint=/var/snap/lxd/common/lxd crypt/lxd/dir
  46. echo "Configuring sysctl"
  47. echo "vm.swappiness = 1" > /etc/sysctl.d/50-usl-mm.conf
  48. echo "vm.min_free_kbytes = 131072" >> /etc/sysctl.d/50-usl-mm.conf
  49. echo "vm.dirty_background_ratio = 5" >> /etc/sysctl.d/50-usl-mm.conf
  50. echo "fs.inotify.max_queued_events = 1048576" >> /etc/sysctl.d/50-usl-mm.conf
  51. echo "fs.inotify.max_user_instances = 1048576" >> /etc/sysctl.d/50-usl-mm.conf
  52. echo "fs.inotify.max_user_watches = 1048576" >> /etc/sysctl.d/50-usl-mm.conf
  53. echo "kernel.dmesg_restrict = 1" >> /etc/sysctl.d/50-usl-mm.conf
  54. echo "net.netfilter.nf_conntrack_max = 4194304" >> /etc/sysctl.d/50-usl-mm.conf
  55. #Ugly fix
  56. echo "@reboot root /sbin/sysctl -w net.netfilter.nf_conntrack_max=4194304" > /etc/cron.d/conntrack_cron
  57. echo "Configuring arc cache for zfs to min 256MB and max 1536MB + txg_timeout to 3"
  58. echo "options zfs zfs_arc_min=268435456" > /etc/modprobe.d/zfs.conf
  59. echo "options zfs zfs_arc_max=1610612736" >> /etc/modprobe.d/zfs.conf
  60. echo "options zfs zfs_txg_timeout=3" >> /etc/modprobe.d/zfs.conf
  61. echo "Doing update-initramfs -u"
  62. update-initramfs -u
  63. echo "Configuring network to use bridge"
  64. echo "auto lo" > /etc/network/interfaces
  65. echo "iface lo inet loopback" >> /etc/network/interfaces
  66. echo " " >> /etc/network/interfaces
  67. echo "iface $NET_IF inet manual" >> /etc/network/interfaces
  68. echo "iface $NET_IF inet6 manual" >> /etc/network/interfaces
  69. echo "auto br0" >> /etc/network/interfaces
  70. echo "iface br0 inet dhcp" >> /etc/network/interfaces
  71. echo " bridge_ports $NET_IF" >> /etc/network/interfaces
  72. echo " bridge_stp off" >> /etc/network/interfaces
  73. echo " bridge_fd 0" >> /etc/network/interfaces
  74. echo " " >> /etc/network/interfaces
  75. echo "iface br0 inet6 auto" >> /etc/network/interfaces
  76. echo " bridge_ports $NET_IF" >> /etc/network/interfaces
  77. echo " bridge_stp off" >> /etc/network/interfaces
  78. echo " bridge_fd 0" >> /etc/network/interfaces
  79. echo "Add DNS to systemd-resolved"
  80. echo "[Resolve]" > /etc/systemd/resolved.conf
  81. echo "DNS=8.8.8.8" >> /etc/systemd/resolved.conf
  82. echo "FallbackDNS=1.1.1.1" >> /etc/systemd/resolved.conf
  83. echo "Purging netplan,disabling dhcpcd and install ifupdown"
  84. apt purge nplan netplan.io -y
  85. rm /etc/netplan/* -f
  86. apt install bridge-utils ifupdown -y
  87. echo "Disabling systemd-networkd-wait-online"
  88. systemctl disable systemd-networkd-wait-online
  89. echo "Doing apt update and apt dist-upgrade"
  90. apt update
  91. apt dist-upgrade -y
  92. echo "Creating onstart script in /root"
  93. echo "#!/bin/bash" > /root/onstart
  94. echo "read -p \"Press any button to start...\"" >> /root/onstart
  95. echo "pass_var=\$(dialog --passwordbox \"Enter password:\" 25 25 --output-fd 1)" >> /root/onstart
  96. echo "pass_var2=\$(dialog --passwordbox \"Enter password again:\" 25 25 --output-fd 1)" >> /root/onstart
  97. echo "if [ \"\$pass_var\" == \"\$pass_var2\" ]; then" >> /root/onstart
  98. echo "echo \"Passwords match!\"" >> /root/onstart
  99. echo "else" >> /root/onstart
  100. echo "echo \"Passwords not match!\"" >> /root/onstart
  101. echo "exit 1" >> /root/onstart
  102. echo "fi" >> /root/onstart
  103. echo "echo \"Stopping LXD snap daemon and deleting /var/snap/lxd/common/lxd/*\"" >> /root/onstart
  104. echo "snap disable lxd" >> /root/onstart
  105. echo "rm /var/snap/lxd/common/lxd/* -rf" >> /root/onstart
  106. echo "echo \"Opening encrypted partition\"" >> /root/onstart
  107. echo "echo \$pass_var | cryptsetup open $PARTITION crypt -c -" >> /root/onstart
  108. echo "partprobe" >> /root/onstart
  109. echo "zpool import -d /dev/mapper crypt -f -m" >> /root/onstart
  110. echo "snap enable lxd" >> /root/onstart
  111. chmod +x /root/onstart
  112. read -p "Press any key for reboot"
  113. reboot
  114. }
  115. post_reboot_script () {
  116. echo "Disabling lxd and delete /var/snap/lxd/common/lxd/*"
  117. snap disable lxd
  118. rm /var/snap/lxd/common/lxd/* -r
  119. echo "Executing /root/onstart"
  120. bash /root/onstart
  121. echo "Configuring LXD"
  122. lxd waitready
  123. cat <<EOF | lxd init
  124. no
  125. yes
  126. storage
  127. zfs
  128. no
  129. crypt/lxd/storage
  130. no
  131. yes
  132. lxdbr0
  133. 10.10.10.1/24
  134. yes
  135. none
  136. no
  137. no
  138. no
  139. EOF
  140. echo "Set screen settings"
  141. echo "startup_message off" >> /root/.screenrc
  142. echo "screen -t htop htop" >> /root/.screenrc
  143. echo "screen -t mc mc" >> /root/.screenrc
  144. echo "screen -t bash bash" >> /root/.screenrc
  145. echo "altscreen on" >> /root/.screenrc
  146. echo "term screen-256color" >> /root/.screenrc
  147. echo "bind 'b' prev" >> /root/.screenrc
  148. echo "bind 'n' next" >> /root/.screenrc
  149. echo "hardstatus alwayslastline" >> /root/.screenrc
  150. echo "autodetach on" >> /root/.screenrc
  151. echo "mousetrack on" >> /root/.screenrc
  152. echo "vbell off" >> /root/.screenrc
  153. echo "termcapinfo xterm* ti@:te@" >> /root/.screenrc
  154. echo "defscrollback 5000" >> /root/.screenrc
  155. echo "scrollback 5000" >> /root/.screenrc
  156. echo "hardstatus string \"%{=b kw} %?%-Lw%?%{=br kw}[%n %t]%{=b kw}%?%+Lw%? %= %c\"" >> /root/.screenrc
  157. echo "Install utilities"
  158. apt install -y mc htop screen zfsnap smartmontools pv
  159. echo "Setting-up wireguard"
  160. apt update
  161. apt install wireguard -y
  162. lxc profile set default linux.kernel_modules wireguard
  163. echo "Set max processes to 3000 in default profile in LXD"
  164. lxc profile set default limits.processes 3000
  165. echo "Set refresh.retain=2 in snap"
  166. snap set system refresh.retain=2
  167. read -p "Done, press any key to return to main menu"
  168. main_menu
  169. }
  170. install_uptrack () {
  171. cd /tmp
  172. wget https://ksplice.oracle.com/uptrack/dist/focal/uptrack.deb
  173. apt install python3-pycurl libgtk2-perl dbus-x11 libglade2-0 libpython2-stdlib libpython2.7-minimal libpython2.7-stdlib python2 python-cairo python-dbus python-gi python-gobject-2 python2-minimal python-pycurl python-yaml python2.7 python2.7-minimal -y
  174. dpkg -i uptrack.deb
  175. uptrack-upgrade -y
  176. apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 82562EA9AD986DA3
  177. read -p "Done, press any key to return to main menu"
  178. main_menu
  179. }
  180. main_menu () {
  181. cmd=(dialog --nocancel --menu "Welcome in setup-lxd-mm!" 22 76 16)
  182. options=(
  183. 1 "Pre-reboot script"
  184. 2 "Post-reboot script"
  185. 3 "Install uptrack-upgrade"
  186. )
  187. choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
  188. for choice in $choices
  189. do
  190. case $choice in
  191. 1)
  192. pre_reboot_script
  193. ;;
  194. 2)
  195. post_reboot_script
  196. ;;
  197. 3)
  198. install_uptrack
  199. ;;
  200. esac
  201. done
  202. clear
  203. }
  204. main_menu