Skip to main content
Became Hot Network Question
Source Link

LUKS on a device with bad blocks - doable via GUI?

I have a portable (3,5'') external drive (Seagate, 2TB, USB3) which I would love to use with my Ubuntu 25.10 laptop. But, it has a few bad blocks:

user@user-ubuntu:~$ sudo mkfs.ext4 -c -c -v /dev/sdc1
mke2fs 1.47.2 (1-Jan-2025)
fs_types for mke2fs.conf resolution: 'ext4'
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
122101760 inodes, 488378389 blocks
24418919 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2636120064
14905 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Filesystem UUID: 9d0331a9-5f52-41fa-950e-0f5d4222f528
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
    102400000, 214990848

Running command: badblocks -b 4096 -X -s -w /dev/sdc1 488378388
Testing with pattern 0xaa: done
Reading and comparing: 2.35% done, 13:26:05 elapsed. (310585/0/9192 errors)

So with only 2.35% of the disk surface examined, we already have 9K+ errors. Hmm.

Now, if all I wanted to build was a traditional ext2/3/4 filesystem (which, yes, is what my command above is doing), I would trust mkfs.ext4 to create a filesystem that only populates good blocks and is stable. I realise there is risk in this strategy as whatever led to the already discovered batch of bad blocks could very well result in more corruption.

But say for a moment that I want to take the risk because I don't want to spend money on a new hard drive, or I don't have easy access to a shop with the right hardware.

How can I create a LUKS protected filesystem on such a disk?

The easy/only way I know how to do that is via gnome-disk-utility:

Screenshot of gnome-disk-utility

My concern is that by doing this, any bad block information that was previously discovered and stored in the ext4 filesystem will be erased. The disk utility does not give me a way to instruct it to:

  1. check the disk for bad blocks

  2. do whatever magic it does with LVM and LUKS to create an encrypted volume on the good blocks only

Ignoring the bad blocks and just instructing gnome-disk-utility to do its thing is a guarantee for disaster - unless gnome-disk-utility or the underlying software is clever enough to detect and deal with bad blocks "on the fly" (but I doubt it, otherwise why would badblocks take 10 days to complete?!)

Is there a way to do what I'm after via the GUI? If not, is there a Ubuntu-specific guide to creating a LUKS-protected filesystem on an external disk, or will a generic tutorial like https://shivering-isles.com/2019/09/create-luks-encrypted-devices do the trick?