From 0ef6b324402d1c114e3d1bde9498499530a290d3 Mon Sep 17 00:00:00 2001 From: Jens Nolte <git@queezle.net> Date: Wed, 12 Jan 2022 02:58:33 +0100 Subject: [PATCH] Add allwinner sbc installation script --- bin/install-sd-allwinner | 100 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100755 bin/install-sd-allwinner diff --git a/bin/install-sd-allwinner b/bin/install-sd-allwinner new file mode 100755 index 0000000..7cd4c53 --- /dev/null +++ b/bin/install-sd-allwinner @@ -0,0 +1,100 @@ +#!/usr/bin/env zsh + +set -e +set -u +set -x +set -o pipefail + +source $DOTFILES_PATH/bin/lib/util.zsh + +cmdname=$(basename $0) +usage() { + print "Usage: $cmdname <machine>" >&2 +} +readonly machine="$1" + +# Update nar-hash of dotfiles repository +nix flake lock --update-input dotfiles "path:$MACHINES_PATH" + +readonly nix=(nix --log-format bar-with-logs) + +# Installables +readonly uboot_installable="path:$MACHINES_PATH#nixosConfigurations.$machine.config.system.build.u-boot" +readonly system_installable="path:$MACHINES_PATH#nixosConfigurations.$machine.config.system.build.toplevel" + +# Build once to catch errors +$nix build --no-link $uboot_installable +$nix build --keep-going --no-link $system_installable + + +# Use cached build to get output path +readonly nixos_config_path=$($nix build --json --no-link $system_installable | jq --raw-output ".[0].outputs.out") + + +# NOTE: Update if required +readonly target_disk="/dev/disk/by-id/usb-Generic_MassStorageClass_000000001538-0:1" + +# NOTE: Update for each new installation +readonly root_partition_uuid="184a74e1-894b-4319-b9c9-9b0f972a30f8" + +# NOTE: Update for each new installation +readonly root_uuid="dec6d7a8-6f97-4f4e-aaeb-98fd1e6bda27" + + +# Derived paths +readonly root_partition="/dev/disk/by-partuuid/$root_partition_uuid" + + +sudo wipefs -a $target_disk + +# 2MB header hole +sudo nix shell nixpkgs#vboot_reference -c cgpt create -p 4096 $(realpath $target_disk) +sudo nix shell nixpkgs#vboot_reference -c cgpt boot -p $(realpath $target_disk) + +sudo nix shell nixpkgs#util-linux -c sfdisk $target_disk --append <<EOF + unit: sectors + sector-size: 512 + + start=4224, type=69dad710-2ce4-4e3c-b16c-21a1d49abed3, uuid=$root_partition_uuid, name="root" +EOF + + +nix shell nixpkgs#busybox -c partprobe + +# Use cached build to get u-boot output path +readonly uboot=$($nix build --json --no-link $uboot_installable | jq --raw-output ".[0].outputs.out") + +#sudo dd if=$uboot/u-boot-sunxi-with-spl.bin of=$uboot_partition bs=16M conv=fsync oflag=direct status=progress +sudo dd if=$uboot/u-boot-sunxi-with-spl.bin of=$target_disk bs=1024 seek=8 conv=fsync status=progress + + +sudo wipefs -a $root_partition + +# partprobe doesn't seem to be enough for symlinks to appear? +while [[ ! -b $root_partition ]] { + print "Waiting for $root_partition" + sleep 1s +} +sudo mkfs.ext4 -U $root_uuid -L root_$machine $root_partition + +mount_point=/mnt/mnt +sudo mount $root_partition $mount_point + +sudo $nix copy --no-check-sigs --to "$mount_point" $nixos_config_path + +print "Setting system profile" +sudo nix-env --store $mount_point --profile $mount_point/nix/var/nix/profiles/system --set $nixos_config_path + +print "Creating /etc/NIXOS" +sudo mkdir -m 0755 -p "$mount_point/etc" +sudo touch "$mount_point/etc/NIXOS" + +# Bootloader installation: broken when installing across architectures +#sudo nixos-enter --root $mount_point -c "NIXOS_INSTALL_BOOTLOADER=1 $nixos_config_path/bin/switch-to-configuration boot" + +# Manual steps: +# - open switch-to-configuration script +# - look for "Install or update the bootloader." +# - run extlinux-conf-builder.sh: +# /nix/store/[...]-extlinux-conf-builder.sh -d /mnt/mnt/boot -c $nixos_config_path -t 5 +sync -- GitLab