# # ZFS on Linux https://zfsonlinux.org/ # # Derived from: https://github.com/zfsonlinux/zfs/wiki/Debian-Buster-Root-on-ZFS # https://github.com/zfsonlinux/zfs/wiki/Debian-Stretch-Root-on-ZFS # # Binary debian packages within # - zfs-linux-0.7.13-debian10-amd64 # - zfs-linux-0.7.13-debian9-amd64 # have been produced using the contained zfs-0.7.13 zfs-linux-0.7.13-source.tar.gz # on debian10-amd64 and debian9-amd64 # using git sources from # - https://github.com/zfsonlinux/spl.git # - https://github.com/zfsonlinux/zfs.git # # Assuming the following steps have been prepared - artifacts are available! # 1) Using own Debian10 Prepared debootstrap: debootstrap01.sh - debootstrap03.sh # 2) Using own Debian10 Live ISO: deblive01.sh - deblive03-iso.sh # # Boot with the created (1) Debian ZFS Live System # # # MYHOSTNAME=jordan POOL=jordan DISK1=ata-WDC_WD2003FYYS-02W0B1_WD-WCAY00187731 DISK2=ata-WDC_WD2003FYYS-02W0B1_WD-WCAY00187732 DISK3=ata-WDC_WD2003FYYS-02W0B1_WD-WCAY00187733 MYSWAPSIZE=33G STRAPBALL=../debian10-zfs-debootstrap.tar.bz2 # # # ## Host sudo -i # # # apt-get update apt-get clean #sed -i "s/PasswordAuthentication no/PasswordAuthentication yes/g" /etc/ssh/sshd_config #service ssh restart modprobe zfs # If you are re-using a MDADM disk, clear it as necessary: # # If the disk was previously used in an MD array, zero the superblock: #apt-get install --yes mdadm #mdadm --zero-superblock --force /dev/disk/by-id/$DISK1 #mdadm --zero-superblock --force /dev/disk/by-id/$DISK2 #mdadm --zero-superblock --force /dev/disk/by-id/$DISK3 # Clear the partition table: sgdisk --zap-all /dev/disk/by-id/$DISK1 sgdisk --zap-all /dev/disk/by-id/$DISK2 sgdisk --zap-all /dev/disk/by-id/$DISK3 # 2.2 Partition your disk: # # Run this if you need legacy (BIOS) booting: sgdisk -a1 -n2:34:2047 -t2:EF02 /dev/disk/by-id/$DISK1 sgdisk -a1 -n2:34:2047 -t2:EF02 /dev/disk/by-id/$DISK2 sgdisk -a1 -n2:34:2047 -t2:EF02 /dev/disk/by-id/$DISK3 #Run these in all cases: sgdisk -n1:0:0 -t1:BF01 /dev/disk/by-id/$DISK1 sgdisk -n1:0:0 -t1:BF01 /dev/disk/by-id/$DISK2 sgdisk -n1:0:0 -t1:BF01 /dev/disk/by-id/$DISK3 # 2.3 Create the root pool # zpool create -f -o ashift=12 -o autoexpand=on \ -O atime=off -O compression=off \ -O mountpoint=/ -R /mnt \ $POOL raidz2 \ /dev/disk/by-id/$DISK1-part1 \ /dev/disk/by-id/$DISK2-part1 \ /dev/disk/by-id/$DISK3-part1 zpool autoexpand=on $POOL zpool autoreplace=off $POOL zpool listsnapshots=off $POOL zfs set dedup=off $POOL zfs set compression=off $POOL zfs set atime=off $POOL zfs set mountpoint=none $POOL # Create Dataset System Root zfs create -o mountpoint=none $POOL/system zfs create -o mountpoint=/ $POOL/system/debian #zfs mount $POOL/system/debian zpool set bootfs=$POOL/system/debian $POOL zfs create -o compression=lz4 $POOL/system/debian/var # Create Datasets .. zfs create -o mountpoint=/home $POOL/users zfs create -o mountpoint=/root $POOL/users/root zfs create -o mountpoint=/backup -o compression=lz4 $POOL/backup zfs create -o mountpoint=/data $POOL/data zfs create -o mountpoint=/srv $POOL/services zfs create -o mountpoint=/usr/local/projects -o compression=lz4 $POOL/projects ## Export / Import ( '-d ..' also changes the dev names ) ##zpool export $POOL ##zpool import -d /dev/disk/by-id -R /mnt $POOL #3.4 Prepare ROOT mkdir -p /mnt (cd /mnt && \ tar --xattrs -xapf $STRAPBALL ) zfs set devices=off $POOL #Step 4: System Configuration # #4.1 Configure the hostname (change HOSTNAME to the desired hostname). # echo $MYHOSTNAME > /mnt/etc/hostname echo "127.0.1.1 $MYHOSTNAME" >> /mnt/etc/hosts #or if the system has a real name in DNS: #echo "127.0.1.1 $MYFQDN $MYHOSTNAME" >> /mnt/etc/hosts #Using NetworkManager should not require this # mv /mnt/etc/resolv.conf /mnt/etc/resolv.conf-orig # cat /etc/resolv.conf > /mnt/etc/resolv.conf # #4.3 Bind the virtual filesystems from the LiveCD environment to the new system and chroot into it: # cp -a ../../zfs /mnt/root/ mount --rbind /dev /mnt/dev mount --rbind /proc /mnt/proc mount --rbind /sys /mnt/sys mount --make-rslave /mnt/dev mount --make-rslave /mnt/proc mount --make-rslave /mnt/sys echo umount -R /mnt/dev echo umount -R /mnt/proc echo umount -R /mnt/sys echo "cat /proc/mounts | awk '{print $2}' | grep "/mnt" | sort -r | xargs umount" echo RUN chroot /mnt /bin/bash --login # # # CHROOT ENVIRONMENT #4.0 Without NetworkManager, you may want to adjust /etc/network/interfaces # #Find the interface name: ip addr show vi /etc/network/interfaces.d/NAME +++ auto NAME iface NAME inet dhcp +++ #4.1 Refine ZFS default (JAU - Required for ZFS 0.7) # /etc/default/zfs # ZFS_INITRD_ADDITIONAL_DATASETS before fstab, i.e. ready for bind! ZFS_INITRD_ADDITIONAL_DATASETS="$POOL/users $POOL/users/root $POOL/backup $POOL/data $POOL/services $POOL/projects" #VERBOSE_MOUNT='yes' #4.2 Optional (but highly recommended): Make debugging GRUB easier: # vi /etc/default/grub +++ Remove quiet from: GRUB_CMDLINE_LINUX_DEFAULT Add 'elevator=noop' to: GRUB_CMDLINE_LINUX_DEFAULT GRUB_CMDLINE_LINUX_DEFAULT="elevator=noop" Uncomment: GRUB_TERMINAL=console Save and quit. +++ # (JAU - Required for ZFS 0.7) ++ # /etc/default/grub GRUB_CMDLINE_LINUX_DEFAULT="elevator=noop" GRUB_CMDLINE_LINUX="root=ZFS=$POOL/system/debian boot=zfs rpool=$POOL bootfs=$POOL/system/debian" ++ +++ #5.0 Configure a basic system environment: # # # # apt-get update apt-get clean passwd #5.1 Verify that the ZFS root filesystem is recognized: # grub-probe / ++ zfs ++ #Step 5: GRUB Installation # #5.2 Refresh the initrd files: # update-initramfs -u -k all #5.4 Update the boot configuration: # update-grub #5.5 Install the boot loader # #5.5a For legacy (MBR) booting, install GRUB to the MBR: # grub-install /dev/disk/by-id/$DISK1 grub-install /dev/disk/by-id/$DISK2 grub-install /dev/disk/by-id/$DISK3 #5.6 Verify that the ZFS module is installed: # ls /boot/grub/*/zfs.mod # #Step 6: First Boot # #6.1 Snapshot the initial installation: # zfs snapshot $POOL/system/debian@install # # # #6.2 Exit from the chroot environment back to the LiveCD environment: # exit HOST ENVIRONMENT #6.3 Run these commands in the LiveCD environment to unmount all filesystems: # # # #7.2 Configure the swap device: #7.2a Create an unencrypted (regular) swap device: # # Swap ZVOL / machine w/ 32GB Ram, x86_64 4k pagesize `getconf PAGESIZE` # zfs create -V $MYSWAPSIZE -b $(getconf PAGESIZE) -o compression=zle \ -o logbias=throughput -o sync=always \ -o primarycache=metadata -o secondarycache=none \ -o com.sun:auto-snapshot=false $POOL/swap zfs set compression=zle $POOL/swap zfs set logbias=throughput $POOL/swap zfs set sync=always $POOL/swap zfs set primarycache=metadata $POOL/swap zfs set secondarycache=none $POOL/swap zfs set com.sun:auto-snapshot=false $POOL/swap zfs set checksum=off $POOL/swap mkswap -f /dev/zvol/$POOL/swap echo /dev/zvol/$POOL/swap none swap defaults 0 0 >> /etc/fstab # UUID=ee57ce05-7287-4b37-93c4-03aeaba756f1 # /etc/fstab # /dev/zvol/$POOL/swap none swap defaults 0 0 # swapon /dev/zvol/$POOL/swap #umount -R /mnt/dev #umount -R /mnt/proc #umount -R /mnt/sys cat /proc/mounts | awk '{print $2}' | grep "/mnt" | sort -r | xargs umount zfs unmount -a zpool export $POOL # # # #6.4 Reboot: # reboot #Step 8: Full Software Installation # #8.1 Upgrade the minimal system: # apt-get update apt-get dist-upgrade --yes #8.2 Optional: Disable log compression: # # # for file in /etc/logrotate.d/* ; do if grep -Eq "(^|[^#y])compress" "$file" ; then sed -i -r "s/(^|[^#y])(compress)/\1#\2/" "$file" fi done # # # #8.3 Reboot: reboot