dcg

Disk Operations

system.disk

Protects against destructive disk operations like dd to devices, mkfs, partition table modifications, RAID management, btrfs/LVM/device-mapper operations, network block devices, and macOS diskutil erase/partition/APFS deletion

  • 59blocking rules
  • 19safe patterns
  • 15Critical
  • 44High

On by default. To turn it off:

~/.config/dcg/config.toml
[packs]
disabled = ["system.disk"]

Evaluated when a command contains dd, diskutil, fdisk, mkfs, mke2fs, mkdosfs, mkntfs, mkexfatfs, newfs, newfs_apfs.

Recorded verdicts

  • dd if=/dev/zero of=/dev/disk2 bs=1mBlockedsystem.disk:dd-device

Blocking rules

Each rule ID is system.disk:<name>. Use it in allowlists and [policy.rules].

  1. badblocks-write

    Critical

    badblocks -w (write mode) overwrites every block on the device with test patterns, destroying all existing data.

  2. blkdiscard

    Critical

    blkdiscard discards (TRIMs) every block on the device, destroying all data instantly with no undo.

  3. cryptsetup-erase

    Critical

    cryptsetup erase/luksErase/luksFormat destroys the LUKS key material; the encrypted volume becomes permanently unreadable.

  4. ddrescue-device

    Critical

    ddrescue --force writes its output onto a device, overwriting all data on it, exactly as dd would.

  5. diskutil-apfs-delete

    Critical

    diskutil apfs delete/erase operations permanently remove APFS containers, volumes, or snapshots.

    Explanation
    Deleting an APFS container destroys every volume inside it; deleting or erasing a volume destroys that volume's data; deleting a snapshot removes a restore point. None of these are recoverable without backups. List APFS structure first: diskutil apfs list
  6. diskutil-erase

    Critical

    diskutil erase operations DESTROY all data on the target disk or volume.

    Explanation
    diskutil eraseDisk/eraseVolume/reformat/zeroDisk/randomDisk/secureErase overwrite the target's contents. On APFS this removes every volume in the container. There is no recovery without backups. Inspect the target first: diskutil list diskutil info <disk>
  7. diskutil-partition

    Critical

    diskutil partitioning operations rewrite the partition map and erase data.

    Explanation
    diskutil partitionDisk erases the entire disk before writing the new partition map; splitPartition and mergePartitions destroy the contents of the partitions they reshape (merge preserves only the first when asked); resetFusion wipes both constituent devices. Preview the current layout first: diskutil list <disk>
  8. hdparm-security-erase

    Critical

    hdparm --security-erase issues an ATA secure erase of the WHOLE drive at the firmware level. Unrecoverable.

  9. nvme-format-sanitize

    Critical

    nvme format/sanitize erases an NVMe namespace (or the entire controller). All data is destroyed.

  10. nwipe

    Critical

    nwipe (the dban successor) overwrites an entire disk with wipe patterns; `--autonuke` targets every disk. All data is destroyed.

  11. scrub-device

    Critical

    scrub overwrites a device with data-destruction patterns (DoD/Gutmann/etc.); its contents are gone.

  12. sg_format

    Critical

    sg_format --format performs a SCSI low-level format, erasing all data on the medium.

  13. wipe-device

    Critical

    wipe securely overwrites the target device, destroying all data on it.

  14. zfs-destroy

    Critical

    zfs destroy removes a ZFS dataset, volume, or snapshot; with -r it destroys the whole descendant tree.

  15. zpool-destroy

    Critical

    zpool destroy removes a ZFS pool and every dataset, snapshot, and byte of data it contains.

  16. btrfs-balance

    High

    btrfs balance redistributes data across devices. Can be slow and disruptive.

  17. btrfs-check-repair

    High

    btrfs check --repair is DANGEROUS and can cause data loss. Backup first!

  18. btrfs-device-add

    High

    btrfs device add incorporates a device into the filesystem. Verify the device is correct.

  19. btrfs-device-remove

    High

    btrfs device remove redistributes data off a device. Interruption causes data loss.

  20. btrfs-filesystem-resize

    High

    btrfs filesystem resize can shrink a filesystem. Data loss if size is too small.

  21. btrfs-rescue

    High

    btrfs rescue operations modify filesystem metadata. Use only as last resort.

  22. btrfs-subvolume-delete

    High

    btrfs subvolume delete PERMANENTLY removes a subvolume and all its data.

  23. copy-to-device

    High

    Copying or moving onto a device OVERWRITES that device, exactly as dd would. Extremely dangerous!

  24. dd-device

    High

    dd to a block device will OVERWRITE all data on that device. Extremely dangerous!

  25. dd-wipe

    High

    dd from /dev/zero or /dev/urandom to a device will WIPE all data!

  26. dmsetup-clear

    High

    dmsetup clear removes the mapping table from a device.

  27. dmsetup-create

    High

    dmsetup create sets up a new device-mapper device. Verify parameters carefully.

  28. dmsetup-load

    High

    dmsetup load changes device mapping. Verify the new table is correct.

  29. dmsetup-remove

    High

    dmsetup remove detaches a device-mapper device. May cause data loss if in use.

  30. dmsetup-remove-all

    High

    dmsetup remove_all removes ALL device-mapper devices. Extremely dangerous!

  31. dmsetup-wipe-table

    High

    dmsetup wipe_table replaces the device table, causing all I/O to fail.

  32. fdisk-edit

    High

    fdisk can modify partition tables and cause data loss.

  33. gdisk-edit

    High

    gdisk/cgdisk open the GPT for interactive editing; a write from that session destroys the partition table.

    Explanation
    gdisk and cgdisk are editors: they load the partition table and apply what the session writes back. An agent that cannot see the prompts cannot know what it is about to commit. Read the table instead, which is never blocked: gdisk -l /dev/sda sgdisk --print /dev/sda lsblk /dev/sda
  34. losetup-device

    High

    losetup modifies loop device associations. Verify before proceeding.

  35. lvconvert-merge

    High

    lvconvert --merge reverts LV to snapshot state, discarding changes since snapshot.

  36. lvreduce

    High

    lvreduce SHRINKS a logical volume. Data loss if filesystem isn't resized first!

  37. lvremove

    High

    lvremove PERMANENTLY deletes a logical volume and ALL its data.

  38. lvresize-shrink

    High

    lvresize with negative size SHRINKS the volume. Resize filesystem first or lose data!

  39. mdadm-create

    High

    mdadm --create initializes a new RAID array, ERASING existing data on member devices.

  40. mdadm-fail

    High

    mdadm --fail marks a device as failed. Use only for intentional drive replacement.

  41. mdadm-grow

    High

    mdadm --grow reshapes a RAID array. Interruption can cause data loss. Backup first.

  42. mdadm-remove

    High

    mdadm --remove removes a drive from a RAID array. May cause data loss if redundancy is lost.

  43. mdadm-stop

    High

    mdadm --stop shuts down a RAID array. Data may become inaccessible.

  44. mdadm-zero-superblock

    High

    mdadm --zero-superblock PERMANENTLY erases RAID metadata. Array cannot be reassembled.

  45. mkfs

    High

    mkfs formats a partition/device and ERASES all existing data.

  46. mkswap

    High

    mkswap formats a partition as a swap area, ERASING any existing data.

  47. mount-bind-root

    High

    mount --bind to root directory can have system-wide effects.

  48. nbd-client-connect

    High

    nbd-client connecting a device can expose or overwrite data. Verify server and device.

  49. nbd-client-disconnect

    High

    nbd-client -d disconnects a network block device. Data loss if not properly unmounted.

  50. parted-modify

    High

    parted can modify partition tables and cause data loss.

  51. pvmove

    High

    pvmove migrates data between physical volumes. Do NOT interrupt or data may be lost.

  52. pvremove

    High

    pvremove ERASES LVM metadata from a physical volume. Data becomes inaccessible.

  53. sfdisk-modify

    High

    sfdisk rewrites the partition table: options act immediately, and a bare invocation reads a new layout from stdin.

    Explanation
    sfdisk is non-interactive by design. Pointed at a device it either applies the requested change (`--delete`, `--part-type`, `--wipe`, `--relocate`) or replaces the whole table with the script on stdin. There is no confirmation and no undo. What stays allowed: - Inspecting: `sfdisk -l /dev/sda`, `sfdisk --json /dev/sda`. - Saving the table: `sfdisk --dump /dev/sda > table.sfdisk`. - Rehearsing: add `-n`/`--no-act`.
  54. sgdisk-modify

    High

    sgdisk rewrites the GPT; --zap-all/-Z also erases the protective MBR, losing every partition.

    Explanation
    sgdisk applies its options and exits — there is no confirmation step and no undo. `--zap-all`/`-Z` destroys the GPT and the protective MBR together; `--clear`/`-o`, `--delete`/`-d`, `--new`/`-n` and `--typecode`/`-t` each rewrite the partition table in place. On a UEFI disk that is the same blast radius as `parted mklabel`, which is already denied. What stays allowed: - Inspecting the table: `sgdisk --print /dev/sda`, `sgdisk -i 1 /dev/sda`. - Saving it: `sgdisk --backup=/tmp/table.bin /dev/sda`. - Rehearsing a change: add `-P`/`--pretend` to see what would happen. Before changing anything, back the table up and look at the device: sgdisk --backup=/tmp/table.bin /dev/sda lsblk /dev/sda
  55. tee-device

    High

    tee/sponge into a device will OVERWRITE that device, exactly as dd would. Extremely dangerous!

  56. umount-force

    High

    umount -f force unmounts which may cause data loss if device is in use.

  57. vgreduce

    High

    vgreduce removes a physical volume from a volume group. Data may be lost.

  58. vgremove

    High

    vgremove DELETES a volume group and all logical volumes within it.

  59. wipefs

    High

    wipefs removes filesystem signatures. Use with extreme caution.

Safe patterns

Checked first. A command that matches one is never blocked by this pack.

  • dd-discard
  • lsblk
  • blkid
  • df
  • parted-print
  • btrfs-subvolume-list
  • btrfs-subvolume-show
  • btrfs-filesystem-show
  • btrfs-filesystem-df
  • btrfs-filesystem-usage
  • btrfs-device-stats
  • btrfs-property-get
  • btrfs-scrub-status
  • dmsetup-ls
  • dmsetup-status
  • dmsetup-info
  • dmsetup-table
  • dmsetup-deps
  • diskutil-readonly