gpu_server_setup/setup_bcache.sh

71 lines
2.1 KiB
Bash

#!/bin/bash
#sources:
#https://wiki.archlinux.org/title/bcache
#https://stackoverflow.com/questions/20797819/command-to-change-the-default-home-directory-of-a-user
#https://unix.stackexchange.com/questions/156102/optimizing-bcache
#https://evilpiepirate.org/git/linux-bcache.git/tree/Documentation/bcache.txt
#Block device for caching (e.g. disk or partition):
ssddev=/dev/sdb
#Block device to use with cache:
hdddev=/dev/sdc
#Cache sequential writes files, no cutoff
#There is an issue with parsing of prefixes, max 4 GB
sequential_cutoff=0
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit
fi
read -p "Block devices $ssddev and $hdddev will be wiped, are you sure proceed?" -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit
fi
while [ -b /dev/bcache0 ]; then
echo "Canceld, device /dev/bcache0 is allready present"
exit
fi
echo "Clean disks and setup bcache... "
dd if=/dev/zero of=$ssddev bs=512 count=8 && \
dd if=/dev/zero of=$hdddev bs=512 count=8 && \
wipefs -a $ssddev && \
wipefs -a $hdddev && \
apt-get update && \
apt-get install -y bcache-tools && \
make-bcache -C $ssddev -B $hdddev --writeback
echo "Wait until device is ready... "
while [ ! -b /dev/bcache0 ]; do sleep 1; done
if [ $? -eq 0 ]; then
echo "Config, format and mount bcache device... "
echo $sequential_cutoff > /sys/block/bcache0/bcache/sequential_cutoff && \
echo "ACTION==\"add\", SUBSYSTEM==\"block\", ENV{MAJOR}==\"252\", ATTR{bcache/sequential_cutoff}=\"$sequential_cutoff\"" \
> /etc/udev/rules.d/99-bcache_sequential_cutoff.rules && \
udevadm test /sys/block/bcache0 && \
mkfs.ext4 /dev/bcache0 && \
mkdir /mnt/bcache && \
mount /dev/bcache0 /mnt/bcache && \
echo "/dev/bcache0 /mnt/bcache ext4 rw 0 0" >> /etc/fstab
fi
if [ $? -eq 0 ]; then
echo "Config default home directory for new users on bcache partition... "
mkdir /mnt/bcache/home && \
echo "#" >> /etc/default/useradd && \
echo "# Modifications:" >> /etc/default/useradd && \
echo "HOME=/mnt/bcache/home" >> /etc/default/useradd
fi
if [ $? -eq 0 ]; then
echo ""
echo "Setup successfully finished"
fi