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
|
@ -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; });
|
||||
}
|
||||
|
|
|
@ -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} <<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