我要在ubuntu20.04上设置bcache。
从安装CD启动时,我通过以下方式创建了一个bcache:
#modprobe bcache
#make-bcache -B /dev/mapper-vgubuntu-root
#make-bcache -C /dev/sdb就在那之后,#fdisk -l向/dev/bcache0展示了。然后是#mkfs.ext4 /dev/bcache0
并将所有文件从backup.tar返回到/dev/bcache的根目录。
编组的/etc/fstab样的:
UUID=------- / ext4 erros=remount-ro 0 1然后我通过以下方式更新了grub:
#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然后,我尝试从新的根/dev/bcache0重新启动系统。然而,它落入了grub-rescue>,
说“未知文件系统UUID=-”。
我从安装CD重新启动系统,并检查系统是否识别/dev/bcahe0。
#fdisk -l显示,系统在引导后不会识别它。
然后
#modprobe bcache
#echo /dev/dm-0 > /sys/fs/bcache/register
#echo /dev/sdb > /sys/fs/bcache/register使用这些命令,fdisk -l显示了/dev/bcache0。
/dev/mapper/vgubuntu-root被认为是/dev/dm-0。
从上面提到的情况来看,我认为在挂载文件系统之前,我必须更新initrd.img以执行上面的脚本。
因此,我在/etc/initramfs-tools/模块中添加了bcache
并将以下脚本写入/etc/initramfs中的文件-tools/ script /init-pre装入/:
#! /bin/sh
echo /dev/dm-0 > /sys/fs/bcache/register
echo /dev/sdb > /sys/fs/bcache/register我将文件命名为10_bcache。
最后,我update-initramfs并重新启动系统,然而,系统仍然不识别/dev/bcache0,并陷入grub救援模式。
如何在系统挂载文件系统之前更新-initramfs以识别bcache设备。
发布于 2020-05-20 12:11:51
我自己解决了这个问题。造成这个问题的原因是,自从我安装了带有默认设置的20.04之后,/boot就被放入了bcache驱动器中。除非加载initrd.img,否则无法识别bcache驱动器,并且grub无法在其中找到/boot。
现在我将/boot放在bcache驱动器之外,grub可以找到它并引导系统。
下面是我设置bcache的方式。
首先,我用fdisk手动分区了hdd。
Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 1054719 1050624 513M EFI System
/dev/sda3 1054720 3151871 2097152 1G Linux filesystem
/dev/sda4 3151872 976773134 973621263 464.3G Linux filesystem第二,逻辑卷是通过以下方式创建的:
# pvcreate /dev/sda4
# vgcreate vgubuntu /dev/sda4
# lvcreate -L 12Gi -n swap1 vgubutu
# lvcreate -l 100%FREE -n root vgubuntufdisk -l显示了结果:
Disk /dev/mapper/vgubuntu-swap1: 12 GiB, 12884901888 bytes, 25165824 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/vgubuntu-root: 452.26 GiB, 485608128512 bytes, 948453376 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes然后由以下人员创建一个bcache驱动器:
# apt install bcache-tools
# modprobe bcache
# make-bcache -B /dev/mapper/vgubuntu-root -C /dev/sdc/dev/sdc是SSD。
fdisk -l显示:
Disk /dev/bcache0: 452.26 GiB, 485608120320 bytes, 948453360 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x91af541f为了在/dev/bcache0中安装系统,fdisk /dev/bcache0在系统中创建了一个分区。fdisk -l显示:
Device Boot Start End Sectors Size Id Type
/dev/bcache0p1 2048 948453359 948451312 452.3G 83 Linux在前面提到的准备之后,我使用安装程序中的高级磁盘设置菜单安装了系统,在这里我将挂载点设置如下。
/dev/sda1 biosgrub
/dev/sda2 EFI system
/dev/sda3 ext2 /boot
/dev/mapper/vgubuntu-swap1 swap
/dev/bcache0p1 ext4 /安装之后,我重新构建了initramfs,以便系统在挂载根文件系统之前识别bcache驱动器。我编辑了一个文件并在/etc/initramfs-tools/中添加了一个脚本。
/etc/initramfs-tools/modules
# List of modules that you want to include in your initramfs.
# They will be loaded at boot time in the order below.
#
# Syntax: module_name [args ...]
#
# You must run update-initramfs(8) to effect this change.
#
# Examples:
#
# raid1
# sd_mod
#
bcache/etc/initramfs-tools/scripts/init-premount/10_bcache
#! /bin/sh
#
# Backing Device
echo /dev/mapper/vgubuntu-root > /sys/fs/bcache/register
# Cashing Device
echo /dev/sdc > sys/fs/bcache/register在上述设置下完成了# update-initramfs操作。
没有后一个脚本,系统就会落入BusyBox中,您必须手动执行上面的脚本,因为bcache驱动器在执行脚本之前不会出现。我从https://wiki.archlinux.org/index.php/Bcache那里学到了这个操作。
/etc/fstab是:
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
#
# boot
/dev/sda3 /boot ext2 defaults 0 0
#
# swap
UUID=840f9099-58a2-45e5-958b-61becd00eabd none swap sw 0 0
#
# bcache root /dev/bcache0p1
UUID=bfff7e4c-c94d-4008-8f6e-0a82f41ccddf / ext4 errors=remount-ro 0 1
#
# external 500GB SDD
UUID=2757914a-06df-4fbb-9364-2d14bb222766 /mnt/workstation ext4 defaults 0 0这就是我为bcache在我的系统中工作所做的所有事情。这些比使用lvm或mdadm要复杂得多。第一个原因是bcache驱动器用于根文件系统,必须在initramfs安装文件系统之前识别它。此外,initramfs必须放置在bcache驱动器之外的一个普通的单独驱动器中。
因此,如果您使用根文件系统以外的bcache驱动器(如/home ),这将更加容易。
https://askubuntu.com/questions/1241038
复制相似问题