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

WLED Backup script

ℹ️ Info: This post was linked in the WLED discussions and the script may make it to the WLED project. Introduction WLED is a powerful open-source solution for controlling addressable LEDs over Wi-Fi, making it popular for DIY smart lighting projects. However, maintaining backups of your WLED configurations can be tedious, especially when managing multiple devices. In this post, I’ll demonstrate a simple bash-based backup solution that discovers WLED devices on your network, pulls their configurations, and saves them locally for easy restoration. The scripts are intended for Linux-based systems and can be scheduled with cron for fully automated backups. ...

March 28, 2025 · 4 min · Michael Bisbjerg

Entity Framework Core: Querying views, but manipulating tables

I had a use case for EF Core where I wanted to query a database view while still supporting classic add/update/delete methods on the base table. Specifically, I wanted to enrich entities with computed values, like a lookup or label, but allow full CRUD support. Example Problem Suppose we have two entities: Entity: (Id, DeviceId) Friendly: (DeviceId, FriendlyName) The goal is to filter Entity records by FriendlyName, even though it’s not part of the table directly. ...

June 8, 2023 · 2 min · Michael Bisbjerg

EntityFramework Core – Composite key filtering

In EF Core, you can easily filter to a list of known values using LINQ: int[] ids = { 1, 3, 7 }; myContext.Posts.Where(s => ids.Contains(s.Id)); But what if the list of values includes composite keys, like Type and Name? var filterBy = new[] { (PostTypes.Blog, "First"), (PostTypes.KnowledgeBase, "Last") }; myContext.Posts.Where(s => filterBy.Contains((s.Type, s.Name))); // But how? There’s no direct Contains() support for tuples or composite keys in EF Core. A Stack Overflow post outlines several options. Here, I’ll focus on Option 6 — building an expression tree to generate a SQL query like: ...

June 3, 2021 · 2 min · Michael Bisbjerg

Introducing Elephant Projects - Cross-repository refactoring

At work, we maintain a product with 400+ projects spread over 15 repositories. Making changes across them is painful—especially when debugging SDK-level code and publishing local packages repeatedly. To make this smoother, I created a tool: ElephantProject (also on NuGet). ElephantProject swaps NuGet <PackageReference>s with <ProjectReference>s, and generates solution files for local dev. These changes are never committed—this is for local development only. Use Case – Refactoring In my local dev directory (called “Work”), I clone all the repositories. Then I run: ...

April 5, 2021 · 2 min · Michael Bisbjerg