2023-10-17 23:53:35 +02:00
|
|
|
---
|
|
|
|
title: nixos btrfs install guide
|
|
|
|
date: 2023-10-14T00:15:29+02:00
|
|
|
|
---
|
|
|
|
|
|
|
|
## BIOS, single partition (for VMs)
|
|
|
|
|
|
|
|
### first, create a new MBR partition table and a single partition
|
|
|
|
|
|
|
|
```shell {lineanchors=list}
|
|
|
|
$ fdisk /dev/vdX
|
|
|
|
fdisk> o
|
|
|
|
fdisk> n
|
2023-11-05 23:23:21 +01:00
|
|
|
# <enter>, <enter>, <enter>
|
2023-10-17 23:53:35 +02:00
|
|
|
# primary partition, number 1, from sector 2048 to end
|
|
|
|
fdisk> w
|
|
|
|
```
|
|
|
|
|
|
|
|
### create a new Btrfs on the new partition
|
|
|
|
|
|
|
|
```shell {lineanchors=list}
|
|
|
|
$ mkfs.btrfs -L nixos /dev/vdX1
|
|
|
|
```
|
|
|
|
|
|
|
|
### create all the subvolumes
|
|
|
|
|
|
|
|
```shell {lineanchors=list}
|
|
|
|
$ mount /dev/vdX1 /mnt
|
|
|
|
$ btrfs subvolume create /mnt/@
|
|
|
|
$ btrfs subv cr /mnt/@boot
|
|
|
|
$ btrfs subv cr /mnt/@home
|
|
|
|
$ btrfs subv cr /mnt/@nix
|
|
|
|
$ btrfs subv cr /mnt/@log
|
|
|
|
$ umount /mnt
|
|
|
|
```
|
|
|
|
|
|
|
|
### Mount the Btrfs again, now properly with the subvolumes
|
|
|
|
|
|
|
|
```shell {lineanchors=list}
|
|
|
|
$ mount -o noatime,subvol=@ /dev/disk/by-uuid/<uuid> /mnt
|
|
|
|
$ mkdir -p /mnt/{boot,home,nix,var/log}
|
|
|
|
$ mount -o noatime,subvol=@boot /dev/disk/by-uuid/<uuid> /mnt/boot
|
|
|
|
$ mount -o subvol=@home /dev/disk/by-uuid/<uuid> /mnt/home
|
|
|
|
$ mount -o noatime,compress=zstd,subvol=@nix /dev/disk/by-uuid/<uuid> /mnt/nix
|
|
|
|
$ mount -o noatime,compress=zstd,subvol=@log /dev/disk/by-uuid/<uuid> /mnt/var/log
|
|
|
|
```
|
|
|
|
|
2023-11-05 23:23:21 +01:00
|
|
|
## UEFI, ESP + single partition
|
|
|
|
|
|
|
|
### first, create a new GPT partition table and two partitions
|
|
|
|
|
|
|
|
```shell {lineanchors=list}
|
|
|
|
$ fdisk /dev/sdX
|
|
|
|
fdisk> g
|
|
|
|
fdisk> n
|
|
|
|
# <enter>, <enter>, +512M
|
|
|
|
# primary partition, number 1, from sector 2048 with size 512MiB
|
|
|
|
fdisk> w
|
|
|
|
```
|
|
|
|
|
|
|
|
### if the root partition should be encrypted
|
|
|
|
|
|
|
|
don't forget proper [drive preparation](https://wiki.archlinux.org/title/Dm-crypt/Drive_preparation)!
|
|
|
|
|
|
|
|
```shell {lineanchors=list}
|
|
|
|
$ cryptsetup -y -v luksFormat /dev/sdX2
|
|
|
|
$ cryptsetup open /dev/sdX2 nixos-root
|
|
|
|
```
|
|
|
|
|
|
|
|
### create the filesystems
|
|
|
|
|
|
|
|
```shell {lineanchors=list}
|
|
|
|
$ mkfs.vfat -F32 -n nixos-boot /dev/sdX1
|
|
|
|
$ mkfs.btrfs -L nixos /dev/sdX2 # or /dev/mapper/nixos-root if encrypted
|
|
|
|
```
|
|
|
|
|
|
|
|
### create all the subvolumes
|
|
|
|
|
|
|
|
```shell {lineanchors=list}
|
|
|
|
$ mount /dev/sdX2 /mnt # or /dev/mapper/nixos-root
|
|
|
|
$ btrfs subvolume create /mnt/@
|
|
|
|
$ btrfs subv cr /mnt/@home
|
|
|
|
$ btrfs subv cr /mnt/@nix
|
|
|
|
$ btrfs subv cr /mnt/@log
|
|
|
|
$ umount /mnt
|
|
|
|
```
|
|
|
|
|
|
|
|
### Mount Btrfs again, now properly with the subvolumes
|
|
|
|
|
|
|
|
```shell {lineanchors=list}
|
|
|
|
$ mount -o noatime,subvol=@ /dev/disk/by-uuid/<uuid> /mnt # or /dev/mapper/nixos-root
|
|
|
|
$ mkdir -p /mnt/{boot,home,nix,var/log}
|
|
|
|
$ mount /dev/disk/by-uuid/<esp-uuid> /mnt/boot
|
|
|
|
$ mount -o subvol=@home /dev/disk/by-uuid/<uuid> /mnt/home
|
|
|
|
$ mount -o noatime,compress=zstd,subvol=@nix /dev/disk/by-uuid/<uuid> /mnt/nix
|
|
|
|
$ mount -o noatime,compress=zstd,subvol=@log /dev/disk/by-uuid/<uuid> /mnt/var/log
|
|
|
|
```
|
|
|
|
|
2023-10-17 23:53:35 +02:00
|
|
|
## rest of the installation
|
|
|
|
|
|
|
|
### generate the initial NixOS system config
|
|
|
|
|
|
|
|
```shell {lineanchors=list}
|
|
|
|
$ nixos-generate-config --root /mnt
|
|
|
|
```
|
|
|
|
|
|
|
|
### review & modify system config
|
|
|
|
|
|
|
|
Here one should set the root password and enable SSH access, at least.
|
|
|
|
Other things can be changed as necessary.
|
|
|
|
|
|
|
|
Don't forget to set `services.openssh.settings.PermitRootLogin = "yes";`!
|
|
|
|
|
|
|
|
```shell {lineanchors=list}
|
|
|
|
$ vim /mnt/etc/nixos/configuration.nix
|
|
|
|
$ vim /mnt/etc/nixos/hardware-configuration.nix
|
|
|
|
```
|
|
|
|
|
|
|
|
### complete the installation
|
|
|
|
|
|
|
|
```shell {lineanchors=list}
|
|
|
|
$ cd /mnt
|
|
|
|
$ nixos-install
|
|
|
|
```
|
|
|
|
|
|
|
|
### perform the first deployment after the install using morph
|
|
|
|
|
|
|
|
```shell {lineanchors=list}
|
|
|
|
$ SSH_USER=root morph deploy --passwd --on <host> ./default.nix switch
|
|
|
|
```
|