Skip to main content

diskmgr

Python License Platform Status Dependencies

Tests Lint Typed Build TUI SemVer Changelog

Manage hard disks and USB drives from one tool: list what is attached, copy or mirror files between drives, and clone a whole disk sector-for-sector.

Windows-first (it uses the Storage PowerShell module and raw \\.\PhysicalDrive access); disk listing and all file-level operations also work on Linux.

Disclaimer

⚠️ READ BEFORE USE. This software permanently destroys data by design. Cloning, imaging and mirroring overwrite entire disks and delete files. A mistyped disk number or path can wipe the wrong drive in seconds, and there is no undo.

USE ENTIRELY AT YOUR OWN RISK. This software is provided "AS IS", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and non-infringement. See the licence for the full terms, which govern.

To the maximum extent permitted by applicable law, the author and contributors accept no liability whatsoever for any claim, damages or other liability — including but not limited to data loss, data corruption, hardware damage, rendering a system unbootable, business interruption, lost profits, or any direct, indirect, incidental, special, exemplary or consequential damages — arising from or in connection with this software or its use, however caused and on any theory of liability, even if advised of the possibility of such damage.

You are solely responsible for:

  • verifying that the target disk is the one you intend to write to, every time;
  • maintaining tested, independent backups before running any destructive operation;
  • confirming you are authorised to access and modify the devices concerned;
  • complying with all applicable laws, regulations, licences and organisational policies where you use it.

This is not certified, validated or warranted for any regulated, forensic, evidentiary, medical, safety-critical, or otherwise high-assurance purpose, and must not be relied upon as the sole safeguard for irreplaceable data. Its safety checks reduce risk; they do not eliminate it, and they can be overridden deliberately.

If you do not accept these terms, do not install or use this software.

Why

Copying a folder to a backup drive and cloning a bootable USB stick are two different jobs that usually need two different tools. This does both, with the same safety model:

  • Nothing destructive happens without a typed confirmation. Erasing disk 2 means typing ERASE DISK 2, not pressing y.
  • The system disk is refused outright, and no combination of flags erases the running OS without that phrase.
  • --dry-run prints the exact plan a real run would execute — the same plan object, not an approximation of it.
  • Everything written is verified: files by hash, disks by reading the target back and comparing digests.

Install

pip install diskmgr                # CLI only, zero dependencies
pip install "diskmgr[tui]"         # adds the interactive terminal UI

From a clone:

pip install -e ".[dev]"

Usage

The CLI is diskmgr; python -m disk_manager works too.

See what is attached

$ diskmgr list
 #  MODEL                              SIZE  BUS     STYLE   FLAGS        VOLUMES
---------------------------------------------------------------------------------
 0  UMIS RPJTJ512MGE1QDQ           476.9 GB  NVMe    GPT     SYSTEM       C: [OS] NTFS, D: [Data] NTFS
 1  SanDisk Ultra USB 3.0           28.9 GB  USB     MBR     REMOVABLE    E: [STICK] FAT32
diskmgr list --json              # machine-readable
diskmgr list --removable-only    # just the USB sticks and SD cards
diskmgr info 1                   # one disk in full, including write safety

diskmgr info also tells you whether the disk may be written to and what the confirmation phrase would be:

  Write safety  : REFUSED
  BLOCKED: disk 0 carries the running operating system (C:, D:)

A disk can be named by index (1), device path (\\.\PhysicalDrive1), or a drive letter it hosts (E:).

Copy files between drives

# Add new and changed files; never deletes anything
diskmgr copy D:\projects E:\backup\projects

# Make the destination identical to the source, deleting extras
diskmgr copy D:\projects E:\backup\projects --mode mirror

# Only take files that are strictly newer than the destination copy
diskmgr copy D:\projects E:\backup\projects --mode sync

Useful flags:

Flag Effect
--dry-run Print the plan, write nothing
--show-files List every planned copy/overwrite/delete
--verify hash Hash every written file against its source (default is size)
--exclude GLOB Skip matching files or folders; repeatable
--include GLOB Only copy matching files; repeatable
--retries N Retries per file on a transient I/O error (default 2)
--stop-on-error Abort on the first failure instead of continuing
diskmgr copy D:\code E:\backup --mode mirror \
    --exclude "*.tmp" --exclude node_modules --exclude .git \
    --verify hash --dry-run --show-files

Each file is written to a temporary name and atomically renamed into place, so an interrupted run leaves either the old file or the complete new one — never a half-written file that the next run would mistake for up to date.

Image a disk

# Read a USB stick into an image file (.gz compresses it)
diskmgr image save 1 D:\images\stick.img.gz

# Write it back, to the same stick or a different one
diskmgr image restore D:\images\stick.img.gz 1

image save is read-only but still needs elevation, because raw device access does. --skip-bad-sectors re-reads a failing block one sector at a time and zero-fills only the sectors that genuinely cannot be read, reporting the count rather than silently producing a short image.

Clone one disk onto another

