Skip to content

Instantly share code, notes, and snippets.

@0x00dec0de
Forked from vizanto/nixos-zfs-root.sh
Created August 13, 2014 20:39
Show Gist options
  • Save 0x00dec0de/403a6d7ee982e4f6eb56 to your computer and use it in GitHub Desktop.
Save 0x00dec0de/403a6d7ee982e4f6eb56 to your computer and use it in GitHub Desktop.
# Add the zfs filesystem to the install environment:
nano /etc/nixos/configuration.nix
## ---8<-------------------------8<---
boot.supportedFilesystems = ["zfs"];
## ---8<-------------------------8<---
nixos-rebuild switch
# Load the just installed ZFS kernel module
modprobe zfs
# Create boot partition and (zfs) data partition
# See: https://github.com/zfsonlinux/pkg-zfs/wiki/HOWTO-install-Ubuntu-to-a-Native-ZFS-Root-Filesystem#step-2-disk-partitioning
fdisk /dev/cciss/c0d0
# Copy the partition table to the other disks
sfdisk --dump /dev/cciss/c0d0 |sfdisk /dev/cciss/c0d1
sfdisk --dump /dev/cciss/c0d0 |sfdisk /dev/cciss/c0d2
sfdisk --dump /dev/cciss/c0d0 |sfdisk /dev/cciss/c0d3
# Create a raid mirror of the first partitions for /boot (GRUB)
mdadm --build /dev/md127 --metadata=0.90 --level=1 --raid-devices=4 /dev/cciss/c0d[0,1,2,3]p1
mkfs.ext4 -m 0 -L boot -j /dev/md127
mount /dev/md127 /mnt/boot
mkfs.ext4 -m 0 -L boot -j /dev/cciss/c0d0p1
mkdir -p /mnt/boot
mount /dev/cciss/c0d0p1 /mnt/boot
# Now for the actual ZFS goodness!
zpool create -o ashift=12 -o altroot=/mnt rpool raidz1 /dev/cciss/c0d[0,1,2,3]p2
zfs create -o mountpoint=none rpool/ROOT
zfs create -o mountpoint=/ rpool/ROOT/nixos
zfs create -o mountpoint=/home rpool/HOME
zfs create -V 16G rpool/swap
nixos-generate-config --root /mnt
# Now edit the generated hardware config:
nano /mnt/etc/nixos/hardware-configuration.nix
## ---8<-------------------------8<---
# This is what you want: (remove everything other than / and /boot)
fileSystems."/" =
{ device = "rpool/ROOT/nixos";
fsType = "zfs";
};
fileSystems."/boot" =
{ device = "/dev/md127";
fsType = "ext4";
options = "rw,data=ordered,relatime";
};
## ---8<-------------------------8<---
# configuration.nix needs some adjustment:
nano /mnt/etc/nixos/configuration.nix
## ---8<-------------------------8<---
# This is some more of what you want:
boot.loader.grub.devices = ["/dev/cciss/c0d0" "/dev/cciss/c0d1" "/dev/cciss/c0d2" "/dev/cciss/c0d3"];
boot.supportedFilesystems = ["zfs"];
# This is required to get NixOS boot Stage 1 to mount the rpool
# until nix's zpool import init script doesn't just try /dev...
# https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/tasks/filesystems/zfs.nix#L63
boot.initrd.postDeviceCommands = "zpool import -f -a -d /dev/cciss";
## ---8<-------------------------8<---
# Ready to go!
nixos-install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment