我已根据文档创建了 LUKS 加密分区。但重启后我无法再访问该驱动器。错误消息很短:
Device /dev/sda3 is not a valid LUKS device.
当然,我尝试用 Google 搜索并做了一些恢复尝试,但是当我查看设备时,我得到了一些看起来像是有效的 LUKS 标头的东西:
# dd if=/dev/sda3 count=128 | hd
2+0 records in
2+0 records out
1024 bytes (1.0 kB, 1.0 KiB) copied, 0.00133979 s, 764 kB/s
00000000 4c 55 4b 53 ba be 00 02 00 00 00 00 00 00 40 00 |LUKS..........@.|
00000010 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 |................|
00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00000040 00 00 00 00 00 00 00 00 73 68 61 32 35 36 00 00 |........sha256..|
00000050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000060 00 00 00 00 00 00 00 00 fb 4b 9c 76 5f 0f ac 65 |.........K.v_..e|
00000070 8b 78 3e 7f 32 8e c3 ea b9 fb 43 83 92 41 64 9e |.x>.2.....C..Ad.|
00000080 14 83 eb 3c 65 09 2a 31 36 c1 c1 36 16 62 c8 f7 |...<e.*16..6.b..|
00000090 ce 43 bc 41 ad 3e 3f 74 18 4c 09 78 98 96 c6 0e |.C.A.>?t.L.x....|
000000a0 60 19 e1 fe 5e db 64 ce 64 66 32 66 35 61 62 63 |`...^.d.df2f5abc|
000000b0 2d 37 38 66 33 2d 34 66 34 38 2d 39 33 62 30 2d |-78f3-4f48-93b0-|
000000c0 35 32 63 35 37 38 34 34 34 30 61 37 00 00 00 00 |52c5784440a7....|
000000d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
000001c0 3d e5 70 f7 eb ac 1f cf f9 0b d4 a9 83 17 e9 38 |=.p............8|
000001d0 08 0b e5 3f 8d 5b 52 dc 87 1f d2 f4 4f 2a 27 d1 |...?.[R.....O*'.|
000001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
我唯一明显做错的事情就是我错误地创建了分区:
# fdisk -l /dev/sda
Ignoring extra data in partition table 5.
Invalid flag 0x0000 of EBR (for partition 5) will be corrected by w(rite).
Disk /dev/sda: 400 GiB, 429496729600 bytes, 838860800 sectors
Disk model: QEMU HARDDISK
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: 0xc915a69a
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 1953791 1951744 953M 83 Linux
/dev/sda2 1953792 419428351 417474560 199.1G 83 Linux
/dev/sda3 419428352 838860799 419432448 200G 5 Extended
/dev/sda5 620349215 1014853874 394504660 188.1G 70 DiskSecure Multi-Boot
尽管如此,我应该能够以某种方式访问数据。但是怎么做呢?
答案1
我解决这个问题的一种方法是通过环回设备安装它:
losetup -o 214747316224 /dev/loop0 /dev/sda && cryptsetup luksOpen /dev/loop0 data --key-file=...
214747316224 是分区 /dev/sda3 的起始乘以块大小(419428352*512)
显然分区表是错误的。那么问题来了:如何修复它而不丢失所有数据?