diskmgr clone 1 2          # copy disk 1 onto disk 2, sector for sector

The target must be at least as large as the source. Before any byte is written the tool locks and dismounts every volume on the target — if a program still has a file open there, the clone is refused rather than corrupting a live filesystem. Afterwards the target is read back and its digest compared with the source:

  source digest      : 9f2c...
  destination digest : 9f2c...
  verification       : PASSED

Interactive terminal UI

diskmgr tui
Key Does
Select a disk
r Re-scan (runs off the UI thread; the interface stays responsive)
u Show only removable devices, or everything again
f Copy files — options form, then a plan preview
i Save an image of the selected disk
R Restore an image onto the selected disk (shifted on purpose)
c Clone the selected disk onto another
x Cancel the running operation
q Quit — refused while an operation is writing

Long operations run on a worker thread, so the interface stays responsive and cancellable throughout, and a crash in one cannot leave the app wedged.

Every flow starts with an options form carrying the same settings as the corresponding CLI command — transfer mode, verify depth, glob filters, retries, bad-sector recovery, size limits, block size, digests. The last values you used are pre-filled, so a repeated job is a couple of keystrokes. Paths can be typed or browsed with a directory tree.

The copy plan preview is the dry run. Before anything is written you get the full list of actions — deletions sorted to the top — plus the free-space check and any folders that could not be scanned. Cancelling there is exactly a dry run, and it shows more than copy --dry-run does, because the engine's own dry run skips the free-space check. For that reason --dry-run, --quiet and --show-files have no TUI equivalent: the preview replaces all three. --yes is deliberately absent too — it exists so scripts can skip the confirmation, which is not something an interactive UI should offer.

Destructive operations show the whole safety picture before the gate: the target's blockers and warnings, whether you are elevated, and the exact phrase required. If the target is refused — the system disk, a read-only or undersized disk — or you are not elevated, the dialog has no input and no proceed button at all. There is nothing to press.

Afterwards the verdict stays on screen until the next run, with both full digests, so a clone that finished hours ago can still be checked against a digest produced by the CLI:

CLONED - VERIFICATION PASSED
  32.0 GB written in 12:41
  source digest      : 9f2c…
  destination digest : 9f2c…

If you are not running elevated, a banner says so on startup and the imaging, restore and clone actions are disabled rather than failing several screens later.

Safety model

Guard Behaviour
System disk Refused. --allow-system downgrades it to a warning but still requires the typed phrase, even with --yes.
Confirmation Exact phrase ERASE DISK <n>, case-insensitive. --yes skips it for non-system disks only.
Same disk Cloning a disk onto itself is refused.
Size A target smaller than the source or image is refused before any write.
Read-only A write-protected disk is refused.
Mounted volumes Locked and dismounted first; a busy volume aborts the operation.
Destination inside source Refused — it would copy the transfer's own output.
Mirror onto a parent of the source Refused — it would delete the source.
Not elevated Surfaced in the TUI on startup and before the phrase gate, rather than as a failure after it.

Raw device access needs an elevated terminal on Windows (or root on Linux). Listing disks and copying files do not.

Development

pip install -e ".[dev]"
pytest          # 160 tests, no hardware or elevation required
flake8 disk_manager tests

The raw-clone tests substitute a plain file for the block device, so the read, write, hash and verify paths all execute for real — including bad-sector recovery and cancellation — without touching any hardware.

The TUI is tested through Textual's own run_test/Pilot, needing no extra dependency. Those tests pin the guarantees that matter: a blocked target's dialog composes no confirmation input at all, declining the gate never starts the clone engine, and a worker crashing with an exception the engine never raises still leaves the app usable.

Licence

MIT — see the LICENSE file in the source distribution.

The MIT licence's warranty disclaimer and limitation of liability are the operative legal terms and apply in full; the disclaimer at the top of this document restates and expands on them in plain language. Nothing in this README creates any warranty, guarantee or obligation of support.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

diskmgr-0.1.0.tar.gz (77.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

diskmgr-0.1.0-py3-none-any.whl (76.8 kB view details)

Uploaded Python 3

File details

Details for the file diskmgr-0.1.0.tar.gz.

File metadata

  • Download URL: diskmgr-0.1.0.tar.gz
  • Upload date:
  • Size: 77.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for diskmgr-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e7dc00fadc1cb47704798ec5a989a7c0871f0475c38cf0779281dc272c81d501
MD5 010948ba536fb6399bc0e633cd51c416
BLAKE2b-256 3a0d26d73eeaf30b63461e915d8903793bd54d29d320efc7ffe2baf496bc6c6f

See more details on using hashes here.

File details

Details for the file diskmgr-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: diskmgr-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 76.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for diskmgr-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1ec2c2dacb4f9b91f37113268ae259f340a907af7253f470045caf1bb169c29a
MD5 727788d1d9ea70f958c2e51c4b6901e3
BLAKE2b-256 8672cbc1f2908942dc272e9630d8fa16e2d0593ccbd8e915ec13233ba30f6c3e

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page