Filesystems

無法在 LUKS 下創建 ext4 文件系統

  • November 24, 2021

我已經從 32Mb USB 快閃記憶體驅動器成功創建了一個 LUKS 驅動器。但是,當我向其寫入 ext4 文件系統時,我無法掛載結果,甚至無法執行fsckdumpe2fs

驅動器顯示lsblk

sda           8:0    1   31M  0 disk
└─luks      253:0    0   15M  0 crypt

然後我用 編寫文件系統sudo mkfs.ext4 -v /dev/mapper/luks,這會產生

mke2fs 1.45.5 (07-Jan-2020)
fs_types for mke2fs.conf resolution: 'ext4', 'small'
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
3840 inodes, 3840 blocks
192 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4194304
1 block group
32768 blocks per group, 32768 fragments per group
3840 inodes per group

Allocating group tables: done
Writing inode tables: done
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done
各種命令的輸出
$ sudo cryptsetup luksDump /dev/sda
LUKS header information
Version:        2
Epoch:          3
Metadata area:  16384 [bytes]
Keyslots area:  16744448 [bytes]
UUID:           1f30e940-4144-4980-a32a-4f1b78a46fc5
Label:          (no label)
Subsystem:      (no subsystem)
Flags:          (no flags)

Data segments:
 0: crypt
       offset: 16777216 [bytes]
       length: (whole device)
       cipher: aes-xts-plain64
       sector: 512 [bytes]

Keyslots:
 0: luks2
       Key:        512 bits
       Priority:   normal
       Cipher:     aes-xts-plain64
       Cipher key: 512 bits
       PBKDF:      argon2i
       Time cost:  4
       Memory:     187471
       Threads:    4
       Salt:       5c c4 28 e0 bc f6 7f df b2 1c 77 b6 fa f3 f1 bc
                   48 66 fc 56 e3 5c e5 13 cc af 1d 52 ec df fc 93
       AF stripes: 4000
       AF hash:    sha256
       Area offset:32768 [bytes]
       Area length:258048 [bytes]
       Digest ID:  0
Tokens:
Digests:
 0: pbkdf2
       Hash:       sha256
       Iterations: 18853
       Salt:       62 8a b7 2c 4d 74 d3 6b 46 c2 9b 34 e2 d6 5c 3d
                   06 12 ee a7 5b b0 81 1f d0 99 19 b6 4f de 5c 77
       Digest:     c2 71 c1 d5 de 16 d9 cc 8c 15 f2 34 21 42 3a a3
                   24 d1 82 26 cd ab f9 98 0c 0a 68 7a 35 e2 3d a9

^這Subsystem: (no subsystem)條線令人擔憂

$ sudo mount -v /dev/mapper/luks /media/luks
mount: /media/luks: wrong fs type, bad option, bad superblock on /dev/mapper/luks, missing codepage or helper program, or other error.
$ sudo fsck /dev/mapper/luks
fsck from util-linux 2.34
e2fsck 1.45.5 (07-Jan-2020)
ext2fs_open2: Bad magic number in super-block
fsck.ext2: Superblock invalid, trying backup blocks...
fsck.ext2: Bad magic number in super-block while trying to open /dev/mapper/luks
...

^fsck.ext2向我建議它不能告訴文件系統

$ sudo dumpe2fs /dev/mapper/luks
dumpe2fs 1.45.5 (07-Jan-2020)
dumpe2fs: Bad magic number in super-block while trying to open /dev/mapper/luks
Couldn't find valid filesystem superblock.

所有這些都向我表明文件系統沒有正確創建,但是據我所知,即使是區區 15Mb 也應該是足夠的空間,我不確定還有什麼問題

聽起來像是硬體問題。您應該badblocks在設備上以寫入模式執行。

另一種選擇是

  • 創建一個小圖像文件(幾個 100 MiB)
  • 在上面放一個循環設備
  • 在其中創建文件系統
  • 將圖像文件複製到設備的(第一部分)
  • 將圖像文件與設備的相應部分進行比較
dd if=/dev/zero of=/path/to/imagefile bs=1M count=100

losetup /dev/loop0 /path/to/imagefile

mkfs.ext4 /dev/loop0

blockdev --getsz /dev/loop0
204800

dd if=imagefile of=/dev/mapper/luks

sha1sum imagefile 
aaafc117548aaebef3dbb5f4a609022e386192b6  imagefile

dd if=/dev/mapper/luks count=204800 | sha1sum 
204800+0 Datensätze ein
204800+0 Datensätze aus
aaafc117548aaebef3dbb5f4a609022e386192b6  -

引用自:https://unix.stackexchange.com/questions/678951