Last active
April 21, 2019 03:46
-
-
Save TheAnonymous/5787963 to your computer and use it in GitHub Desktop.
Making a SSD working as a Cache for a HDD with bcache.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There are 3 Methods for using a SSD as cache. | |
dm-cache, bcache,enhance-io all three should be avaliable in Kernel Version 3.10. | |
Performance differenceses are discussed here => http://lkml.indiana.edu/hypermail/linux/kernel/1306.1/01246.html | |
In this tutorial I will use bcache since dm-cache didn't worked for me. | |
At the moment there is only an rc5 candidate for kernel 3.10.0 | |
How to compile it is explained below. If you have a newer kernel than 3.10 and it is bcache enabled you dont need to compile it by yourself. In this case just jump over the kernel-compile-exlanation. If your kernel is compiled with bcache support you can test with "modprobe bcache". If that doesnt throw an error it should work :) | |
I will link to the tutorials I used. If you found better ones please paste a link in the comments | |
How to compile a kernel by yourself is explained at: | |
=> http://bodhizazen.net/Tutorials/kernel | |
I used Fedora 18. If you got it done in another distribution you may want to do a fork of this tutorial and change the stepps which differs. | |
In short the steps are: | |
sudo yum-builddep kernel | |
sudo yum install xz tar ncurse | |
wget https://www.kernel.org/pub/linux/kernel/v3.x/testing/linux-3.10-rc5.tar.xz | |
tar xvf linux-3.10-rc5.tar.xz | |
cd linux-3.10-rc5 | |
make oldconfig | |
hold enter until everything is choosen | |
make menuconfig | |
go to "device drivers" -> "Multiple devices driver support (RAID and LVM)" -> "Block device as cache" enable it! | |
save and exit | |
make -j20 | |
make -j20 modules | |
sudo make modules_install | |
sudo cp arch/x86/boot/bzImage /boot/vmlinuz-3.10.0-rc5 | |
sudo cp System.map /boot/System.map-3.10.0-rc5 | |
sudo cp .config /boot/config-3.10.0-rc5 | |
sudo dracut /boot/initramfs-3.10.0-rc5.img 3.10.0-rc5 | |
sudo grub2-mkconfig -o /boot/grub2/grub.cfg #this path can be other just search for grub.cfg in /boot " find /boot -iname grub.cfg" #this differs from the tutorial because the tutorial is for an old Fedora Version | |
Now try to reboot and test if the new kernel boots | |
when this works you are done half of the way | |
You now need a clear SSD and a clear partition on the HDD you want to cache. | |
But first things first. | |
sudo yum install git libuuid libuuid-devel | |
git clone http://evilpiepirate.org/git/bcache-tools.git | |
cd bcache-tools | |
make | |
sudo make install | |
this should it be. | |
Now you can follow http://atlas.evilpiepirate.org/git/linux-bcache.git/tree/Documentation/bcache.txt?h=bcache-dev | |
In short: #Please of course use the devicenames of your own devices! | |
modprobe bcache | |
make-bcache -B /dev/mapper/fedora_virthost-home | |
make-bcache -C /dev/sda1 | |
modprobe bcache | |
echo /dev/mapper/fedora_virthost-home > /sys/fs/bcache/register | |
echo /dev/sda1 > /sys/fs/bcache/register | |
mkfs.ext4 /dev/bcache0 | |
mount /dev/bcache0 /home #you can mount it whereever you want it! | |
ls /sys/fs/bcache/ #get uuid | |
echo 766e3ca5-f2db-44c9-97cc-13a97b32d348 > /sys/block/bcache0/bcache/attach #The number is the uuid from previous step | |
Now you should have a working partition in /home (or whereever you mounted it) | |
But this is just till the next reboot | |
so lets make it peresistent | |
place the following script in /etc/init.d/bcache | |
cd /etc/init.d/ | |
sudo yum install nano | |
nano bcache | |
and copy everything between the lines in the file... | |
customise the marked lines | |
------------------ | |
#!/bin/bash | |
# chkconfig: 2345 20 80 | |
# description: Mounting bcache on /home | |
# Source function library. | |
. /etc/init.d/functions | |
start() { | |
modprobe bcache | |
echo /dev/mapper/fedora_virthost-cache > /sys/fs/bcache/register #please customise!!!! | |
echo /dev/sda1 > /sys/fs/bcache/register #please customise!!!! | |
mount /dev/bcache0 /home #please customise!!!! | |
} | |
stop() { | |
umount /dev/bcache0 /home #please customise!!!! | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart) | |
stop | |
start | |
;; | |
*) | |
echo "Usage: $0 {start|stop|restart}" | |
esac | |
exit 0 | |
------------------ | |
close and save (Strg + x and enter) | |
chmod +x bcache | |
systemctl enable bcache.service | |
reboot | |
now we test if it is there again with | |
df -h|grep bcache | |
there should be something like this | |
/dev/bcache0 852G 255G 554G 32% /home | |
Thats it have fun. | |
Thanks for all the tutorials/websites i used below. | |
https://wiki.archlinux.org/index.php/Bcache | |
http://unix.stackexchange.com/questions/62501/where-can-i-find-a-good-tutorial-for-installing-bcache | |
http://atlas.evilpiepirate.org/git/linux-bcache.git/tree/Documentation/bcache.txt?h=bcache-dev | |
http://bcache.evilpiepirate.org/#index2h3 | |
http://evilpiepirate.org/git/bcache-tools.git | |
http://evilpiepirate.org/git/linux-bcache.git | |
http://lkml.indiana.edu/hypermail/linux/kernel/1306.1/01246.html | |
http://bodhizazen.net/Tutorials/kernel | |
https://www.kernel.org/ | |
I not tested the tutorial so I may forgot a step. If that happend or you find a bug please let me know in the comments! | |
I will correct it. | |
I just didn't found a straight forward tutorial so I made one after I got it done. | |
So all these steps are reproduced and NOT tested! | |
Have fun Jakob Oesterling |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment