Skip to content

Instantly share code, notes, and snippets.

@Matthewacon
Last active May 27, 2024 23:52

Revisions

  1. Matthewacon revised this gist Dec 6, 2020. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion arch-luks-zfs-efistub-install.sh
    Original file line number Diff line number Diff line change
    @@ -102,7 +102,8 @@ pacstrap /mnt \
    linux-firmware\
    mkinitcpio\
    intel-ucode\
    reflector
    reflector\
    wpa_supplicant

    # Chroot into your new installation
    arch-chroot /mnt
  2. Matthewacon renamed this gist Oct 28, 2020. 1 changed file with 13 additions and 2 deletions.
    15 changes: 13 additions & 2 deletions arch-luks-zfs-efistub-install → arch-luks-zfs-efistub-install.sh
    Original file line number Diff line number Diff line change
    @@ -60,8 +60,19 @@ cp /etc/zfs/zpool.cache /mnt/etc/zfs/zpool.cache
    arch-chroot /mnt
    zpool set cachefile=/etc/zfs/zpool.cache zroot

    # Enable the the following systemd services in order to import the zroot pool and mount all datasets at boot
    systemctl enable zfs.target zfs-mount.service zfs-import-cache.service
    # Enable the the following systemd services in order to import the zroot pool at boot
    systemctl enable zfs.target zfs-import-cache.service zfs-import.target

    # Set up zfs-mount-generator to generate systemd mount units for all of your datasets that need to be mounted at boot
    mkdir /etc/zfs/zfs-list.cache
    ln -s /usr/lib/zfs/zfs/zed.d/history_event-zfs-list-cacher.sh /etc/zfs/zed.d
    systemctl enable zfs-zed.service
    systemctl start zfs-zed.service
    touch /etc/zfs/zfs-list.cache/zroot
    # Update a property of your root dataset in order to generate a ZED event and update the list cache for the pool
    zfs set canmount=on zroot
    # Restore the previous value for that dataset
    zfs set canmount=off zroot

    # Mount your ESP
    mkdir -p /mnt/boot
  3. Matthewacon revised this gist Jun 28, 2020. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions arch-luks-zfs-efistub-install
    Original file line number Diff line number Diff line change
    @@ -111,6 +111,12 @@ timedatectl set-timezone your_timezone
    # Enable DHCPCD on boot
    systemctl enable dhcpcd

    # Set your default nameserver (Cloudflare in this case)
    # Add the following lines to /etc/resolv.conf:
    # nameserver 1.1.1.1
    # nameserver 2606:4700:4700::1001
    # options single-request

    # Enable the wheel sudo group
    # Uncomment the following line in /etc/sudoers with visudo
    # %wheel ALL=(ALL) ALL
  4. Matthewacon revised this gist Jun 28, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion arch-luks-zfs-efistub-install
    Original file line number Diff line number Diff line change
    @@ -183,7 +183,7 @@ mkinitcpio -p linux

    # Build your EFISTUB loader
    # Note: If you make changes to your initrd, or files included in your initrd, you will need to re-run this command
    # in order to update your EFISTUB.
    # in order to update your EFISTUB. This includes /boot/cmdline.txt
    build_efi_kernels

    # Register your EFISTUB loader with efibootmgr or place it in the default x86_64 EFI location
  5. Matthewacon revised this gist Jun 28, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions arch-luks-zfs-efistub-install
    Original file line number Diff line number Diff line change
    @@ -170,6 +170,7 @@ lsblk -o +UUID
    # Configure your kernel cmdline
    # - For udev-based systems, edit /boot/cmdline.txt and add the following:
    # cryptdevice=UUID=UUID_OF_YOUR_LUKS_PARTITION:luks:allow-discards zfs=zroot/root root=ZFS=zroot/root rw quiet
    #
    # - For systemd-based systems the configuration is a little different
    # Note: There seems to be an issue with the sd-zfs systemd generator that causes importing pools by cache file to break.
    # The current workaround is to just disable it by setting zfs_force=1 and zfs_ignorecache=1
  6. Matthewacon revised this gist Jun 28, 2020. 1 changed file with 6 additions and 2 deletions.
    8 changes: 6 additions & 2 deletions arch-luks-zfs-efistub-install
    Original file line number Diff line number Diff line change
    @@ -170,8 +170,12 @@ lsblk -o +UUID
    # Configure your kernel cmdline
    # - For udev-based systems, edit /boot/cmdline.txt and add the following:
    # cryptdevice=UUID=UUID_OF_YOUR_LUKS_PARTITION:luks:allow-discards zfs=zroot/root root=ZFS=zroot/root rw quiet
    # - For systemd-based systems, edit /boot/cmdline.txt and add the following:
    # rd.luks.name=UUID_OF_YOUR_LUKS_PARTITION=root zfs=zroot/root root=zfs:zroot/root rw quiet
    # - For systemd-based systems the configuration is a little different
    # Note: There seems to be an issue with the sd-zfs systemd generator that causes importing pools by cache file to break.
    # The current workaround is to just disable it by setting zfs_force=1 and zfs_ignorecache=1
    #
    # Edit /boot/cmdline.txt and add the following:
    # rd.luks.name=UUID_OF_YOUR_LUKS_PARTITION=root zfs=zroot/root zfs_force=1 zfs_ignorecache=1 root=zfs:zroot/root rw quiet

    # Rebuild your initrd as root
    mkinitcpio -p linux
  7. Matthewacon revised this gist Jun 28, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion arch-luks-zfs-efistub-install
    Original file line number Diff line number Diff line change
    @@ -171,7 +171,7 @@ lsblk -o +UUID
    # - For udev-based systems, edit /boot/cmdline.txt and add the following:
    # cryptdevice=UUID=UUID_OF_YOUR_LUKS_PARTITION:luks:allow-discards zfs=zroot/root root=ZFS=zroot/root rw quiet
    # - For systemd-based systems, edit /boot/cmdline.txt and add the following:
    # rd.luks.name=UUID_OF_YOUR_LUKS_PARTITION=root zfs=zroot/root root=ZFS/zroot/root rw quiet
    # rd.luks.name=UUID_OF_YOUR_LUKS_PARTITION=root zfs=zroot/root root=zfs:zroot/root rw quiet

    # Rebuild your initrd as root
    mkinitcpio -p linux
  8. Matthewacon revised this gist Jun 28, 2020. 1 changed file with 8 additions and 6 deletions.
    14 changes: 8 additions & 6 deletions arch-luks-zfs-efistub-install
    Original file line number Diff line number Diff line change
    @@ -162,17 +162,19 @@ yay -Sy --noconfirm --sudoloop arch-efiboot zfs-utils zfs-dkms
    yay -Sy --noconfirm --sudoloop mkinitcpio-sd-zfs
    # and set the following lines in /etc/mkinitcpio.conf
    # MODULES=(zfs)
    # HOOKS=(base systemd autodetect modconf block sd-encrypt sd-zfs filesystems keyboard)
    # HOOKS=(base systemd keyboard autodetect modconf block sd-encrypt sd-zfs filesystems)

    # Exit your user's shell and rebuild your initrd as root
    mkinitcpio -p linux

    # Get the UUID of your LUKS partition
    # Exit your user's shell and get the UUID of your LUKS partition
    lsblk -o +UUID

    # Configure your kernel cmdline
    # - Edit /boot/cmdline.txt and add the following:
    # - For udev-based systems, edit /boot/cmdline.txt and add the following:
    # cryptdevice=UUID=UUID_OF_YOUR_LUKS_PARTITION:luks:allow-discards zfs=zroot/root root=ZFS=zroot/root rw quiet
    # - For systemd-based systems, edit /boot/cmdline.txt and add the following:
    # rd.luks.name=UUID_OF_YOUR_LUKS_PARTITION=root zfs=zroot/root root=ZFS/zroot/root rw quiet

    # Rebuild your initrd as root
    mkinitcpio -p linux

    # Build your EFISTUB loader
    # Note: If you make changes to your initrd, or files included in your initrd, you will need to re-run this command
  9. Matthewacon revised this gist Jun 28, 2020. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions arch-luks-zfs-efistub-install
    Original file line number Diff line number Diff line change
    @@ -60,6 +60,9 @@ cp /etc/zfs/zpool.cache /mnt/etc/zfs/zpool.cache
    arch-chroot /mnt
    zpool set cachefile=/etc/zfs/zpool.cache zroot

    # Enable the the following systemd services in order to import the zroot pool and mount all datasets at boot
    systemctl enable zfs.target zfs-mount.service zfs-import-cache.service

    # Mount your ESP
    mkdir -p /mnt/boot
    mount /dev/sdx1 /mnt/boot
  10. Matthewacon revised this gist Jun 28, 2020. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions arch-luks-zfs-efistub-install
    Original file line number Diff line number Diff line change
    @@ -135,6 +135,9 @@ pacman -Sy
    # - Uncomment and change #MAKEFLAGS="-j2" to MAKEFLAGS="-j`nproc`"
    # - Change PKGEXT='.pkg.tar.xz' to PKGEXT='.pkg.tar' to disable package compression

    # Give your user relevant access to their dataser
    zfs allow your_user_here create,mount,mountpoint,snapshot zroot/home/your_user_here

    # Su into your user and cd to your home directory
    su your_user_here
    cd ~
  11. Matthewacon revised this gist Jun 28, 2020. 1 changed file with 16 additions and 5 deletions.
    21 changes: 16 additions & 5 deletions arch-luks-zfs-efistub-install
    Original file line number Diff line number Diff line change
    @@ -43,11 +43,22 @@ zpool import -R /mnt zroot
    # 3 - zroot/home/root (/root)
    # 4 - zroot/home/your_user_here (/home/your_user_here)
    # 5 - zroot/var (/var)
    zfs create -o mountpoint=/ -o canmount=noauto zroot/root
    zfs create -o mountpoint=/home -o canmount=noauto zroot/home
    zfs create -o mountpoint=/home/your_user_here -o canmount=noauto zroot/home/your_user_here
    zfs create -o mountpoint=/root -o canmount=noauto zroot/home/root
    zfs create -o mountpoint=/var -o canmount=noauto zroot/var
    zfs create -o mountpoint=/ zroot/root
    zfs create -o mountpoint=/home zroot/home
    zfs create -o mountpoint=/home/your_user_here zroot/home/your_user_here
    zfs create -o mountpoint=/root zroot/home/root
    zfs create -o mountpoint=/var zroot/var

    # Configure the root filesystem
    zpool set bootfs=zroot/root zroot

    # Exit the chroot and copy over hte current ZFS cache
    # Note: This step is required for the ZFS daemon to start
    cp /etc/zfs/zpool.cache /mnt/etc/zfs/zpool.cache

    # Re-enter the chroot and set the cache for the root pool
    arch-chroot /mnt
    zpool set cachefile=/etc/zfs/zpool.cache zroot

    # Mount your ESP
    mkdir -p /mnt/boot
  12. Matthewacon renamed this gist Jun 28, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  13. Matthewacon revised this gist Jun 28, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -158,6 +158,8 @@ lsblk -o +UUID
    # cryptdevice=UUID=UUID_OF_YOUR_LUKS_PARTITION:luks:allow-discards zfs=zroot/root root=ZFS=zroot/root rw quiet

    # Build your EFISTUB loader
    # Note: If you make changes to your initrd, or files included in your initrd, you will need to re-run this command
    # in order to update your EFISTUB.
    build_efi_kernels

    # Register your EFISTUB loader with efibootmgr or place it in the default x86_64 EFI location
  14. Matthewacon revised this gist Jun 28, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -162,7 +162,7 @@ build_efi_kernels

    # Register your EFISTUB loader with efibootmgr or place it in the default x86_64 EFI location
    # - Register with efibootmgr
    efibootmgr -c -d /dev/sdx -p 1 -L "EFISTUB" -l "\linux.efi"
    efibootmgr -c -d /dev/sdx -p 1 -L "EFISTUB" -l "\linux.efi"

    # - Move it into the default x86_64 EFI location
    mkdir -p /boot/EFI/BOOT
  15. Matthewacon revised this gist Jun 28, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -162,7 +162,7 @@ build_efi_kernels

    # Register your EFISTUB loader with efibootmgr or place it in the default x86_64 EFI location
    # - Register with efibootmgr
    efibootmgr
    efibootmgr -c -d /dev/sdx -p 1 -L "EFISTUB" -l "\linux.efi"

    # - Move it into the default x86_64 EFI location
    mkdir -p /boot/EFI/BOOT
  16. Matthewacon revised this gist Jun 28, 2020. 1 changed file with 18 additions and 0 deletions.
    18 changes: 18 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -150,4 +150,22 @@ yay -Sy --noconfirm --sudoloop mkinitcpio-sd-zfs
    # Exit your user's shell and rebuild your initrd as root
    mkinitcpio -p linux

    # Get the UUID of your LUKS partition
    lsblk -o +UUID

    # Configure your kernel cmdline
    # - Edit /boot/cmdline.txt and add the following:
    # cryptdevice=UUID=UUID_OF_YOUR_LUKS_PARTITION:luks:allow-discards zfs=zroot/root root=ZFS=zroot/root rw quiet

    # Build your EFISTUB loader
    build_efi_kernels

    # Register your EFISTUB loader with efibootmgr or place it in the default x86_64 EFI location
    # - Register with efibootmgr
    efibootmgr

    # - Move it into the default x86_64 EFI location
    mkdir -p /boot/EFI/BOOT
    mv /boot/linux.efi /boot/EFI/BOOT/bootx64.efi

    # That's it, enjoy your new system!
  17. Matthewacon revised this gist Jun 28, 2020. 1 changed file with 25 additions and 2 deletions.
    27 changes: 25 additions & 2 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -101,9 +101,10 @@ systemctl enable dhcpcd
    # Uncomment the following line in /etc/sudoers with visudo
    # %wheel ALL=(ALL) ALL

    # Create your user
    # Create your user and set the correct permissions for your home directory
    useradd your_user_here
    usermod -aG wheel your_user_here
    chown your_user_here:your_user_here /home/your_user_here

    # Set a root password
    passwd
    @@ -121,10 +122,32 @@ pacman -Sy

    # Configure makepkg for faster AUR package builds
    # - Uncomment and change #MAKEFLAGS="-j2" to MAKEFLAGS="-j`nproc`"
    # - Change PKGEXT='.pkg.tar.gz' to PKGEXT='.pkg.tar' to disable package compression
    # - Change PKGEXT='.pkg.tar.xz' to PKGEXT='.pkg.tar' to disable package compression

    # Su into your user and cd to your home directory
    su your_user_here
    cd ~

    # Install Yay (or your AUR helper of of choice)
    git clone https://aur.archlinux.org/yay.git
    cd yay
    makepkg -si

    # Use Yay (or your AUR helper of choice) to install the following packages
    yay -Sy --noconfirm --sudoloop arch-efiboot zfs-utils zfs-dkms

    # Configure your initrd (udev or systemd)
    # - For udev-based systems, set the following lines in /etc/mkinitcpio.conf
    # MODULES=(zfs)
    # HOOKS=(base udev autodetect modconf block encrypt zfs filesystems keyboard)

    # - For systemd-based systems, install the follwing AUR packages
    yay -Sy --noconfirm --sudoloop mkinitcpio-sd-zfs
    # and set the following lines in /etc/mkinitcpio.conf
    # MODULES=(zfs)
    # HOOKS=(base systemd autodetect modconf block sd-encrypt sd-zfs filesystems keyboard)

    # Exit your user's shell and rebuild your initrd as root
    mkinitcpio -p linux

    # Build your EFISTUB loader
  18. Matthewacon revised this gist Jun 28, 2020. 1 changed file with 31 additions and 0 deletions.
    31 changes: 31 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -97,3 +97,34 @@ timedatectl set-timezone your_timezone
    # Enable DHCPCD on boot
    systemctl enable dhcpcd

    # Enable the wheel sudo group
    # Uncomment the following line in /etc/sudoers with visudo
    # %wheel ALL=(ALL) ALL

    # Create your user
    useradd your_user_here
    usermod -aG wheel your_user_here

    # Set a root password
    passwd

    # Set your user's password
    passwd your_user_here

    # Enable the multiarch repo in /etc/pacman.conf by uncommenting the following lines:
    # [multilib]
    # Include = /etc/pacman.d/mirrorlist

    # Use reflector to order your mirrorlist for speed and update your repos
    reflector -c Country -f 150 --threads `nproc` > /mnt/etc/pacman.d/mirrorlist
    pacman -Sy

    # Configure makepkg for faster AUR package builds
    # - Uncomment and change #MAKEFLAGS="-j2" to MAKEFLAGS="-j`nproc`"
    # - Change PKGEXT='.pkg.tar.gz' to PKGEXT='.pkg.tar' to disable package compression

    # Su into your user and cd to your home directory
    su your_user_here
    cd ~

    # Install Yay (or your AUR helper of of choice)
  19. Matthewacon created this gist Jun 27, 2020.
    99 changes: 99 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,99 @@
    # Create your partition layout (using GPT)
    # 1 - ESP (FAT32, 128M)
    # 2 - Linux (luks, any size)

    # Format your partitions
    mkfs.fat -F32 /dev/sdx1
    cryptsetup luksFormat --key-size 512 --cipher aes-xts-plain64 /dev/sdx2

    # Open your luks partition
    cryptsetup open /dev/sdx2 luks_root

    # Make sure ZFS is loaded before continuing
    modprobe zfs

    # Create your ZFS pool
    # Note:
    # - For drives with a block size of 512b, use ashift=9
    # - For drives with a blocks size of 4KiB, use ahift=12
    zpool create \
    -o ashift=12\
    -O xattr=sa\
    -O redundant_metadata=most\
    -O normalization=formD\
    -O acltype=posixacl\
    -O compression=lz4\
    -O dedup=on\
    -O dnodesize=legacy\
    -O relatime=on\
    -O mountpoint=none\
    -O canmount=off\
    -O devices=off\
    -m none\
    zroot\
    /dev/mapper/luks_root

    # Export your new zpool and reimport it with an alternate root to avoid mounting conflicts
    zpool export zroot
    zpool import -R /mnt zroot

    # Create all of your datasets
    # 1 - zroot/root (/)
    # 2 - zroot/home (/home)
    # 3 - zroot/home/root (/root)
    # 4 - zroot/home/your_user_here (/home/your_user_here)
    # 5 - zroot/var (/var)
    zfs create -o mountpoint=/ -o canmount=noauto zroot/root
    zfs create -o mountpoint=/home -o canmount=noauto zroot/home
    zfs create -o mountpoint=/home/your_user_here -o canmount=noauto zroot/home/your_user_here
    zfs create -o mountpoint=/root -o canmount=noauto zroot/home/root
    zfs create -o mountpoint=/var -o canmount=noauto zroot/var

    # Mount your ESP
    mkdir -p /mnt/boot
    mount /dev/sdx1 /mnt/boot

    # Export your mount configuration to /mnt/etc/fstab
    # Note: You must comment out all of the exported ZFS dataset mounts, otheriwse you will experience issues booting
    genfstab -pU /mnt > /mnt/etc/fstab

    # Add a tmpfs for /tmp to /mnt/etc/fstab
    # tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0

    # Install Arch Linux
    pacstrap /mnt \
    base\
    base-devel\
    zsh\
    vim\
    git\
    efibootmgr\
    dialog\
    openssh\
    dhcpcd\
    dosfstools\
    linux\
    linux-headers\
    linux-firmware\
    mkinitcpio\
    intel-ucode\
    reflector

    # Chroot into your new installation
    arch-chroot /mnt

    # Set your locales
    echo "LANG=en_US.UTF-8\nLC_ALL=C\nLANGUAGE=en_US" > /etc/locale.conf
    echo "en_US.UTF-8 UTF-8" > /etc/locale.gen
    locale-gen

    # Set your hostname
    echo "your_hostname" > /etc/hostname

    # Enable NTP and set your timezone
    timedatectl set-ntp true
    timedatectl set-timezone your_timezone

    # Enable DHCPCD on boot
    systemctl enable dhcpcd