How to write Live usb with extra data partition?

I’d like to dd a nixos.iso to a partition(10GB) on a thumb-drive(32GB) and have an other ext4 partition(22GB) for data.

I’ve tried a few different thing but everytime it’s unbootable. The cursor keeps flickering top left during boot.

  dd if=/dev/zero of=/dev/sdc bs=512 count=1
  parted /dev/sdc rm 2
  parted /dev/sdc rm 1
  parted /dev/sdc mklabel msdos
  parted /dev/sdc 'unit GB mkpart primary 20.8 30.8'
  parted /dev/sdc 'unit GB mkpart primary 0 20.8'
  parted /dev/sdc set 1 boot on
  dd bs=4M if=nixos.iso of=/dev/sdc1 status=progress oflag=sync
  isohybrid --partok nixos.iso

My desired usecase(short-version):
Thumb-drive:

  • partition_x: custom build nixos iso (nix build .#nixosConfigurations.iso.config.system.build.isoImage)
  • partition_y: data luks+ext4
    – nixcfg: my nixos-config flake (mostly based on chvp’s config)
    – ssh keys extracted from newly installed host (/etc/ssh/ssh_host_ed25519_key.pub ${HOME}/.ssh/id_ed25519.pub) needed for agenix

  1. Insert thumb-drive in new pc and boot

  2. Run “setup-nixos-native-encrypted-zfs-boot.sh” (included in live iso)
    – select_boot_drives
    – drive_prep
    – partition_drive
    – zpool_create
    – configure_and_mount_partitions
    – copy_nixcfg
    – generate_boot_loader_nix
    – generate_hardware_configuration_nix
    – nixos-install --flake “/mnt/somepath/nixcfg#${selected_hostname}” --root /mnt --no-channel-copy --no-root-passwd --impure
    – installation_complete

  3. Currently I extract the ssh keys from the new host after a reboot using a thumbdrive. I hope to extract them to the partition_y during the installation_complete step.

  4. On my main machine: Mount thumb-drive and add the extracted ssh keys to nixcfg’s agenix

  5. nixos-rebuild --switch

  6. nixos-rebuild --switch remote (after this step the local nixcfg can be removed)

  7. On my main machine: Enable agenix for the new host in nixcfg

  8. nixos-rebuild --switch remote

It looks complex but I’m not ready to make my config public in real time(github/gitlab).

1 Like

Did you make it work in the end?