Using dmsetup to Salvage Disks with Bad Blocks

Introduction I have a disk with bad blocks. The filesystem I’m using (such as ZFS) doesn’t support marking bad blocks like ext did, and completely replacing the disk is costly and unnecessary. Instead, I’ve used dmsetup to create a virtual disk that excludes the bad sectors, allowing the filesystem to work with the remaining good areas. This guide covers the process of scanning the disk, preparing a custom partition, setting up dmsetup, and ensuring everything works across reboots. I’ve additionally included steps to ensure that the dmsetup configuration follows the disk, ensuring you don’t loose that critical piece of information. ...

April 7, 2025 · 9 min · Michael Bisbjerg