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.
This commit is contained in:
parent
e9464dfbe7
commit
4f26e935ee
3 changed files with 52 additions and 1 deletions
3
Justfile
3
Justfile
|
@ -94,6 +94,9 @@ hm-iterate-qtile:
|
||||||
disk-prepare dir:
|
disk-prepare dir:
|
||||||
just -v _device diskPrepare {{dir}} --argstr rebuildarg "dummy"
|
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'
|
# 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:
|
disk-mount dir:
|
||||||
just -v _device diskMount {{dir}} --argstr rebuildarg "dummy"
|
just -v _device diskMount {{dir}} --argstr rebuildarg "dummy"
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
, moreargs ? ""
|
, moreargs ? ""
|
||||||
, diskId ? (import ((builtins.getEnv "PWD")+"/${dir}/hw.nix") {}).hardware.encryptedDisk.diskId
|
, diskId ? (import ((builtins.getEnv "PWD")+"/${dir}/hw.nix") {}).hardware.encryptedDisk.diskId
|
||||||
, gitRoot ? "$(git rev-parse --show-toplevel)"
|
, gitRoot ? "$(git rev-parse --show-toplevel)"
|
||||||
|
, previousDiskId ? ""
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
|
@ -35,5 +36,5 @@ let
|
||||||
in {
|
in {
|
||||||
recipes = {
|
recipes = {
|
||||||
inherit rebuild;
|
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; });
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
, moreargs
|
, moreargs
|
||||||
, diskId
|
, diskId
|
||||||
, gitRoot
|
, gitRoot
|
||||||
|
, previousDiskId ? ""
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
|
@ -117,4 +118,50 @@ in rec {
|
||||||
|
|
||||||
${diskUmount}
|
${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} <<EOF
|
||||||
|
x
|
||||||
|
n
|
||||||
|
2
|
||||||
|
2-${diskId}
|
||||||
|
n
|
||||||
|
3
|
||||||
|
3-${diskId}
|
||||||
|
r
|
||||||
|
i
|
||||||
|
2
|
||||||
|
i
|
||||||
|
3
|
||||||
|
w
|
||||||
|
EOF
|
||||||
|
} || {
|
||||||
|
sync
|
||||||
|
sudo partprobe ${ownLib.disk.bootGrubDevice diskId}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if test "${previousDiskId}"; then
|
||||||
|
sudo cryptsetup luksOpen ${ownLib.disk.bootLuksDevice diskId} ${ownLib.disk.luksName diskId}
|
||||||
|
sync
|
||||||
|
sleep 1
|
||||||
|
if sudo vgs ${previousDiskId}; then
|
||||||
|
sudo vgrename ${previousDiskId} ${diskId}
|
||||||
|
sudo vgscan
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
sudo cryptsetup close ${ownLib.disk.luksName diskId}
|
||||||
|
'';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue