Skip to content

Instantly share code, notes, and snippets.

@mharsch
Last active December 29, 2023 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mharsch/90ef6412fcc2f0ae28b2f47917eabe9d to your computer and use it in GitHub Desktop.
Save mharsch/90ef6412fcc2f0ae28b2f47917eabe9d to your computer and use it in GitHub Desktop.
wipe and prep drives for replotting
#!/bin/bash
# Script for wiping old plot directories and prepping drives for new plots
# Pause between steps in case something goes wrong (Ctrl-C to bail out)
RANGE=sdb[g-j]
DEVS=/dev/$RANGE
DEVS_SCHED=/sys/block/${RANGE}/queue/scheduler
PARTS=/dev/${RANGE}1
OLD_DIRS=/plots/${RANGE}1
NEW_DIRS=/gplots/${RANGE}1
echo "removing old plot dirs from chia"
for i in $OLD_DIRS;do echo $i; chia plots remove -d $i; done
read -p "Continue?"
echo "unmounting old plot dirs"
for i in $OLD_DIRS;do echo $i; sudo umount $i; done
read -p "Continue?"
echo "removing old partitions"
for i in $DEVS;do echo $i; sudo parted -s $i rm 1; done
read -p "Continue?"
echo "rewriting partition tables"
for i in $DEVS;do echo $i; sudo parted -s $i mklabel gpt; done
read -p "Continue?"
echo "switch to bfq io scheduler (for transition period)"
sudo modprobe bfq-iosched
for i in $DEVS_SCHED;do echo "bfq" |sudo tee $i; done
read -p "Continue?"
echo "make one big partition to fill each drive"
for i in $DEVS;do echo $i; sudo parted -s --align=optimal $i mkpart primary 0% 100%; done
read -p "Continue?"
echo "formatting new partitions"
for i in $PARTS;do echo $i; sudo mkfs.ext4 -F -m 0 -O extent,^has_journal,sparse_super2 -T largefile4 $i; done
read -p "Continue?"
echo "mounting new partitions"
for i in $PARTS;do echo $i; sudo mount -o noatime $i $(echo $i|sed 's/dev/gplots/'); done
read -p "Continue?"
echo "setting permissions on new mounts"
for i in $NEW_DIRS;do echo $i; sudo chown -R $USER:$USER $i; done
echo "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment