Metadata-Version: 2.4
Name: remap_badblocks
Version: 0.9
Summary: CLI tool for remapping bad sectors on Linux disks using device-mapper
Author-email: Luigi Privitera <priviteraluigi98@gmail.com>
License-Expression: GPL-3.0-only
Project-URL: Repository, https://gitlab.com/Luigi-98/remap_badblocks.git
Project-URL: Issues, https://gitlab.com/Luigi-98/remap_badblocks/-/issues
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: dev
Requires-Dist: mypy; extra == "dev"
Requires-Dist: flake8; extra == "dev"
Requires-Dist: ruff; extra == "dev"
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pre-commit; extra == "dev"
Requires-Dist: black; extra == "dev"
Requires-Dist: isort; extra == "dev"
Dynamic: license-file

# remap-badblocks

`remap-badblocks` is a Linux CLI tool written in Python that scans a block device for bad sectors and creates a device-mapper target that skips over them. It can also reserve extra space to dynamically remap future badblocks.

It's a simple way to extend the usefulness of slightly damaged drives, ideal for anyone who wants to avoid discarding a disk due to a few bad sectors.

## Features

* Scans disks using `badblocks` to identify damaged sectors
* Creates a `device-mapper` target that avoids bad sectors
* Reserves spare sectors for dynamic remapping
* Supports using only part of a device (e.g., for hard partitioning or isolation)

## Installation

### From PyPI

```bash
pip install remap-badblocks
```

### From source

```bash
git clone https://gitlab.com/Luigi-98/remap-badblocks.git
cd remap-badblocks
pip install -e .[dev]
```

## Usage

### Database

`remap-badblocks` relies on a single source of stateful storage: a SQLite database. By default, it is stored at `/etc/remap_badblocks/devices_config.db`, but you can specify an alternative location using the `-P` option.

### Device Identification

Devices can be referenced by either:

* **Name**: set at creation, used as the name of the output device-mapper
* **ID**: an internal remap-badblocks identifier

### CLI Reference

```bash
remap-badblocks --help
```

### Example Workflow

```bash
# Add a new device
remap-badblocks add my_remapped_device --path /dev/sda

# Run a read-mode scan and initialize the mapping
#   by reserving spare space
remap-badblocks update --name my_remapped_device --mode read --spare-space 100MB

# Apply changes to generate the device-mapper
remap-badblocks apply

# Resulting device appears under /dev/mapper
ls /dev/mapper/
# /dev/mapper/my_remapped_device
```

## Contributing

We welcome feedback, bug reports, feature ideas, code contributions, and help shaping the roadmap — or even rethinking the project from the ground up.

Start with CONTRIBUTING.md, then open an issue or submit a merge request to get involved.

## License

GPL v3 License — see LICENSE for details.

## Community

* GitLab: [remap-badblocks project page](https://gitlab.com/Luigi-98/remap_badblocks)
* PyPI: [remap-badblocks](https://pypi.org/project/remap-badblocks/)
* Issues: [remap-badblocks Gitlab issues](https://gitlab.com/Luigi-98/remap_badblocks/-/issues)

## Acknowledgements & Related Tools

* [`badblocks`](https://linux.die.net/man/8/badblocks)
* [`device-mapper`](https://linux.die.net/man/8/dmsetup)
