Skip to content

Instantly share code, notes, and snippets.

@deadjakk
Created January 27, 2021 04:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deadjakk/c98ee2ffa5f55b204db07598b45393db to your computer and use it in GitHub Desktop.
Save deadjakk/c98ee2ffa5f55b204db07598b45393db to your computer and use it in GitHub Desktop.
Quick script to create an encrypted luks container, create a zfs pool for it along with a mount point, add a new user, then write the crypttab line for boot
#!/bin/bash
echo "enter username:"
read USERNAME
echo "enter # of gigabytes the home drive should be, just the number"
read SIZE
echo "Executing:" "sudo dd if=/dev/null of=/$USERNAME.img count=0 seek=${SIZE}G"
cd /
sudo adduser $USERNAME
sudo rm -rf /home/${USERNAME} # removing the home directory it created
sudo dd if=/dev/null of=/$USERNAME.img count=0 seek=${SIZE}G
sudo cryptsetup luksFormat /$USERNAME.img
echo "dont screw this up, i did not do any checking..."
sudo cryptsetup luksOpen /$USERNAME.img $USERNAME
sudo zpool create -o ashift=12 -O normalization=formD -O atime=off -m none -R /home/$USERNAME -O compression=lz4 ${USERNAME}tank /dev/mapper/$USERNAME
sudo zfs create -o mountpoint=/home/$USERNAME ${USERNAME}tank/HOME
sudo chown $USERNAME:$USERNAME -R /home/$USERNAME
sudo echo $USERNAME /$USERNAME.img none luks,timeout=120,tries=5 >> /etc/crypttab
echo "reboot and see if the new dataset is mounted, if not it might have created /home/$USERNAME which would block the new mount"
echo "if this is the case, then delete the directory it created and then run zpool import ${USERNAME}tank && zfs mount -a "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment