l init: update with local tests, sgdisk, etc..
This commit is contained in:
parent
e1251ee299
commit
687ae7ca86
@ -61,7 +61,7 @@ in {
|
|||||||
pubkey = config.krebs.users.lass.pubkey;
|
pubkey = config.krebs.users.lass.pubkey;
|
||||||
};
|
};
|
||||||
in ''
|
in ''
|
||||||
alias ${initscript};
|
alias ${initscript}/bin/init;
|
||||||
'';
|
'';
|
||||||
locations."= /blue.pub".extraConfig = ''
|
locations."= /blue.pub".extraConfig = ''
|
||||||
alias ${pkgs.writeText "pub" config.krebs.users.lass.pubkey};
|
alias ${pkgs.writeText "pub" config.krebs.users.lass.pubkey};
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
pkgs.writeScript "init" ''
|
pkgs.writeScriptBin "init" ''
|
||||||
#!/usr/bin/env nix-shell
|
#!/usr/bin/env nix-shell
|
||||||
#! nix-shell -i bash -p jq parted libxfs
|
#! nix-shell -i bash -p cryptsetup gptfdisk jq libxfs
|
||||||
set -efu
|
set -xefuo pipefail
|
||||||
|
|
||||||
disk=$1
|
disk=$1
|
||||||
|
|
||||||
@ -14,12 +14,12 @@ pkgs.writeScript "init" ''
|
|||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
bootdev="$disk"2
|
||||||
luksdev="$disk"3
|
luksdev="$disk"3
|
||||||
luksmap=/dev/mapper/${luksmap}
|
luksmap=/dev/mapper/${luksmap}
|
||||||
|
|
||||||
vgname=${vgname}
|
vgname=${vgname}
|
||||||
|
|
||||||
bootdev=/dev/sda2
|
|
||||||
|
|
||||||
rootdev=/dev/mapper/${vgname}-root
|
rootdev=/dev/mapper/${vgname}-root
|
||||||
homedev=/dev/mapper/${vgname}-home
|
homedev=/dev/mapper/${vgname}-home
|
||||||
@ -35,15 +35,13 @@ pkgs.writeScript "init" ''
|
|||||||
# dd if=/dev/zero bs=512 count=34 of=/dev/sda
|
# dd if=/dev/zero bs=512 count=34 of=/dev/sda
|
||||||
# TODO zero last 34 blocks (lsblk -bno SIZE /dev/sda)
|
# TODO zero last 34 blocks (lsblk -bno SIZE /dev/sda)
|
||||||
if ! test "$(blkid -o value -s PTTYPE "$disk")" = gpt; then
|
if ! test "$(blkid -o value -s PTTYPE "$disk")" = gpt; then
|
||||||
parted -s -a optimal "$disk" \
|
sgdisk -og "$disk"
|
||||||
mklabel gpt \
|
sgdisk -n 1:2048:4095 -c 1:"BIOS Boot Partition" -t 1:ef02 "$disk"
|
||||||
mkpart no-fs 0 1024KiB \
|
sgdisk -n 2:4096:+1G -c 2:"EFI System Partition" -t 2:ef00 "$disk"
|
||||||
set 1 bios_grub on \
|
sgdisk -n 3:0:0 -c 3:"LUKS container" -t 3:8300 "$disk"
|
||||||
mkpart ESP fat32 1025KiB 1024MiB set 2 boot on \
|
|
||||||
mkpart primary 1025MiB 100%
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! test "$(blkid -o value -s PARTLABEL "$luksdev")" = primary; then
|
if ! test "$(blkid -o value -s PARTLABEL "$luksdev")" = "LUKS container"; then
|
||||||
echo zonk2
|
echo zonk2
|
||||||
exit 23
|
exit 23
|
||||||
fi
|
fi
|
||||||
@ -58,7 +56,6 @@ pkgs.writeScript "init" ''
|
|||||||
if ! test -e "$luksmap"; then
|
if ! test -e "$luksmap"; then
|
||||||
echo "$lukspw" | cryptsetup luksOpen "$luksdev" "$(basename "$luksmap")" -
|
echo "$lukspw" | cryptsetup luksOpen "$luksdev" "$(basename "$luksmap")" -
|
||||||
fi
|
fi
|
||||||
# cryptsetup close
|
|
||||||
|
|
||||||
if ! test "$(blkid -o value -s TYPE "$luksmap")" = LVM2_member; then
|
if ! test "$(blkid -o value -s TYPE "$luksmap")" = LVM2_member; then
|
||||||
pvcreate "$luksmap"
|
pvcreate "$luksmap"
|
||||||
@ -68,11 +65,7 @@ pkgs.writeScript "init" ''
|
|||||||
|
|
||||||
lvchange -a y /dev/mapper/"$vgname"
|
lvchange -a y /dev/mapper/"$vgname"
|
||||||
|
|
||||||
if ! test -e "$rootdev"; then lvcreate -L 7G -n root "$vgname"; fi
|
if ! test -e "$rootdev"; then lvcreate -L 3G -n root "$vgname"; fi
|
||||||
if ! test -e "$homedev"; then lvcreate -L 100M -n home "$vgname"; fi
|
|
||||||
|
|
||||||
# lvchange -a n "$vgname"
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# formatting
|
# formatting
|
||||||
@ -82,35 +75,23 @@ pkgs.writeScript "init" ''
|
|||||||
mkfs.vfat "$bootdev"
|
mkfs.vfat "$bootdev"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! test "$(blkid -o value -s TYPE "$rootdev")" = btrfs; then
|
if ! test "$(blkid -o value -s TYPE "$rootdev")" = xfs; then
|
||||||
mkfs.xfs "$rootdev"
|
mkfs.xfs "$rootdev"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! test "$(blkid -o value -s TYPE "$homedev")" = btrfs; then
|
|
||||||
mkfs.xfs "$homedev"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
if ! test "$(lsblk -n -o MOUNTPOINT "$rootdev")" = /mnt; then
|
if ! test "$(lsblk -n -o MOUNTPOINT "$rootdev")" = /mnt; then
|
||||||
|
mkdir -p /mnt
|
||||||
mount "$rootdev" /mnt
|
mount "$rootdev" /mnt
|
||||||
fi
|
fi
|
||||||
if ! test "$(lsblk -n -o MOUNTPOINT "$bootdev")" = /mnt/boot; then
|
if ! test "$(lsblk -n -o MOUNTPOINT "$bootdev")" = /mnt/boot; then
|
||||||
mkdir -m 0000 -p /mnt/boot
|
mkdir -m 0000 -p /mnt/boot
|
||||||
mount "$bootdev" /mnt/boot
|
mount "$bootdev" /mnt/boot
|
||||||
fi
|
fi
|
||||||
if ! test "$(lsblk -n -o MOUNTPOINT "$homedev")" = /mnt/home; then
|
|
||||||
mkdir -m 0000 -p /mnt/home
|
|
||||||
mount "$homedev" /mnt/home
|
|
||||||
fi
|
|
||||||
|
|
||||||
# umount -R /mnt
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# dependencies for stockholm
|
# dependencies for stockholm
|
||||||
#
|
#
|
||||||
|
|
||||||
nix-env -iA nixos.git
|
|
||||||
|
|
||||||
# TODO: get sentinal file from target_path
|
# TODO: get sentinal file from target_path
|
||||||
mkdir -p /mnt/var/src
|
mkdir -p /mnt/var/src
|
||||||
touch /mnt/var/src/.populate
|
touch /mnt/var/src/.populate
|
||||||
@ -119,7 +100,7 @@ pkgs.writeScript "init" ''
|
|||||||
# print all the infos
|
# print all the infos
|
||||||
#
|
#
|
||||||
|
|
||||||
parted "$disk" print
|
gdisk -l "$disk"
|
||||||
lsblk "$disk"
|
lsblk "$disk"
|
||||||
|
|
||||||
echo READY.
|
echo READY.
|
||||||
|
7
lass/5pkgs/init/run-vm.sh
Executable file
7
lass/5pkgs/init/run-vm.sh
Executable file
@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env nix-shell
|
||||||
|
#! nix-shell -i bash -p nixos-generators
|
||||||
|
|
||||||
|
set -efu
|
||||||
|
|
||||||
|
WD=$(dirname "$0")
|
||||||
|
nixos-generate -I stockholm="$WD"/../../.. -c "$WD"/config.nix -f vm-nogui --run
|
13
lass/5pkgs/init/test.nix
Normal file
13
lass/5pkgs/init/test.nix
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
{
|
||||||
|
virtualisation.emptyDiskImages = [
|
||||||
|
8000
|
||||||
|
];
|
||||||
|
virtualisation.memorySize = 1500;
|
||||||
|
boot.tmpOnTmpfs = true;
|
||||||
|
|
||||||
|
environment.systemPackages = [
|
||||||
|
(pkgs.callPackage ./default.nix {})
|
||||||
|
];
|
||||||
|
services.mingetty.autologinUser = lib.mkForce "root";
|
||||||
|
}
|
11
lass/5pkgs/init/test.sh
Executable file
11
lass/5pkgs/init/test.sh
Executable file
@ -0,0 +1,11 @@
|
|||||||
|
#!/usr/bin/env nix-shell
|
||||||
|
#! nix-shell -i bash -p nixos-generators
|
||||||
|
|
||||||
|
set -xefu
|
||||||
|
|
||||||
|
WD=$(realpath $(dirname "$0"))
|
||||||
|
TMPDIR=$(mktemp -d)
|
||||||
|
cd "$TMPDIR"
|
||||||
|
nixos-generate -c "$WD"/test.nix -f vm-nogui --run "$@"
|
||||||
|
cd -
|
||||||
|
rm -r "$TMPDIR"
|
Loading…
Reference in New Issue
Block a user