在bcache上的LUKS上的LVM
俄罗斯玩偶游戏在这里更深一点,有3个堆栈/层...
我对这个问题的最初想法是在LUKS上使用默认的Ubuntu安装LVM,并将其转换为带块的bcache支持设备,但在我的LVM测试中不起作用。
而且,ubuntu安装程序(ubiquity)太局限了,无法安装在预先准备好的bcache设备中(至少使用LVM上的LUKS),因此我们退回到了手动处理方法。
引导到实时CD / USB,然后选择“尝试Ubuntu”并打开一个终端
预装
sudo -i
# Define some variable to avoid confusion and error
luks_part=/dev/sda3
boot=/dev/sda2 # boot partition
caching_bcache=/dev/sdb # SSD or partition in SSD
# Do secure erase of encrypted backing and caching device (see Notes [1])
dd if=/dev/urandom of=$luks_part || dd if=/dev/urandom of=$caching_bcache
# Go and grab some coffe, this will take a while...
apt-get install bcache-tools
# Setup bcache caching and backing devices
make-bcache -C $caching_bcache -B $luks_part
# (Optional) Tweak bcache
echo writeback > /sys/block/bcache0/bcache/cache_mode
# Below we now create manually what ubiquity should have done for us
# Setup LUKS device on bcache device
cryptsetup --key-size 512 luksFormat /dev/bcache0
cryptsetup luksOpen /dev/bcache0 crypted
# Setup LVM on LUKS
# You can skip that part if you don't want to use a swap
# or don't want to use multiple partition. Use /dev/mapper/crypted
# as you root latter on
pvcreate /dev/mapper/crypted
vgcreate vg /dev/mapper/crypted
lvcreate -L 1G vg -n swap
lvcreate -l 100%FREE vg -n root
安装
保持终端处于打开状态,然后运行安装。分区时选择“其他”并指定
- 您的启动分区(
/dev/sda2
)
- 您的根分区(
/dev/mapper/vg-root
)
- 您的交换(
/dev/mapper/vg-swap
)
并选中复选框以格式化分区
安装结束时,请勿重新启动,只需单击“继续尝试ubuntu”
安装后
在我们打开的终端中
# Install bcache-tools to add bcache module to initramfs
mount /dev/mapper/vg-root /mnt
mount $boot /mnt/boot
mount -o bind /sys /mnt/sys
mount -o bind /proc /mnt/proc
mount -o bind /dev /mnt/dev
chroot /mnt
# To get apt-get running in the chroot
echo 'nameserver 8.8.8.8' > /run/resolvconf/resolv.conf
apt-get install bcache-tools
# Create /etc/crypttab to add crypted bcached partition
echo "crypted UUID=`blkid -o value /dev/bcache0|head -1` none luks" > /etc/crypttab
exit
sync
umount /mnt/sys
umount /mnt/proc
umount /mnt/dev
umount /mnt/boot
umount /mnt
vgchange -an /dev/mapper/crypted
cryptsetup luksClose crypted
sync
# Reboot & enjoy
Live CD / USB中存在一个已知的Ubuntu 15.04重新启动错误,因此您可能不得不强制重新启动/关闭
校验
一旦启动,您可以检查/dev/bcache0
是否实际上是具有以下内容的LUKS分区:
if sudo cryptsetup isLuks /dev/bcache0; then \
echo "crypted";\
else echo "unencrypted";\
fi
这是因为它是您的LUKS分区的缓存,现在您可以通过设备访问数据,而不必/dev/bcache0
从原始后备设备访问数据(/dev/sda3
此处)
参考文献
http://bcache.evilpiepirate.org/
https://wiki.archlinux.org/index.php/Bcache
https://wiki.archlinux.org/index.php/Dm-crypt
bcache-status尚未正式合并到bcache-tools中。您可以在这里找到它:https : //gist.github.com/djwong/6343451
[1]可能有更好的方式来做到这抹