Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using disko-install from usb installation: wrong boot partition #743

Open
hjfcook opened this issue Aug 21, 2024 · 5 comments
Open

using disko-install from usb installation: wrong boot partition #743

hjfcook opened this issue Aug 21, 2024 · 5 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@hjfcook
Copy link

hjfcook commented Aug 21, 2024

Hi,

I have a full NixOS installation on a USB stick, to be able to use my own system from any PC.

I attempted to reinstall my NixOS configuration onto my laptop using disko-install from the USB installation, with the --write-efi-boot-entries option, using the following command:

sudo nix run "github:nix-community/disko#disko-install" -- \
  --flake "/etc/nixos/?submodules=1#elitebook" \
  --disk main "/dev/sda" \
  --extra-files "/var/lib/sops-nix/key.txt" "/var/lib/sops-nix/key.txt" \
  --extra-files "/etc/nixos" "/etc/nixos" \
  --write-efi-boot-entries

This almost worked, however the EFI boot entry was written to the boot partition of the USB instead of the laptop.

What went wrong here, and what would I need to do in order to successfully install NixOS onto a computer from my USB installation?

@Mic92
Copy link
Member

Mic92 commented Aug 25, 2024

Are you using grub or systemd-boot?

@hjfcook
Copy link
Author

hjfcook commented Aug 27, 2024

I am using systemd-boot.

@hjfcook
Copy link
Author

hjfcook commented Aug 30, 2024

I have looked into this a bit further and tried using the standard formatting command given when following the quickstart guide (https://github.com/nix-community/disko/blob/master/docs/quickstart.md#step-6-run-disko-to-partition-format-and-mount-your-disks):

# nix --experimental-features "nix-command flakes" run github:nix-community/disko -- --mode disko /etc/nixos/hosts/thinkpad/disks.nix

This results in the hard drive being formatted as per the defined scheme, but the wrong partitions get mounted. For example, on my thinkpad, the internal drive is /dev/nvme0n1, and the USB stick is /dev/sda. After running that command, /dev/sda1 is mounted at /mnt/boot, and /dev/sda2 is mounted at /mnt.

If I instead use --mode format, and mount the partitions myself, I can successfully install:

# nix --experimental-features "nix-command flakes" run github:nix-community/disko -- --mode format /etc/nixos/hosts/thinkpad/disks.nix
# mkdir -p /mnt/boot
# mount /dev/nvme0n1p2 /mnt
# mount -o umask=077 /dev/nvme0n1p1 /mnt/boot
# nixos-generate-config --no-filesystems --root /mnt --dir /etc/nixos/hosts/thinkpad/
# nixos-install --flake "/etc/nixos/?submodules=1#thinkpad" --no-root-passwd
# cp /var/lib/sops-nix/key.txt /mnt/var/lib/sops-nix/key.txt
# cp -r -T /etc/nixos /mnt/etc/nixos

I have a hunch that this might be due to a naming clash resulting in the wrong partitions being mounted, which could potentially be mitigated by providing a name attribute in disks.nix.

The reason I have this hunch is that I had a similar issue when trying to boot from my usb having just installed nixos as above, as it was looking for a root partition with the name disk-main-root, which matched both the root partition of the usb, and the root partition of the thinkpad. Providing names in the usb disk config resolved the clash, as its root partition got a name of disk-usb-root instead, so the correct partition could be found.

I have not had a chance to test this theory out yet!

@iFreilicht
Copy link
Contributor

the internal drive is /dev/nvme0n1, and the USB stick is /dev/sda

Just to make sure, if the USB stick is /dev/sda, why do you invoke disko-install with --disk main "/dev/sda"? Shouldn't that be --disk main "/dev/nvme0n1"?

@hjfcook
Copy link
Author

hjfcook commented Sep 22, 2024

Sorry for the confusion - the first time I was having the issue on one laptop (elitebook), which has its internal drive at /dev/sda, so the USB stick is at /dev/sdb.

The second comment in which I successfully installed by manually mounting the partitions was done on a second laptop (thinkpad), which has its internal drive at /dev/nvme0n1, so the USB stick is at /dev/sda.

If I were to try using disko-install on the thinkpad, the command certainly should include --disk main /dev/nvme0n1!

@iFreilicht iFreilicht added bug Something isn't working help wanted Extra attention is needed labels Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants