ZFS: Difference between revisions
imported>Mic92 No edit summary |
imported>Nornagon Add simpler & more complete instructions for non-RAID ZFS |
||
| Line 133: | Line 133: | ||
== How to install NixOS on a ZFS root filesystem == | == How to install NixOS on a ZFS root filesystem == | ||
=== Single-disk === | |||
These instructions will get you started with a single-disk ZFS setup. If you're interested in setting up RAID, see below. | |||
<syntaxhighlight lang="bash"> | |||
# Always use the by-id aliases for devices, otherwise ZFS can choke on imports. | |||
DISK=/dev/disk/by-id/... | |||
# Partition 2 will be the boot partition, needed for legacy (BIOS) boot | |||
sgdisk -a1 -n2:34:2047 -t2:EF02 $DISK | |||
# If you need EFI support, make an EFI partition: | |||
sgdisk -n3:1M:+512M -t3:EF00 $DISK | |||
# Partition 1 will be the main ZFS partition, using up the remaining space on the drive. | |||
sgdisk -n1:0:0 -t1:BF01 $DISK | |||
# Create the pool. If you want to tweak this a bit and you're feeling adventurous, you | |||
# might try adding one or more of the following additional options: | |||
# To disable writing access times: | |||
# -O atime=off | |||
# To enable filesystem compression: | |||
# -O compression=lz4 | |||
# To enable normalizing unicode filenames (and implicitly set utf8only=on): | |||
# -O normalization=formD | |||
# To improve performance of certain extended attributes: | |||
# -O xattr=sa | |||
# To specify that your drive uses 4K sectors instead of relying on the size reported | |||
# by the hardware: | |||
# -O ashift=12 | |||
# | |||
# The 'mountpoint=none' option disables ZFS's automount machinery; we'll use the | |||
# normal fstab-based mounting machinery in Linux. | |||
# '-R /mnt' is not a persistent property of the FS, it'll just be used while we're installing. | |||
zpool create -O mountpoint=none -R /mnt rpool $DISK-part1 | |||
# Create the filesystems. This layout is designed so that /home is separate from the root | |||
# filesystem, as you'll likely want to snapshot it differently for backup purposes. It also | |||
# makes a "nixos" filesystem underneath the root, to support installing multiple OSes if | |||
# that's something you choose to do in future. | |||
zfs create -o mountpoint=none rpool/root | |||
zfs create -o mountpoint=legacy rpool/root/nixos | |||
zfs create -o mountpoint=legacy rpool/home | |||
# Mount the filesystems manually. The nixos installer will detect these mountpoints | |||
# and save them to /mnt/nixos/hardware-configuration.nix during the install process. | |||
mount -t zfs rpool/root/nixos /mnt | |||
mkdir /mnt/home | |||
mount -t zfs rpool/home /mnt/home | |||
# Generate the NixOS configuration, as per the NixOS manual. | |||
nixos-generate-config --root /mnt | |||
# Edit /mnt/etc/nixos/configuration.nix and add the following line: | |||
## ---8<-------------------------8<--- | |||
boot.supportedFilesystems = [ "zfs" ]; | |||
## ---8<-------------------------8<--- | |||
# Also, make sure you set the networking.hostId option, which ZFS requires: | |||
## ---8<-------------------------8<--- | |||
networking.hostId = "<random 8-digit hex string>" | |||
## ---8<-------------------------8<--- | |||
# See https://nixos.org/nixos/manual/options.html#opt-networking.hostId for more. | |||
# Continue with installation! | |||
nixos-install | |||
</syntaxhighlight> | |||
=== With RAID === | |||
Here's an example of how to create a ZFS root pool using 4 disks in RAID-10 mode (striping+mirroring), create a ZFS root+home filesystems and install NixOS on them: | Here's an example of how to create a ZFS root pool using 4 disks in RAID-10 mode (striping+mirroring), create a ZFS root+home filesystems and install NixOS on them: | ||
| Line 138: | Line 206: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
# Add the zfs filesystem to the install environment: | # Add the zfs filesystem to the install environment (note this is no longer | ||
# necessary since nixOS 18.09, as the install environment comes with | |||
# zfs enabled by default): | |||
nano /etc/nixos/configuration.nix | nano /etc/nixos/configuration.nix | ||
| Line 151: | Line 221: | ||
# Create boot partition and (zfs) data partition | # Create boot partition and (zfs) data partition | ||
# See: https://github.com/zfsonlinux/ | # See: https://github.com/zfsonlinux/zfs/wiki/Ubuntu-18.04-Root-on-ZFS#step-2-disk-formatting | ||
fdisk /dev/sda | fdisk /dev/sda | ||