Skip to content

Instantly share code, notes, and snippets.

@nexus166
Last active February 11, 2021 08:35
Show Gist options
  • Save nexus166/cc962080201df2ac435632b2b793e3c9 to your computer and use it in GitHub Desktop.
Save nexus166/cc962080201df2ac435632b2b793e3c9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -xeuo pipefail
DISK="${1}"
_DISKNAME="$(basename "${DISK}")"
openssl rand 4096 >"${_DISKNAME}.key"
yes YES | cryptsetup luksFormat -d "${_DISKNAME}.key" "${DISK}" || true
cryptsetup luksOpen -d "${_DISKNAME}.key" "${DISK}" "${_DISKNAME}"
pvcreate "/dev/mapper/${_DISKNAME}"
vgcreate "${_DISKNAME}-vg" "/dev/mapper/${_DISKNAME}"
lvcreate -l 99%FREE -n "${_DISKNAME}-crypt" "${_DISKNAME}-vg"
printf '%s %s %s luks,discard,lvm=%s\n' "${_DISKNAME}" "${DISK}" "$(realpath "${_DISKNAME}".key)" "${_DISKNAME}" | tee -a /etc/crypttab

LVM autoinit on boot for LUKS disk

openssl rand 4096 > sdc.key
cryptsetup luksFormat -d sdc.key /dev/sdc
cryptsetup luksOpen -d sdc.key /dev/sdc sdc
pvcreate /dev/mapper/sdc 
vgcreate sdc-vg /dev/mapper/sdc
lvcreate -l 99%FREE -n sdc2T sdc-vg
printf 'sdc /dev/sdc /root/sdc.key luks,discard,lvm=sdc\n' >> /etc/crypttab
@nexus166
Copy link
Author

convert to thinpool for PVE

lvconvert --type thin-pool vgname/lvname

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment