2023-04-27 16:36:48 +02:00
|
|
|
# Installing NixOS in a new node
|
|
|
|
|
|
|
|
This article shows the steps to install NixOS in a node following the
|
|
|
|
configuration of the repo.
|
|
|
|
|
2023-08-24 12:29:44 +02:00
|
|
|
## Enable the serial console
|
|
|
|
|
|
|
|
By default, the nodes have the serial console disabled in the GRUB and also boot
|
|
|
|
without the serial enabled.
|
|
|
|
|
|
|
|
To enable the serial console in the GRUB, set in /etc/default/grub the following
|
|
|
|
lines:
|
|
|
|
|
|
|
|
```
|
|
|
|
GRUB_TERMINAL="console serial"
|
|
|
|
GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"
|
|
|
|
```
|
|
|
|
|
|
|
|
To boot Linux with the serial enabled, so you can see the boot log and login via
|
|
|
|
serial set:
|
|
|
|
|
|
|
|
```
|
|
|
|
GRUB_CMDLINE_LINUX="console=ttyS0,115200n8 console=tty0"
|
|
|
|
```
|
|
|
|
|
|
|
|
Then update the grub config:
|
|
|
|
|
|
|
|
```
|
|
|
|
# grub2-mkconfig -o /boot/grub2/grub.cfg
|
|
|
|
```
|
|
|
|
|
|
|
|
And reboot.
|
|
|
|
|
2023-04-27 16:36:48 +02:00
|
|
|
## Prepare the disk
|
|
|
|
|
|
|
|
Create a main partition and label it `nixos` following [the manual][1].
|
|
|
|
|
|
|
|
[1]: https://nixos.org/manual/nixos/stable/index.html#sec-installation-manual-partitioning.
|
|
|
|
|
|
|
|
```
|
|
|
|
# disk=/dev/sdX
|
|
|
|
# parted $disk -- mklabel msdos
|
2023-05-10 10:58:27 +02:00
|
|
|
# parted $disk -- mkpart primary 1MB -8GB
|
|
|
|
# parted $disk -- mkpart primary linux-swap -8GB 100%
|
2023-04-27 16:36:48 +02:00
|
|
|
# parted $disk -- set 1 boot on
|
|
|
|
```
|
|
|
|
|
|
|
|
Then create an etx4 filesystem, labeled `nixos` where the system will be
|
|
|
|
installed. **Ensure that no other partition has the same label.**
|
|
|
|
|
|
|
|
```
|
|
|
|
# mkfs.ext4 -L nixos "${disk}1"
|
2023-05-10 10:58:27 +02:00
|
|
|
# mkswap -L swap "${disk}2"
|
2023-04-27 16:36:48 +02:00
|
|
|
# mount ${disk}1 /mnt
|
|
|
|
# lsblk -f $disk
|
|
|
|
NAME FSTYPE LABEL UUID MOUNTPOINT
|
|
|
|
sdX
|
|
|
|
`-sdX1 ext4 nixos 10d73b75-809c-4fa3-b99d-4fab2f0d0d8e /mnt
|
|
|
|
```
|
|
|
|
|
|
|
|
## Prepare nix and nixos-install
|
|
|
|
|
2023-06-14 11:15:00 +02:00
|
|
|
Mount the nix store from the hut node in read-only /nix.
|
2023-04-27 16:36:48 +02:00
|
|
|
|
|
|
|
```
|
|
|
|
# mkdir /nix
|
2023-06-14 11:15:00 +02:00
|
|
|
# mount -o ro hut:/nix /nix
|
2023-04-27 16:36:48 +02:00
|
|
|
```
|
|
|
|
|
2023-06-14 11:15:00 +02:00
|
|
|
Get the nix binary and nixos-install tool from hut:
|
2023-04-27 16:36:48 +02:00
|
|
|
|
|
|
|
```
|
2023-06-14 11:15:00 +02:00
|
|
|
# ssh hut 'readlink -f $(which nix)'
|
2023-04-27 16:36:48 +02:00
|
|
|
/nix/store/0sxbaj71c4c4n43qhdxm31f56gjalksw-nix-2.13.3/bin/nix
|
2023-06-14 11:15:00 +02:00
|
|
|
# ssh hut 'readlink -f $(which nixos-install)'
|
2023-04-27 16:36:48 +02:00
|
|
|
/nix/store/9yq8ps06ysr2pfiwiij39ny56yk3pdcs-nixos-install/bin/nixos-install
|
|
|
|
```
|
|
|
|
|
|
|
|
And add them to the PATH:
|
|
|
|
|
|
|
|
```
|
|
|
|
# export PATH=$PATH:/nix/store/0sxbaj71c4c4n43qhdxm31f56gjalksw-nix-2.13.3/bin
|
|
|
|
# export PATH=$PATH:/nix/store/9yq8ps06ysr2pfiwiij39ny56yk3pdcs-nixos-install/bin/
|
|
|
|
# nix --version
|
|
|
|
nix (Nix) 2.13.3
|
|
|
|
```
|
|
|
|
|
2023-05-10 10:58:27 +02:00
|
|
|
## Adapt owl configuration
|
|
|
|
|
|
|
|
Clone owl repo:
|
|
|
|
|
|
|
|
```
|
|
|
|
$ git clone git@bscpm03.bsc.es:rarias/owl.git
|
|
|
|
$ cd owl
|
|
|
|
```
|
|
|
|
|
|
|
|
Edit the configuration to your needs.
|
|
|
|
|
|
|
|
## Install from another Linux OS
|
|
|
|
|
|
|
|
Install nixOS into the storage drive.
|
|
|
|
|
|
|
|
```
|
|
|
|
# nixos-install --flake --root /mnt .#xeon0X
|
|
|
|
```
|
|
|
|
|
|
|
|
At this point, the nixOS grub has been installed into the nixos device, which
|
|
|
|
is not the default boot device. To keep both the old Linux and NixOS grubs, add
|
|
|
|
an entry into the old Linux grub to jump into the new grub.
|
|
|
|
|
|
|
|
```
|
|
|
|
# echo "
|
|
|
|
|
|
|
|
menuentry 'NixOS' {
|
|
|
|
insmod chain
|
|
|
|
search --no-floppy --label nixos --set root
|
|
|
|
configfile /boot/grub/grub.cfg
|
|
|
|
} " >> /etc/grub.d/40_custom
|
|
|
|
```
|
|
|
|
|
|
|
|
Rebuild grub config.
|
|
|
|
|
|
|
|
```
|
|
|
|
# grub2-mkconfig -o /boot/grub/grub.cfg
|
|
|
|
```
|
|
|
|
|
|
|
|
To boot into NixOS manually, reboot and select NixOS in the grub menu to boot
|
|
|
|
into NixOS.
|
|
|
|
|
|
|
|
To temporarily boot into NixOS only on the next reboot run:
|
|
|
|
|
|
|
|
```
|
|
|
|
# grub2-reboot 'NixOS'
|
|
|
|
```
|
|
|
|
|
|
|
|
To permanently boot into NixOS as the default boot OS, edit `/etc/default/grub/`:
|
|
|
|
|
|
|
|
```
|
|
|
|
GRUB_DEFAULT='NixOS'
|
|
|
|
```
|
|
|
|
|
|
|
|
And update grub.
|
|
|
|
|
|
|
|
```
|
|
|
|
# grub2-mkconfig -o /boot/grub/grub.cfg
|
|
|
|
```
|
|
|
|
|
2023-04-27 16:36:48 +02:00
|
|
|
## Build the nixos kexec image
|
|
|
|
|
|
|
|
```
|
|
|
|
# nix build .#nixosConfigurations.xeon02.config.system.build.kexecTree -v
|
|
|
|
```
|
2024-06-03 09:20:11 +02:00
|
|
|
|
2024-06-07 10:40:37 +02:00
|
|
|
## Chain NixOS in same disk with other systems
|
|
|
|
|
|
|
|
To install NixOS on a partition along another system which controls the GRUB,
|
|
|
|
first disable the grub device, so the GRUB is not installed in the disk by
|
|
|
|
NixOS (only the /boot files will be generated):
|
|
|
|
|
|
|
|
```
|
|
|
|
boot.loader.grub.device = "nodev";
|
|
|
|
```
|
|
|
|
|
|
|
|
Then add the following entry to the old GRUB configuration:
|
2024-06-03 09:20:11 +02:00
|
|
|
|
|
|
|
```
|
|
|
|
menuentry 'NixOS' {
|
|
|
|
insmod chain
|
2024-06-07 10:40:37 +02:00
|
|
|
search --no-floppy --label nixos --set root
|
2024-06-03 09:20:11 +02:00
|
|
|
configfile /boot/grub/grub.cfg
|
|
|
|
}
|
|
|
|
```
|
2024-06-07 10:40:37 +02:00
|
|
|
|
|
|
|
The partition with NixOS must have the label "nixos" for it to be found. New
|
|
|
|
system configuration entries will be stored in the GRUB configuration managed
|
|
|
|
by NixOS, so there is no need to change the old GRUB settings.
|