void

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

zbm (4658B)

      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 	printf "HOSTNAME=\"$HOSTNAME\"\nHARDWARECLOCK=\"UTC\"\nTIMEZONE=\"America/New_York\"\nKEYMAP=us\n" > /etc/rc.conf
     90 
     91 	printf "en_US.UTF-8 UTF-8\nen_US ISO-8859-1\n" > /etc/default/libc-locales
     92 	xbps-reconfigure -f glibc-locales
     93 
     94 	printf "nofsck=\"yes\"\nadd_dracutmodules+=\" zfs \"\nomit_dracutmodules+=\" btrfs \"\n" > /etc/dracut.conf.d/zol.conf
     95 
     96 	xbps-install -y zfs
     97 	zfs set org.zfsbootmenu:commandline="quiet loglevel=4" zroot/ROOT
     98 
     99 	mkfs.vfat -F32 ${BOOT_DRIVE}1
    100 	BOOT_UUID=$(blkid -s UUID -o value ${BOOT_DRIVE}1)
    101 	echo "UUID=$BOOT_UUID /boot/efi vfat defaults 0 0" > /etc/fstab
    102 	mkdir -p /boot/efi
    103 	mount /boot/efi
    104 
    105 	# Everything below this line is a "hacky" solution to a problem I was having with the zfsbootmenu package
    106 	# https://github.com/zbm-dev/zfsbootmenu/issues/293
    107 	# The developers of zfsbootmenu are rude and unhelpful, so I had to figure this out on my own:
    108 	#	12:39 -- Mode #zfsbootmenu [+b *!*@big.dick.acid.vegas] by zdykstra
    109 	#	12:39 ◀▬▬ zdykstra has kicked acidvegas (acidvegas)
    110 	#	12:39 -- #zfsbootmenu: Cannot join channel (+b) - you are banned
    111 
    112 	xbps-install -S zfsbootmenu gummiboot-efistub yq
    113 	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
    114 	generate-zbm
    115 
    116 	xbps-install -y refind
    117 	refind-install
    118 	rm /boot/refind_linux.conf
    119 	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
    120 
    121 	mkdir -p /boot/efi/EFI/BOOT
    122 	mvrefind /boot/efi/EFI/refind /boot/efi/EFI/BOOT
    123 	temp=$(mktemp -d)
    124 	wget -O $temp/latest.tar.gz https://get.zfsbootmenu.org/latest.tar.gz
    125 	tar xvf $temp/latest.tar.gz -C $temp/
    126 	rm $temp/latest.tar.gz
    127 	mv $temp/zfs*/* /boot/efi/EFI/ZBM/
    128 	rm /boot/efi/EFI/ZBM/vmlinuz.efi
    129 
    130 	xbps-remove zfsbootmenu
    131 	xbps-reconfigure -fa
    132 
    133 	exit
    134 }
    135 
    136 
    137 
    138 if [ "$#" -ne 1 ]; then
    139 	printf "usage: $0 [zfs|chroot|final]\n"
    140 	exit 1
    141 fi
    142 
    143 case "$1" in
    144 	zfs)    setup_zfs ;;
    145 	chroot) setup_chroot ;;
    146 	final)  umount -n -R /mnt; zpool export zroot; reboot ;;
    147 	*)      printf "usage: $0 [zfs|chroot|final]\n"; exit 1 ;;
    148 esac