From d366f450d6a2ee8eaf79f336c17008b19ad64543 Mon Sep 17 00:00:00 2001 From: kneutron <50146127+kneutron@users.noreply.github.com> Date: Tue, 13 Jul 2021 00:15:04 -0500 Subject: [PATCH] Add files via upload --- ZFS/drive-slicer-get-longform.sh | 41 ++++++++++++++++++++++++++++++++ ZFS/zfs-drive-slicer.sh | 18 +++++++++----- 2 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 ZFS/drive-slicer-get-longform.sh diff --git a/ZFS/drive-slicer-get-longform.sh b/ZFS/drive-slicer-get-longform.sh new file mode 100644 index 0000000..9af69d8 --- /dev/null +++ b/ZFS/drive-slicer-get-longform.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +# 2021 Dave Bechtel +# REQUIRES output file from zfs-drive-slicer.sh, sed, awk, grep, head + +# Translate short-form disks +#sdb sdc sdd sde sdf sdg sdh sdi sdj sdk sdl +# To long-form: +#pci-0000:00:16.0-sas-phy0-lun-0 pci-0000:00:16.0-sas-phy1-lun-0 pci-0000:00:16.0-sas-phy2-lun-0 pci-0000:00:16.0-sas-phy3-lun-0 pci-0000:00:16.0-sas-phy4-lun-0 pci-0000:00:16.0-sas-phy5-lun-0 pci-0000:00:16.0-sas-phy6-lun-0 pci-0000:00:16.0-sas-phy7-lun-0 pci-0000:00:16.0-sas-phy8-lun-0 pci-0000:00:16.0-sas-phy9-lun-0 pci-0000:00:16.0-sas-phy10-lun-0 + +# Useful when creating ZFS arrays +# Pseudocode: +# get zfs-drive-slicer output file +# use sed to delete line cont chars out +# read a line +## for every word in line; lookup + print dev/disk/by-path equivalent no-newline +# at line end print line continuation char + +DBP=/dev/disk/by-path +DBI=/dev/disk/by-id +usetype=$DBP +# ^^ TODO EDITME + +# NOTE WARNING when using SAS disks we are NOT guaranteed an entry in disk-by-id! + +infile=/tmp/zfsds.txt +[ "$1" = "" ] || infile="$1" # override, if 1st arg passed + +sed -i 's/\\//g' "$infile" # remove line-continuation chars + +# set -x ## DEBUG +while read inline; do + for word in $inline; do + printf $(ls -l $usetype |grep -w /$word |awk '{print $9}' |head -n 1)" " + done + echo ' \' +done < $infile +# NOTE ^^ this may be inaccurate, no error checking for missing disks, just print what we find + +#lrwxrwxrwx 1 root root 9 Jul 12 23:10 pci-0000:00:16.0-sas-phy9-lun-0 -> ../../sdk +# 1 2 3 4 5 j 7 8 9 diff --git a/ZFS/zfs-drive-slicer.sh b/ZFS/zfs-drive-slicer.sh index 66f5cb6..7ba70d5 100644 --- a/ZFS/zfs-drive-slicer.sh +++ b/ZFS/zfs-drive-slicer.sh @@ -4,12 +4,13 @@ # DONE [b..y] a[a..x] get slices of X disks and be able to verify with wc -w # REQUIRES: seq -echo "$0 - 2021 Dave Bechtel" -echo "Pass arg1=total disks in pool -- arg2=how many disks per vdev" -# NOTE arg2 ^^ should factor in the RAIDz level 1/2/3 desired to sustain X number of failed disks per vdev + vspares, -# dont go too narrow or will lose capacity - -echo "NOTE output lines should be the same number of devices to balance" +# Trick to put header outside of col -t +>&2 echo "$0 - 2021 Dave Bechtel" +>&2 echo "Pass arg1=total disks in pool -- arg2=how many disks per vdev" +>&2 echo "+ NOTE arg2 ^^ should factor in the RAIDz level 1/2/3 desired to sustain X number" +>&2 echo "+ of failed disks per vdev + vspares, dont go too narrow or will lose capacity" +>&2 echo "NOTE output lines should be the same number of devices to balance" +>&2 echo "PROTIP: Pipe output to column -t to make it look nice" # REF: https://tldp.org/LDP/abs/html/arrays.html # regular array - STARTS AT 0 @@ -112,3 +113,8 @@ slice $1 $2 # 14 # 14 # 14 + + +# HOWTO get long-form disks: +# use drive-slicer-get-longform.sh +# ^ Requires output from this script