void

- enter the void 🪐
git clone git://git.acid.vegas/archlinux.git
Log | Files | Refs | Archive

enterthezoid (4961B)

      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.2.x/guides/void-linux/uefi.html
      5 #            https://docs.zfsbootmenu.org/en/v2.3.x/guides/void-linux/uefi.html (do we need to make any updates?)
      6 
      7 set -xev
      8 
      9 # Configuration
     10 HOSTNAME=blackhole
     11 BOOT_DRIVE=/dev/sde # Use the internal USB drive for the boot partition
     12 POOL_DRIVES="/dev/sda /dev/sdb /dev/sdc /dev/sdd" # Verify these with lsblk before running
     13 
     14 
     15 convert_pool_drives() {
     16     local devices=$1
     17     local by_id_drives=""
     18 
     19     for dev in $devices; do
     20         local device_by_id_path=""
     21         for id in /dev/disk/by-id/*; do
     22             if [ "$(readlink -f "$id")" = "$(readlink -f "$dev")" ] && ! [[ $id =~ .*-part[0-9]+ ]]; then
     23                 device_by_id_path="$id"
     24                 break
     25             fi
     26         done
     27         by_id_drives+="${device_by_id_path} "
     28     done
     29 
     30     echo $by_id_drives
     31 }
     32 
     33 
     34 setup_zfs() {
     35 	source /etc/os-release
     36 	export ID
     37 	zgenhostid -f 0x00bab10c
     38 
     39 	wipefs -a $BOOT_DRIVE
     40 	sgdisk --zap-all $BOOT_DRIVE
     41 	sgdisk -n "1:1m:+1g" -t "1:ef00" "$BOOT_DRIVE"
     42 
     43 	for d in $POOL_DRIVES; do
     44 		wipefs -a $d
     45 		sgdisk --zap-all $d
     46 		sgdisk -n "1:0:-10m" -t "1:bf00" "$d"
     47 		if zdb -l "$d" &> /dev/null; then
     48 			zpool labelclear -f "$d"
     49 		fi
     50 	done
     51 
     52 	POOL_DRIVES=$(convert_pool_drives "$POOL_DRIVES")
     53 	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 $POOL_DRIVES
     54 
     55 	zfs create -o mountpoint=none zroot/ROOT
     56 	zfs create -o mountpoint=/ -o canmount=noauto zroot/ROOT/$ID
     57 	zfs create -o mountpoint=/home zroot/home
     58 	zpool set bootfs=zroot/ROOT/$ID zroot
     59 
     60 	zpool export zroot
     61 	zpool import -N -R /mnt zroot
     62 	zfs mount zroot/ROOT/$ID
     63 	zfs mount zroot/home
     64 
     65 	udevadm trigger
     66 
     67 	XBPS_ARCH=x86_64 xbps-install -S -R https://mirrors.servercentral.com/voidlinux/current -r /mnt base-system
     68 	cp /etc/hostid /mnt/etc
     69 
     70 	xchroot /mnt
     71 }
     72 
     73 
     74 setup_chroot() {
     75 	passwd
     76 
     77 	xbps-install -Suy
     78 
     79 	xbps-install -y void-repo-nonfree
     80 	xbps-install -Suy
     81 	xbps-install -y intel-ucode
     82 	ln -sf /etc/sv/intel-ucode /etc/runit/runsvdir/default/
     83 
     84 	ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime
     85 	ln -sf /etc/sv/dhcpcd /etc/runit/runsvdir/default/
     86 	hwclock --systohc
     87 	printf "$HOSTNAME\n" > /etc/hostname
     88 
     89 	# CGROUP_MODE="unified" is required on Void to fix a bug with incus expecting systemd (https://github.com/lxc/incus/issues/625#issuecomment-2153154219)
     90 	# Temporary solution:
     91 	#	mkdir /sys/fs/cgroup/systemd
     92 	#	mount -t cgroup -o none,name=systemd systemd /sys/fs/cgroup/systemd 
     93 	printf "HOSTNAME=\"$HOSTNAME\"\nHARDWARECLOCK=\"UTC\"\nTIMEZONE=\"America/New_York\"\nKEYMAP=us\nCGROUP_MODE=\"unified\"" > /etc/rc.conf
     94 
     95 	printf "en_US.UTF-8 UTF-8\nen_US ISO-8859-1\n" > /etc/default/libc-locales
     96 	xbps-reconfigure -f glibc-locales
     97 
     98 	printf "nofsck=\"yes\"\nadd_dracutmodules+=\" zfs \"\nomit_dracutmodules+=\" btrfs \"\n" > /etc/dracut.conf.d/zol.conf
     99 
    100 	xbps-install -y zfs
    101 	zfs set org.zfsbootmenu:commandline="quiet loglevel=4" zroot/ROOT
    102 
    103 	mkfs.vfat -F32 ${BOOT_DRIVE}1
    104 	BOOT_UUID=$(blkid -s UUID -o value ${BOOT_DRIVE}1)
    105 	echo "UUID=$BOOT_UUID /boot/efi vfat defaults 0 0" > /etc/fstab
    106 	mkdir -p /boot/efi
    107 	mount /boot/efi
    108 
    109 	# Everything below this line is a "hacky" solution to a problem I was having with the zfsbootmenu package
    110 	# https://github.com/zbm-dev/zfsbootmenu/issues/293
    111 	# The developers of zfsbootmenu are rude and unhelpful, so I had to figure this out on my own:
    112 	#	12:39 -- Mode #zfsbootmenu [+b *!*@big.dick.acid.vegas] by zdykstra
    113 	#	12:39 ◀▬▬ zdykstra has kicked acidvegas (acidvegas)
    114 	#	12:39 -- #zfsbootmenu: Cannot join channel (+b) - you are banned
    115 
    116 	xbps-install -S zfsbootmenu gummiboot-efistub yq
    117 	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
    118 	generate-zbm
    119 
    120 	xbps-install -y refind
    121 	refind-install
    122 	rm /boot/refind_linux.conf
    123 	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
    124 
    125 	mkdir -p /boot/efi/EFI/BOOT
    126 	mvrefind /boot/efi/EFI/refind /boot/efi/EFI/BOOT 
    127 	temp=$(mktemp -d)
    128 	wget -O $temp/latest.tar.gz https://get.zfsbootmenu.org/latest.tar.gz
    129 	tar xvf $temp/latest.tar.gz -C $temp/
    130 	rm $temp/latest.tar.gz
    131 	mv $temp/zfs*/* /boot/efi/EFI/ZBM/
    132 	rm /boot/efi/EFI/ZBM/vmlinuz.efi
    133 
    134 	xbps-remove zfsbootmenu
    135 	xbps-reconfigure -fa
    136 
    137 	exit
    138 }
    139 
    140 
    141 
    142 if [ "$#" -ne 1 ]; then
    143 	printf "usage: $0 [zfs|chroot|final]\n"
    144 	exit 1
    145 fi
    146 
    147 case "$1" in
    148 	zfs)    setup_zfs ;;
    149 	chroot) setup_chroot ;;
    150 	final)  umount -n -R /mnt; zpool export zroot; reboot ;;
    151 	*)      printf "usage: $0 [zfs|chroot|final]\n"; exit 1 ;;
    152 esac