Skip to content

Instantly share code, notes, and snippets.

View 0xf10e's full-sized avatar
😶
I may be slow to respond.

Florian Ermisch 0xf10e

😶
I may be slow to respond.
View GitHub Profile
@0xf10e
0xf10e / .sh
Created August 3, 2015 17:53
So easy to get all the info you need for a $POOL-$POSITION-$SERIAL label with mfiutil(8) and mfi(4)/mrsas(4)
~% POOL=foobar; sudo mfiutil -u 1 show drives | sed -ne 's/ *\([0-9]*\) (.*serial=\([A-Z0-9]*\)> SCSI-[0-9]* \(E[0-9]*:S[0-9]*\)/ID=\1 SERIAL=\2 POS=\3/p'| while read LINE; do eval "$LINE"; DEV=`dmesg | sed -ne "/deviceid: $ID)/s/\(mfi[^:]*\):.*/\1/p" | tail -n 1`; echo $DEV has serial $SERIAL, located in $POS:; gpart
list $DEV 2> /dev/null | grep label: || ( sudo gpart show $DEV || ( sudo gpart create -s gpt $DEV && sudo gpart add -a 1M -t freebsd-zfs -s 3700GB -l $POOL-`printf %02d "${POS#*S}"`-$SERIAL $DEV) ); done