I'm setting up bcache on ubuntu 20.04.
Booting from install CD, I created a bcache dirve by:
#modprobe bcache
#make-bcache -B /dev/mapper-vgubuntu-root
#make-bcache -C /dev/sdb
Just after that #fdisk -l
showed /dev/bcache0
.
Then #mkfs.ext4 /dev/bcache0
and put all the files back from the backup.tar to the root of /dev/bcache
.
Editted /etc/fstab like:
UUID=------- / ext4 erros=remount-ro 0 1
Then I updated grub by:
#mount -t ext4 /dev/bcache /mnt
#munt -B /dev /mnt/dev
#mount -B /proc /mnt/proc
#mount -B /sys /mnt/sys
#grub-install --recheck /dev/sda
#update-grub
Then I tried to restart the system from the new root /dev/bcache0
.
However, it fell into grub-rescue>
,
saying "unknown file system UUID=-----".
I restarted the system from the install CD and checked whether or not the system recognized /dev/bcahe0
.
#fdisk -l
showed that the system didin't recognize it after boot.
Then
#modprobe bcache
#echo /dev/dm-0 > /sys/fs/bcache/register
#echo /dev/sdb > /sys/fs/bcache/register
With these commands fdisk -l
showed /dev/bcache0
.
/dev/mapper/vgubuntu-root
is recognized as /dev/dm-0
.
From the situation mentioned above, I think I have to update the initrd.img to execute the above scripts before the file system is mounted.
So I added bcache in /etc/initramfs-tools/modules
and wrote the following script to a file in /etc/initramfs-tools/scripts/init-premount/:
#! /bin/sh
echo /dev/dm-0 > /sys/fs/bcache/register
echo /dev/sdb > /sys/fs/bcache/register
I named the file 10_bcache.
Finally I update-initramfs
and then restarted the system, however, the system still doesn't recognize /dev/bcache0
and falls into grub rescue mode.
How should I update-initramfs to recognize the bcache device before the system mounts the file system.
I've solved this by myself. The cause of the problem is that
/boot
was put in the bcache drive since I installed 20.04 with default settings. Unless initrd.img is loaded, the bcache drive is not recognized and grub cannot find/boot
in it.Now I put
/boot
outside the bcache drive and grub can find it and boot the system.The followings are the way I set up bcache.
First, I manually partitioned the hdd with fdisk.
Second, logical volumes were created by:
fdisk -l
shows the result:Then a bcache drive was created by:
/dev/sdc
is the SSD.fdisk -l
shows:In order to install the system in
/dev/bcache0
a partition was made in it byfdisk /dev/bcache0
.fdisk -l
shows:After the preparation mentioned above, I installed the system using the advanced disk setting menu in the installer, where I set the mount points as the following.
After the installation, I rebuilt initramfs in order for the system to recognize the bcache drive before mounting root file system. I editted a file and added a script in
/etc/initramfs-tools/
./etc/initramfs-tools/modules
/etc/initramfs-tools/scripts/init-premount/10_bcache
Under the above settings
# update-initramfs
was done.Without the latter script the system falls into BusyBox and you have to execute the above scripts manually because bcache drive doesn't appear until the scripts are executed. I learned this operation from https://wiki.archlinux.org/index.php/Bcache.
And
/etc/fstab
is:This is all the things I've done for bcache to work in my system. These are much more complicated than using lvm or mdadm. No.1 reason is that the bcache drive is used for the root file system, which has to be recognized before initramfs mounts file systems. In addition, initramfs has to be placed in an ordinary separate drive outside the bcache drive.
So, if you use bcache drives other than root file system, such as
/home
,it will be much easier.