gpu_server_setup/setup_bcache.sh

57 lines
1.6 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
ssddev=/dev/sdb
hdddev=/dev/sdc
sequential_cutoff=24000M
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
while [ -b /dev/bcache0 ]
then echo "Canceld, device /dev/bcache0 is allready present"
exit
fi
echo "Setup bcache... "
apt-get update && \
apt-get install -y bcache-tools && \
dd if=/dev/zero if=$ssddev bs=512 count=8 && \
dd if=/dev/zero if=$hdddev bs=512 count=8 && \
wipefs -a $ssddev && \
wipefs -a $hdddev && \
make-bcache -C $ssddev -B $hdddev --writeback && \
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
if [ $? -eq 0 ]; then
echo "Wait until device is ready... "
while [ ! -b /dev/bcache0 ]; do sleep 1; done
echo "Fromat and mount bcache device... "
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 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