3.3 KiB
3.3 KiB
title | date |
---|---|
nixos btrfs install guide | 2023-10-14T00:15:29+02:00 |
BIOS, single partition (for VMs)
first, create a new MBR partition table and a single partition
$ fdisk /dev/vdX
fdisk> o
fdisk> n
# <enter>, <enter>, <enter>
# primary partition, number 1, from sector 2048 to end
fdisk> w
create a new Btrfs on the new partition
$ mkfs.btrfs -L nixos /dev/vdX1
create all the subvolumes
$ 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
$ 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
UEFI, ESP + single partition
first, create a new GPT partition table and two partitions
$ 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!
$ cryptsetup -y -v luksFormat /dev/sdX2
$ cryptsetup open /dev/sdX2 nixos-root
create the filesystems
$ 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
$ 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
$ 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
rest of the installation
generate the initial NixOS system config
$ 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";
!
$ vim /mnt/etc/nixos/configuration.nix
$ vim /mnt/etc/nixos/hardware-configuration.nix
complete the installation
$ cd /mnt
$ nixos-install
perform the first deployment after the install using morph
$ SSH_USER=root morph deploy --passwd --on <host> ./default.nix switch