1

I've successfully created a LUKS drive from a 32Mb USB flash drive. However when I write an ext4 filesystem to it I am unable to mount the result, or even run fsck or dumpe2fs etc.

The drive shows up under lsblk as

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

I'm then writing the filesystem with sudo mkfs.ext4 -v /dev/mapper/luks, which produces

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
Output from various commands
$ 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

^The Subsystem: (no subsystem) line is worrying

$ 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 suggests to me that it can't tell the filesystem

$ 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.

All of these suggest to me that the filesystem hasn't been created correctly, however from what I can tell even a measly 15Mb should be enough space and I'm not sure what else could be the problem

4
  • There's nothing obviously wrong with the filesystem part. It might be worth sharing how you've created the LUKS partition. You have opened the LUKS partition (decrypted its access), haven't you...? Commented Nov 24, 2021 at 21:34
  • Sounds like a hardware problem. You should run badblocks in write mode on the device. Commented Nov 24, 2021 at 21:51
  • 1
    @HaukeLaging aha that looks like it, the latter half of the blocks are bad Commented Nov 24, 2021 at 22:57
  • That would get you! Commented Nov 24, 2021 at 23:11

1 Answer 1

1

Sounds like a hardware problem. You should run badblocks in write mode on the device.

Another option would be

  • to create a small image file (a few 100 MiB)
  • put a loop device upon it
  • create the filesystem in it
  • copy the image file to the (first part of the) device
  • compare the image file to the respective part of the device
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  -

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.