#!/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 #Name of the mounted device: mountname=/mnt/bcache #Cache setting for sequential writes #There is an issue with parsing prefixes, max 4 GB, use 0 for no cutoff sequential_cutoff=0 set -e 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 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 echo "Wait until device is ready... " while [ ! -b /dev/bcache0 ]; do sleep 1; done echo echo "Config 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 echo echo "Format and mount bcache device..." mkfs.ext4 /dev/bcache0 mkdir $mountname mount /dev/bcache0 $mountname echo "/dev/bcache0 $mountname ext4 rw 0 0" >> /etc/fstab echo echo "Config default home directory for new users on bcache partition... " echo "home path of exising users will not be moved automaticaly" mkdir $mountname/home echo "#" >> /etc/default/useradd echo "# Modifications:" >> /etc/default/useradd echo "HOME=$mountname/home" >> /etc/default/useradd echo echo "Setup successfully finished"