mirror of
https://gitea.com/mcereda/oam.git
synced 2026-02-09 05:44:23 +00:00
Improved script to create a crypted btrfs device
This commit is contained in:
@@ -4,13 +4,22 @@
|
||||
: ${LABEL:?not set}
|
||||
|
||||
: "${MOUNT_OPTIONS:=compress-force=zstd}"
|
||||
: "${MOUNT_POINT:=/mnt/$LABEL}"
|
||||
|
||||
[[ $EUID -eq 0 ]] || (echo "Please rerun this script with root privileges" && exit 1)
|
||||
[[ -f "$DEVICE" ]] || echo "${DEVICE} not found"
|
||||
|
||||
cryptsetup luksFormat "$DEVICE"
|
||||
cryptsetup luksOpen "$DEVICE" "$LABEL"
|
||||
cryptsetup open "$DEVICE" "$LABEL"
|
||||
|
||||
mkfs.btrfs --label "$LABEL" "/dev/mapper/${LABEL}"
|
||||
mount --types btrfs --options "$MOUNT_OPTIONS" "/dev/mapper/${LABEL}" "/mnt/${LABEL}"
|
||||
mkdir -p "$MOUNT_POINT"
|
||||
mount -t btrfs -o "$MOUNT_OPTIONS" "/dev/mapper/${LABEL}" "$MOUNT_POINT"
|
||||
|
||||
btrfs subvolume create "$MOUNT_POINT/.snapshots"
|
||||
btrfs subvolume create "$MOUNT_POINT/data"
|
||||
|
||||
chown "$USER":"$USER" "$MOUNT_POINT/data"
|
||||
|
||||
umount "/mnt/${LABEL}"
|
||||
cryptsetup luksClose "$DEVICE"
|
||||
cryptsetup close "$DEVICE"
|
||||
|
||||
Reference in New Issue
Block a user