这几天我一直在努力设置加密 NAS。基本计划是在 raid1 上的 lvm 上的 luks 上安装 btrfs,并在根分区上使用写回模式的 lvmcache,以减少磁盘访问。
长话短说:
设置分区和文件系统后GRUB
无法安装:
grub-install: warning: Attempting to install GRUB to a disk with multiple partition labels. This is not supported yet..
grub-install: error: embedding is not possible, but this is required for RAID and LVM install.
分区
按照 Arch Wiki,我首先设置分区:
gdisk
/dev/sda 和 /dev/sdb 的输出:
Disk /dev/sda: 976773168 sectors, 465.8 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 9EFA6587-E34F-4AC1-8B56-5262480A6C6A
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 976773134
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)
Number Start (sector) End (sector) Size Code Name
1 2048 4095 1024.0 KiB EF02 BIOS boot partition
2 4096 976773134 465.8 GiB 8300 Linux filesystem
请注意BIOS启动分区这显然是在模式GRUB
下安装时所需要的BIOS/GPT
。
MDADM
因为我有两个磁盘,所以我希望它们位于一个RAID1
阵列中:
mdadm --create --level=1 --raid-devices=2 /dev/md0 /dev/sda2 /dev/sdb2
root@archiso ~ # mdadm --detail --scan
ARRAY /dev/md0 metadata=1.2 name=archiso:0 UUID=bdfc3fea:f4a0ee6d:6ac08012:59ea384b
root@archiso ~ # cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdb2[1] sda2[0]
488253440 blocks super 1.2 [2/2] [UU]
[>....................] resync = 2.0% (9832384/488253440) finish=96.6min speed=82460K/sec
bitmap: 4/4 pages [16KB], 65536KB chunk
unused devices: <none>
卢克斯
接下来我LUKS
在以下位置设置一个卷RAID
:
root@archiso ~ # cryptsetup luksFormat /dev/md0
WARNING!
========
This will overwrite data on /dev/md0 irrevocably.
Are you sure? (Type uppercase yes): YES
Enter passphrase:
Verify passphrase:
root@archiso ~ # cryptsetup luksOpen /dev/md0 md0-crypt
Enter passphrase for /dev/md0:
左心室容量
Btrfs
可以使用快照来代替LVM
,但在撰写本文时,无法向 中添加 SSD 缓存设备Btrfs
。所以我选择使用LVM
并通过稍后添加SSD lvmcache
:
(一步创建卷组:)
root@archiso ~ # vgcreate vg0 /dev/mapper/md0-crypt
Physical volume "/dev/mapper/md0-crypt" successfully created
Volume group "vg0" successfully created
root@archiso ~ # lvcreate -L 100M -C y vg0 -n boot
Logical volume "boot" created.
root@archiso ~ # lvcreate -L 20G vg0 -n root
Logical volume "root" created.
root@archiso ~ # lvcreate -L 10G vg0 -n var
Logical volume "var" created.
root@archiso ~ # lvcreate -L 6G -C y vg0 -n swap
Logical volume "swap" created.
root@archiso ~ # lvcreate -l +100%FREE vg0 -n home
Logical volume "home" created
产生以下布局:
root@archiso ~ # lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
boot vg0 -wc-a----- 100.00m
home vg0 -wi-a----- 429.53g
root vg0 -wi-a----- 20.00g
swap vg0 -wc-a----- 6.00g
var vg0 -wi-a----- 10.00g
Btrfs/文件系统
创建文件系统:
root@archiso ~ # mkfs.ext4 /dev/vg0/boot
root@archiso ~ # mkfs.btrfs /dev/vg0/home
root@archiso ~ # mkfs.btrfs /dev/vg0/root
root@archiso ~ # mkfs.btrfs /dev/vg0/var
(ext4
之所以选择引导,是因为btrfs
抱怨分区尺寸太小。)
挂载文件系统:
root@archiso ~ # swapon /dev/vg0/swap
root@archiso ~ # mount /dev/vg0/root /mnt/arch -o compress=lzo
root@archiso ~ # mount /dev/vg0/home /mnt/arch/home -o compress=lzo
root@archiso ~ # mount /dev/vg0/var /mnt/arch/var -o compress=lzo
root@archiso ~ # mount /dev/vg0/boot /mnt/arch/boot
安装拱门
实际上我只是从以前的备份中复制系统:
root@archiso ~ # rsync -Pa /mnt/bkp/sda/* /mnt/arch
(咖啡时间(休闲时光)
设置 mdadm.conf 和 fstab
root@archiso ~ # genfstab -U /mnt/arch > /mnt/arch/etc/fstab
root@archiso ~ # cat /mnt/arch/etc/fstab
# /dev/mapper/vg0-root
UUID=62ebf0c9-bb37-4b4e-87dd-eb8a4ace6a69 / btrfs rw,relatime,compress=lzo,space_cache 0 0
# /dev/mapper/vg0-home
UUID=53113e11-b663-452f-b4da-1443e470b065 /home btrfs rw,relatime,compress=lzo,space_cache 0 0
# /dev/mapper/vg0-var
UUID=869ffe10-7a1c-4254-9612-25633c7ae619 /var btrfs rw,relatime,compress=lzo,space_cache 0 0
# /dev/mapper/vg0-boot
UUID=d121a9df-8c03-4ad9-a6e0-b68739b1a358 /boot ext4 rw,relatime,data=ordered 0 2
# /dev/mapper/vg0-swap
UUID=29035eeb-540d-4437-861b-c30597bb7c16 none swap defaults 0 0
root@archiso ~ # mdadm --detail --scan >> /mnt/arch/etc/mdadm.conf
root@archiso ~ # cat /mnt/arch/etc/mdadm.conf
[...]
ARRAY /dev/md0 metadata=1.2 name=archiso:0 UUID=bdfc3fea:f4a0ee6d:6ac08012:59ea384b
chroot 进入系统
root@archiso ~ # arch-chroot /mnt/arch /bin/bash
[root@archiso /]#
mkinitcpio.conf
添加了这些钩子:mdadm_udev encrypt lvm2 btrfs
[root@archiso /]# mkinitcpio -p linux
配置GRUB
现在,对于有趣的(也是失败的)部分,我选择GRUB
作为我的引导加载程序,因为它应该支持我使用的所有装置。
参考:
- https://wiki.archlinux.org/index.php/Dm-crypt/Encrypting_an_entire_system#LVM_on_LUKS
- http://www.pavelkogan.com/2014/05/23/luks-full-disk-encryption/
更改的部分/etc/default/grub
:
GRUB_CMDLINE_LINUX="cryptdevice=/dev/md0:vg0"
GRUB_ENABLE_CRYPTODISK=y
安装 grub:
[root@archiso /]# grub-install --target=i386-pc --recheck /dev/sda
Installing for i386-pc platform.
/run/lvm/lvmetad.socket: connect failed: No such file or directory
WARNING: Failed to connect to lvmetad. Falling back to internal scanning.
/run/lvm/lvmetad.socket: connect failed: No such file or directory
WARNING: Failed to connect to lvmetad. Falling back to internal scanning.
/run/lvm/lvmetad.socket: connect failed: No such file or directory
WARNING: Failed to connect to lvmetad. Falling back to internal scanning.
grub-install: warning: Attempting to install GRUB to a disk with multiple partition labels. This is not supported yet..
grub-install: error: embedding is not possible, but this is required for RAID and LVM install.
(--debug
输出可用这里)
坦白说......我不知道这里出了什么问题。在 BIOS/GPT 模式下,GRUB 应该将其 core.img 嵌入到ef02/BIOS boot
分区中,不是吗?
编辑
https://bbs.archlinux.org/viewtopic.php?id=144254不适用于此处:
[root@archiso /]# btrfs fi show --all-devices
Label: none uuid: 62ebf0c9-bb37-4b4e-87dd-eb8a4ace6a69
Total devices 1 FS bytes used 965.77MiB
devid 1 size 20.00GiB used 3.04GiB path /dev/mapper/vg0-root
Label: none uuid: 869ffe10-7a1c-4254-9612-25633c7ae619
Total devices 1 FS bytes used 339.15MiB
devid 1 size 10.00GiB used 3.04GiB path /dev/mapper/vg0-var
Label: none uuid: 53113e11-b663-452f-b4da-1443e470b065
Total devices 1 FS bytes used 384.00KiB
devid 1 size 429.53GiB used 2.04GiB path /dev/mapper/vg0-home
Btrfs v3.17.3
答案1
嗯......显然这一行是线索:
grub-install: warning: Attempting to install GRUB to a disk with multiple partition labels. This is not supported yet..
以前我直接安装btrfs
在/dev/sda
和上/dev/sdb
。这就是为什么它们都附加了 FSTYPE 和 LABEL(如图所示lsblk
)。
解决方案:我现在已经用(安全擦除)擦除了/dev/sda
和。可能有更好的方法来取消设置这些标志......但这对我有用。/dev/sdb
hdparm
答案2
这是 Google 的最佳搜索结果之一
grub-install: error: embedding is not possible, but this is required for RAID and LVM install.
对我来说,修复方法是使用 dd 擦除我的启动磁盘(我试图在 USB 磁盘上安装 GRUB),例如...
dd if=/dev/zero of=/dev/sdd bs=1M status=progress
然后创建一个新的分区表,只不过这次比默认晚几个扇区启动......
fdisk /dev/sdd
n (for new partition)
p (for primary partition)
1 (for partition 1)
50000 (for first sector 50,000 vs default 2,480)
写入新分区和分区表后,我运行了 grub-install 程序...
grub-install --force --skip-fs-probe /dev/sdd