linux系统全盘加密,boot分区加密

linux全盘加密可以防止泄露重要文件
debian系在安装系统时提供了基于LUKS的磁盘全盘加密
然而/boot分区安装时是不能加密的
我们需要安装完成后,另外使用LUKS1进行/boot分区加密
注意:没有必要,不要折腾boot 加密。默认的系统加密方式已经很安全了。
(加密-映射-格式化-挂载)

1.查看/boot分区信息

lsblk -pf

假设/dev/sda1 是 /boot 分区

2. 备份/boot分区

mount -oremount,ro /boot
install -m0600 /dev/null /tmp/boot.tar
tar -C /boot --acls --xattrs --one-file-system -cf /tmp/boot.tar .
umount /boot

3.使用LUKS1加密/boot

cryptsetup luksFormat --type luks1 /dev/sda1

4. 映射boot_crypt到加密的boot分区

uuid="$(blkid -o value -s UUID /dev/sda1)"
echo "boot_crypt UUID=$uuid none luks" | tee -a /etc/crypttab
cryptdisks_start boot_crypt

5.在映射设备上创建文件系统,重新格式化

grep /boot /etc/fstab
lsblk -dno uuid /dev/sda1
mkfs.ext2 -m0 -U D388-FE1E /dev/mapper/boot_crypt

6.重新挂载/boot,并且恢复文件

mount -v /boot
tar -C /boot --acls --xattrs -xf /tmp/boot.tar

(如果 /boot/efi 是一个单独的分区,你也需要重新挂载)

7. 在GRUB2启动时使用cryptomount

echo "GRUB_ENABLE_CRYPTODISK=y" >>/etc/default/grub
update-grub
grub-install /dev/sda

到这里,linux系统全盘加密的工作已经完成

linux全盘加密还有其他高级功能,比如luks2降级到luks1,使用秘钥快速启动,使用其他键盘布局
如果你需要用到,请查看参考文章

https://cryptsetup-team.pages.debian.net/cryptsetup/encrypted-boot.html
https://sysguides.com/fedora-35-luks-full-disk-encryption/
https://unix.stackexchange.com/questions/577379/how-can-i-install-debian-with-full-disk-encryption-and-a-custom-sized-swapfile/577765#577765

此处评论已关闭