void- enter the void 🪐 |
git clone git://git.acid.vegas/archlinux.git |
Log | Files | Refs | Archive |
enterthezoid (6355B)
1 #!/bin/bash 2 # enter the zoid (zfs on root with zraid) - developed by acidvegas (https://git.acid.vegas/void) 3 # boot: https://github.com/leahneukirchen/hrmpf 4 # reference: https://docs.zfsbootmenu.org/en/v2.3.x/guides/void-linux/uefi.html (do we need to make any updates?) 5 6 set -xev 7 8 # Configuration 9 export HOSTNAME=blackhole 10 export BOOT_DRIVE=/dev/sde # Use the internal USB drive for the boot partition 11 export BOOT_METHOD=direct # Use direct or refind 12 export POOL_DRIVES="/dev/sda /dev/sdb /dev/sdc /dev/sdd" # Verify these with lsblk before running 13 export RAIDZ_PARITY="1" # Number of drives to use for the RAID-Z parity (must be 1 or greater otherwise why are you using ZFS?) 14 15 16 checks() { 17 # Check if the system is using UEFI or BIOS 18 if [ ! -d /sys/firmware/efi ]; then 19 echo "System must be using UEFI" 20 exit 1 21 fi 22 23 # Check if all drives exist and are valid 24 for d in $BOOT_DRIVE $POOL_DRIVES; do 25 if [ ! -b $d ]; then 26 echo "Drive $d does not exist" 27 exit 1 28 fi 29 done 30 31 # Check if the boot method is valid 32 if [ $BOOT_METHOD != "direct" ] && [ $BOOT_METHOD != "refind" ]; then 33 echo "Boot method must be direct or refind" 34 exit 1 35 fi 36 37 # Check if the RAID-Z parity is valid 38 if [ $RAIDZ_PARITY -lt 1 ]; then 39 echo "RAID-Z parity must be 1 or greater" 40 exit 1 41 fi 42 } 43 44 45 setup_zfs() { 46 # Validation 47 check 48 49 # Generate the hostid 50 source /etc/os-release 51 export ID 52 zgenhostid -f 0x00bab10c 53 54 # Prepare the boot drive 55 wipefs -a $BOOT_DRIVE 56 sgdisk --zap-all $BOOT_DRIVE 57 sgdisk -n "1:1m:+1g" -t "1:ef00" $BOOT_DRIVE 58 59 # Prepare the ZFS pool drives 60 for d in $POOL_DRIVES; do 61 wipefs -a $d 62 sgdisk --zap-all $d 63 sgdisk -n "1:0:-10m" -t "1:bf00" "$d" 64 if zdb -l "$d" &> /dev/null; then 65 zpool labelclear -f "$d" 66 fi 67 done 68 69 # Create the ZFS pool (should we use noatime=on instead of relatime=on?) 70 ZFS_POOL_DRIVES=$(echo $(for dev in $POOL_DRIVES; do find /dev/disk/by-id/ -samefile $(readlink -f "$dev") ! -name "*-part*" -print -quit; done)) 71 zpool create -f -o ashift=12 -O compression=lz4 -O acltype=posixacl -O xattr=sa -O relatime=on -o autotrim=on -o compatibility=openzfs-2.1-linux -m none zroot raidz${RAIDZ_PARITY} $ZFS_POOL_DRIVES 72 73 # Create the ZFS datasets 74 zfs create -o mountpoint=none zroot/ROOT 75 zfs create -o mountpoint=/ -o canmount=noauto zroot/ROOT/$ID 76 zfs create -o mountpoint=/home zroot/home 77 zpool set bootfs=zroot/ROOT/$ID zroot 78 79 # Export and import the ZFS pool 80 zpool export zroot 81 zpool import -N -R /mnt zroot 82 zfs mount zroot/ROOT/$ID 83 zfs mount zroot/home 84 85 # Trigger udev 86 udevadm trigger 87 88 # Install base system 89 XBPS_ARCH=x86_64 xbps-install -S -R https://mirrors.servercentral.com/voidlinux/current -r /mnt base-system 90 91 # Copy the hostid into the new system 92 cp /etc/hostid /mnt/etc 93 94 # Chroot into the new system 95 echo "entering the void..." 96 xchroot /mnt 97 } 98 99 100 setup_chroot() { 101 # Set the root password 102 echo "root:root" | chpasswd 103 104 # Update the package manager and install some basic packages 105 xbps-install -Suy nano wget 106 107 # Install the non-free repository 108 xbps-install -y void-repo-nonfree 109 xbps-install -Suy 110 111 # Install & enable the intel microcode service 112 xbps-install -y intel-ucode 113 ln -sf /etc/sv/intel-ucode /etc/runit/runsvdir/default/ 114 115 # Set the timezone & hardware clock 116 ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime 117 hwclock --systohc 118 119 # Set the hostname 120 echo "$HOSTNAME" > /etc/hostname 121 122 # Set the rc.conf variables 123 printf "HOSTNAME=\"$HOSTNAME\"\nHARDWARECLOCK=\"UTC\"\nTIMEZONE=\"America/New_York\"\nKEYMAP=us\n" > /etc/rc.conf 124 125 # Set nameservers 126 printf "nameserver 9.9.9.9" > /etc/resolv.conf 127 128 # Set the locales 129 printf "en_US.UTF-8 UTF-8\nen_US ISO-8859-1\n" > /etc/default/libc-locales 130 xbps-reconfigure -f glibc-locales 131 132 # Set the dracut configuration 133 printf "nofsck=\"yes\"\nadd_dracutmodules+=\" zfs \"\nomit_dracutmodules+=\" btrfs \"\n" > /etc/dracut.conf.d/zol.conf 134 135 # Install the zfs package 136 xbps-install -y zfs 137 138 # Set the zfsbootmenu command line options 139 zfs set org.zfsbootmenu:commandline="quiet loglevel=4" zroot/ROOT 140 141 # Setup & mount the boot partition 142 mkfs.vfat -F32 ${BOOT_DRIVE}1 143 BOOT_UUID=$(blkid -s UUID -o value ${BOOT_DRIVE}1) 144 echo "UUID=$BOOT_UUID /boot/efi vfat defaults 0 0" > /etc/fstab 145 mkdir -p /boot/efi 146 mount /boot/efi 147 148 # Install and setup zfsbootmenu 149 xbps-install -S zfsbootmenu gummiboot-efistub yq 150 yq -iy '.Global.ManageImages=true | .Global.BootMountPoint="/boot/efi" | .Components.Enabled=false | .EFI.ImageDir="/boot/efi/EFI/zbm" | .EFI.Versions=false | .EFI.Enabled=true | .Kernel.CommandLine="quiet loglevel=0"' /etc/zfsbootmenu/config.yaml 151 generate-zbm 152 153 # Apply boot method 154 # Note : Some systems can have issues with EFI boot entries, you might need to use a well-known EFI file name. 155 # Reference : https://docs.zfsbootmenu.org/en/v2.3.x/general/portable.html 156 if [ $BOOT_METHOD == "direct" ]; then 157 xbps-install efibootmgr 158 efibootmgr -c -d "$BOOT_DRIVE" -p "1" -L "ZFSBootMenu (Backup)" -l '\EFI\ZBM\VMLINUZ-BACKUP.EFI' 159 efibootmgr -c -d "$BOOT_DRIVE" -p "1" -L "ZFSBootMenu" -l '\EFI\ZBM\VMLINUZ.EFI' 160 elif [ $BOOT_METHOD == "refind" ]; then 161 xbps-install -y refind 162 refind-install 163 rm /boot/refind_linux.conf 164 printf "\"Boot default\" \"quiet loglevel=0 zbm.skip\"\n\"Boot to menu\" \"quiet loglevel=0 zbm.show\"\n" > /boot/efi/EFI/ZBM/refind_linux.conf 165 # Note : Everything below this line is a "hacky" solution to a problem I was having with the zfsbootmenu package 166 # Reference: https://github.com/zbm-dev/zfsbootmenu/issues/293 167 mkdir -p /boot/efi/EFI/BOOT 168 mvrefind /boot/efi/EFI/refind /boot/efi/EFI/BOOT 169 temp=$(mktemp -d) 170 wget -O $temp/latest.tar.gz https://get.zfsbootmenu.org/latest.tar.gz 171 tar xvf $temp/latest.tar.gz -C $temp/ 172 rm $temp/latest.tar.gz 173 mv $temp/zfs*/* /boot/efi/EFI/ZBM/ 174 rm /boot/efi/EFI/ZBM/vmlinuz.efi 175 xbps-remove zfsbootmenu 176 fi 177 178 # Reconfigure the system 179 xbps-reconfigure -fa 180 181 # Exit the chroot environment 182 echo "exiting the void..." 183 exit 184 } 185 186 187 188 # Check the command 189 if [ "$#" -ne 1 ]; then 190 echo "usage: $0 [zfs|chroot|final]" 191 exit 1 192 fi 193 194 # Execute the command 195 case "$1" in 196 zfs) setup_zfs ;; 197 chroot) setup_chroot ;; 198 final) umount -n -R /mnt; zpool export zroot; reboot ;; 199 *) echo "usage: $0 [zfs|chroot|final]" && exit 1 ;; 200 esac