From 90df3c62aaefd464957e1d7dfabccb294e3a11f5 Mon Sep 17 00:00:00 2001 From: clerie Date: Sat, 2 Jul 2022 00:00:22 +0200 Subject: [PATCH] Add automatiion script for creating backup disks --- hosts/palladium/backup-scripts.nix | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/hosts/palladium/backup-scripts.nix b/hosts/palladium/backup-scripts.nix index 50364cc..b2a8f56 100644 --- a/hosts/palladium/backup-scripts.nix +++ b/hosts/palladium/backup-scripts.nix @@ -18,6 +18,24 @@ let ${pkgs.cryptsetup}/bin/cryptsetup luksClose external-drive ''; + cb-prepare = pkgs.writeScriptBin "cb-prepare" '' + echo "Formatting disk" + sgdisk -Z /dev/disk/by-path/pci-0000:00:12.0-ata-2 + sgdisk -N 1 /dev/disk/by-path/pci-0000:00:12.0-ata-2 + partprobe /dev/disk/by-path/pci-0000:00:12.0-ata-2 + + echo "Creating encrypted partition" + ${pkgs.cryptsetup}/bin/cryptsetup luksFormat -c aes-xts-plain64 --hash=sha256 -s 256 /dev/disk/by-path/pci-0000:00:12.0-ata-2-part1 + + echo "Opening encrypted partition" + ${pkgs.cryptsetup}/bin/cryptsetup luksOpen /dev/disk/by-path/pci-0000:00:12.0-ata-2-part1 external-drive + + echo "Creating file system" + mkfs.ext4 /dev/mapper/external-drive + + echo "Closing encrypted partition" + ${pkgs.cryptsetup}/bin/cryptsetup luksClose external-drive + ''; in { - environment.systemPackages = [ cb-mount cb-unmount ]; + environment.systemPackages = [ cb-mount cb-unmount cb-prepare ]; }