Skip to content

Instantly share code, notes, and snippets.

@vizanto
Last active April 16, 2016 11:31
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save vizanto/7374277 to your computer and use it in GitHub Desktop.
Save vizanto/7374277 to your computer and use it in GitHub Desktop.
Installing NixOS as ZFS raidz1 root on a DL360 G5
# 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
@vizanto
Copy link
Author

vizanto commented Nov 8, 2013

NOTE: using nix os the /dev/md0 is often named /dev/md127
https://invalidmagic.wordpress.com/2011/05/10/nix-os-on-a-hetzner-root-server/

@CMCDragonkai
Copy link

@vizanto can you please create an example for a single primary and single swap partition? I'm not familiar with the RAID architecture you've created, and I just want ZFS for a single VM.

@vizanto
Copy link
Author

vizanto commented Apr 16, 2016

Recent Grub 2 can read ZFS and doesn't require a separate boot partition. Maybe even supports booting from RAID-Z pools

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment