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.

Revisions

  1. nexus166 revised this gist Aug 31, 2020. 1 changed file with 17 additions and 0 deletions.
    17 changes: 17 additions & 0 deletions cryptpv.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    #!/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
  2. nexus166 created this gist Aug 27, 2020.
    11 changes: 11 additions & 0 deletions luks-lvm-notboot.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    ## LVM autoinit on boot for LUKS disk

    ```shell
    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
    ```