我的Linux文件服务器有四个LUKSencryption的USB-3磁盘。 把所有的东西装上去都有点困惑:虽然他们可能会得到和上次一样的盘符,但是他们可能不会,这会导致一些反复试验。
为了安装它们,我通常会这样说(通常是c,d,e和f中的每一个):
sudo cryptsetup open --type luks /dev/sdc d1 sudo mount /dev/mapper/d1 /d1
(请注意,这里的威胁场景是有人偷了我的硬件,目标是当它关机时,需要我重新启动它,文件服务器在我不在时不提供文件是可以接受的。
我可以在/dev/disk/by-uuid/看到UUID,尽pipe这些不是LUKS UUID。 我怀疑他们是稳定的。
我还会在/dev/disk/by-path/看到USB端口信息(不太好,取决于插入的位置)和WWID在/dev/disk/by-id/ 。 在这两种情况下,我都可以构造一个用于扫描熟悉名字的简短脚本(用于手动运行),使用sed来提取驱动器号,然后执行上面的两行来打开和安装卷。
但也许这个问题有更好的解决办法。 有什么build议么?
我会configuration/ etc / crypttab和使用UUIDs例如
usb1 UUID=d665864f-08e1-49ed-9adc-c608deadbeef
这将从相关磁盘configuration/ dev / mapper / usb1。 然后你可以使用fstab条目等东西挂载。 在启动过程中,系统会提示input密码来解锁磁盘,不需要额外的脚本。
最后,我写了一个简短的bash脚本来挂载UUID。
上面的链接将显示当前的状态(可能包括死亡),所以这是今天的样子:
#!/bin/bash # Mount all LUKS partitions that I know about that are connected to # this machine but not already mounted. luks_mount() { # This is the UUID we can see before luksOpen. uuid="$1" # Where to mount it. Should be at the root of the root file # system with no trailing slash. That is, /foo, not /foo/, # /foo/bar or simply foo. mount_point="$2" if [ ! -d $mount_point ]; then echo "$mount_point does not exist or is not a directory." return fi root_id=$(stat -c '%D %m' /) mount_id=$(stat -c '%D %m' "$mount_point") if [ "$root_id" != "$mount_id" ]; then echo "$mount_point is already mounted (is not part of the root filesystem)." echo "$root_id != $mount_id" return fi if [ ! -e /dev/disk/by-uuid/$uuid ]; then echo "LUKS volume for $mount_point not available." return fi drive_letter=$(stat /dev/disk/by-uuid/$uuid -c '%N' | \ sed -e 's/^.*sd//;' | \ tr -d "'") device=/dev/sd$drive_letter; mapping=$(echo $mount_point | tr -d /); echo "Mounting $mount_point:" sudo cryptsetup open --type luks $device $mapping; sudo mount /dev/mapper/$mapping /$mapping; } luks_mount 4d4bc0a0-e67a-4f9b-8c70-05cfdbf9282c /jma-4t luks_mount 4b824f8c-94d4-4655-8e56-67ead167ed4c /jma-3t luks_mount 5d6777f0-f475-451e-bad8-3cdf6e80f7c5 /sb-4t luks_mount 4ea3852f-8cdd-4ed9-898e-d86a851e0a9c /sb-3t