From 4f26e935ee36ddccdf67e8450b57f8e461eabe89 Mon Sep 17 00:00:00 2001 From: Stefan Junker Date: Sat, 12 Jan 2019 22:24:30 +0100 Subject: [PATCH] nix/os/devices: add relabel command After bytewise-copying from a prevoius disk, the partition labels and logical volume groupnames need to be renamed according to the new disk id. --- Justfile | 3 +++ nix/os/devices/default.nix | 3 ++- nix/os/devices/disk.nix | 47 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/Justfile b/Justfile index 189ef4c..8651c3d 100755 --- a/Justfile +++ b/Justfile @@ -94,6 +94,9 @@ hm-iterate-qtile: disk-prepare dir: just -v _device diskPrepare {{dir}} --argstr rebuildarg "dummy" +disk-relabel dir previous: + just -v _device diskRelabel {{dir}} --argstr rebuildarg "dummy" --argstr previousDiskId {{previous}} + # Mount the target disk specified by device configuration directory. The 'dir' argument points to a device configuration, e.g. 'nix/os/devices/steveej-live-mmc-SL32G_0x259093f6' disk-mount dir: just -v _device diskMount {{dir}} --argstr rebuildarg "dummy" diff --git a/nix/os/devices/default.nix b/nix/os/devices/default.nix index b361188..932f730 100644 --- a/nix/os/devices/default.nix +++ b/nix/os/devices/default.nix @@ -5,6 +5,7 @@ , moreargs ? "" , diskId ? (import ((builtins.getEnv "PWD")+"/${dir}/hw.nix") {}).hardware.encryptedDisk.diskId , gitRoot ? "$(git rev-parse --show-toplevel)" +, previousDiskId ? "" }: let @@ -35,5 +36,5 @@ let in { recipes = { inherit rebuild; - } // (import ./disk.nix { inherit pkgs ownLib dir rebuildarg moreargs diskId gitRoot; }); + } // (import ./disk.nix { inherit pkgs ownLib dir rebuildarg moreargs diskId gitRoot previousDiskId; }); } diff --git a/nix/os/devices/disk.nix b/nix/os/devices/disk.nix index 4490311..6b012d8 100644 --- a/nix/os/devices/disk.nix +++ b/nix/os/devices/disk.nix @@ -5,6 +5,7 @@ , moreargs , diskId , gitRoot +, previousDiskId ? "" }: let @@ -117,4 +118,50 @@ in rec { ${diskUmount} ''; + + diskRelabel = pkgs.writeScript "script" '' + #!/usr/bin/env bash + set -xe + + read -p "Continue to relabel ${ownLib.disk.bootGrubDevice diskId} (YES/n)?" choice + case "$choice" in + YES ) echo "Continuing in 3 seconds..."; sleep 3;; + n|N ) echo "Exiting..."; exit 0;; + * ) echo "Exiting..."; exit 1;; + esac + + sync + { + sudo fdisk ${ownLib.disk.bootGrubDevice diskId} <