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:
steveej 2019-01-12 22:24:30 +01:00
parent e9464dfbe7
commit 4f26e935ee
3 changed files with 52 additions and 1 deletions

View file

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