]> gitweb.fluxo.info Git - hydra.git/commitdiff
Feat: hydractl: provision: support for discards (TRIM)
authorSilvio Rhatto <rhatto@riseup.net>
Sat, 8 Jan 2022 13:32:37 +0000 (10:32 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Sat, 8 Jan 2022 13:32:37 +0000 (10:32 -0300)
share/hydractl/provision

index 9c4b32feefe3ff2ce2a2c737a69a8c018bd3174d..c3f46206f3611dd2e6e63537a5f0bbc728fe89a8 100755 (executable)
@@ -138,6 +138,7 @@ function hydra_provision_config {
   fi
 
   hydra_user_config   disable_zeroing   n                                "Disable zeroing of LVM volumes? (y/n)"
+  hydra_user_config   discards          n                                "Enable discards on volumes (TRIM etc)? (y/n)"
   hydra_user_config   hostname          machine                          "Hostname"
   hydra_user_config   domain            example.org                      "Domain"
   hydra_user_config   arch              $base_arch                       "System arch"
@@ -153,6 +154,11 @@ function hydra_provision_config {
     echo "You probably want to run provision-raspi instead of provision"
     exit 1
   fi
+
+  # Set discards config
+  if [ "$discards" == "y" ]; then
+    crypttab_discards=",discard"
+  fi
 }
 
 # Load configuration
@@ -444,19 +450,19 @@ echo "# <target name> <source device>   <key file>  <options>" | $SUDO tee $WORK
 
 if [ "$encrypt" == "y" ]; then
   cat <<-EOF | $SUDO tee $WORK/etc/crypttab > /dev/null
-root            /dev/mapper/$vg-root      none            luks
+root            /dev/mapper/$vg-root      none            luks$crypttab_discards
 EOF
 fi
 
 if [ "$home_size" != "0" ] && [ "$encrypt" == "y" ]; then
   cat <<-EOF | $SUDO tee -a $WORK/etc/crypttab > /dev/null
-home            /dev/mapper/$vg-home      none            luks
+home            /dev/mapper/$vg-home      none            luks$crypttab_discards
 EOF
 fi
 
 if [ "$var_size" != "0" ] && [ "$encrypt" == "y" ]; then
   cat <<-EOF | $SUDO tee -a $WORK/etc/crypttab > /dev/null
-var             /dev/mapper/$vg-var       none            luks
+var             /dev/mapper/$vg-var       none            luks$crypttab_discards
 EOF
 fi
 
@@ -516,6 +522,11 @@ EOF
   fi
 fi
 
+# LVM.
+if [ "$discards" == "y" ]; then
+  $SUDO sed -i -e 's/issue_discards = 0/issue_discards = 1' $WORK/etc/lvm/lvm.conf
+fi
+
 # Boot device must be available before installing kernel and initramfs.
 if [ "$grub" == "y" ] && [ "$encrypt" != "y" ]; then
   echo "Boot device setup..."