# dd — Datenträger blockweise kopieren, klonen und löschen

> Praxis-Guide zu dd: Disk-Images erstellen, Laufwerke klonen, ISOs auf USB schreiben, Datenträger löschen und rohe Blockdaten kopieren — mit Sicherheitshinweisen.

Source: https://www.jpkc.com/db/cheatsheets/shell-system/dd/

<!-- PROSE:intro -->
dd kopiert Daten Block für Block direkt auf Geräteebene — ideal für Disk-Images, das Klonen ganzer Festplatten, bootfähige USB-Sticks oder das sichere Überschreiben von Datenträgern. Genau diese Macht macht das Werkzeug aber auch gefährlich: dd trägt nicht umsonst den Beinamen „disk destroyer". Ein vertauschtes `if=`/`of=` oder ein falsches `of=/dev/sdX` überschreibt sofort und unwiderruflich eine ganze Platte — ohne Rückfrage, ohne Papierkorb, ohne Undo. Prüfe das Zielgerät deshalb immer vorher mit `lsblk`, bevor du Enter drückst.
<!-- PROSE:intro:end -->

## Grundlagen

`dd if=<input> of=<output>` — Kopiert Daten von der Eingabe- in die Ausgabedatei.

```bash
dd if=/dev/sda of=/dev/sdb
```

`dd if=<input> of=<output> bs=<size>` — Kopiert mit einer bestimmten Blockgröße (beeinflusst die Geschwindigkeit).

```bash
dd if=/dev/sda of=disk.img bs=4M
```

`dd if=<input> of=<output> bs=<size> count=<n>` — Kopiert nur N Blöcke der angegebenen Größe.

```bash
dd if=/dev/zero of=testfile bs=1M count=100
```

`dd if=<input> of=<output> status=progress` — Zeigt den Fortschritt während des Kopiervorgangs an.

```bash
dd if=/dev/sda of=backup.img bs=4M status=progress
```

`dd if=<input> of=<output> conv=<flags>` — Wendet beim Kopieren Konvertierungsoptionen an.

```bash
dd if=data.txt of=upper.txt conv=ucase
```

## Disk-Images & Klonen

`dd if=<device> of=<image> bs=4M status=progress` — Erstellt ein rohes Disk-Image von einem Gerät.

```bash
dd if=/dev/sda of=disk-backup.img bs=4M status=progress
```

`dd if=<image> of=<device> bs=4M status=progress` — Schreibt ein Disk-Image zurück auf ein Gerät.

```bash
dd if=disk-backup.img of=/dev/sda bs=4M status=progress
```

`dd if=<device> bs=4M status=progress | gzip > <image>.gz` — Erstellt ein komprimiertes Disk-Image.

```bash
dd if=/dev/sda bs=4M status=progress | gzip > disk-backup.img.gz
```

`gunzip -c <image>.gz | dd of=<device> bs=4M status=progress` — Schreibt ein komprimiertes Disk-Image zurück.

```bash
gunzip -c disk-backup.img.gz | dd of=/dev/sda bs=4M status=progress
```

`dd if=<device1> of=<device2> bs=4M conv=noerror,sync status=progress` — Klont eine Festplatte (überspringt Lesefehler, füllt mit Nullen auf).

```bash
dd if=/dev/sda of=/dev/sdb bs=4M conv=noerror,sync status=progress
```

## Bootfähige USB-Sticks & ISOs

`dd if=<iso> of=<device> bs=4M status=progress oflag=sync` — Schreibt ein ISO-Image auf einen USB-Stick.

```bash
dd if=ubuntu-24.04-desktop-amd64.iso of=/dev/sdb bs=4M status=progress oflag=sync
```

`dd if=<device> of=<iso> bs=4M status=progress` — Erstellt ein ISO von einem CD/DVD-Laufwerk.

```bash
dd if=/dev/cdrom of=disc.iso bs=4M status=progress
```

`dd if=/dev/zero of=<device> bs=512 count=1` — Löscht den MBR (die ersten 512 Byte) einer Platte.

```bash
dd if=/dev/zero of=/dev/sdb bs=512 count=1
```

## Testdateien erzeugen

`dd if=/dev/zero of=<file> bs=1M count=<n>` — Erstellt eine mit Nullen gefüllte Datei einer bestimmten Größe.

```bash
dd if=/dev/zero of=100mb.bin bs=1M count=100
```

`dd if=/dev/urandom of=<file> bs=1M count=<n>` — Erstellt eine mit Zufallsdaten gefüllte Datei.

```bash
dd if=/dev/urandom of=random.bin bs=1M count=50
```

`dd if=/dev/zero of=<file> bs=1 count=0 seek=<size>` — Erstellt eine Sparse-Datei (reserviert Platz, ohne ihn zu beschreiben).

```bash
dd if=/dev/zero of=sparse.img bs=1 count=0 seek=10G
```

## Löschen & sicheres Überschreiben

`dd if=/dev/zero of=<device> bs=4M status=progress` — Überschreibt eine Platte mit Nullen.

```bash
dd if=/dev/zero of=/dev/sdb bs=4M status=progress
```

`dd if=/dev/urandom of=<device> bs=4M status=progress` — Überschreibt eine Platte mit Zufallsdaten (sicherer).

```bash
dd if=/dev/urandom of=/dev/sdb bs=4M status=progress
```

`dd if=/dev/zero of=<file> bs=4M; rm <file>` — Überschreibt eine Datei, bevor sie gelöscht wird.

```bash
dd if=/dev/zero of=secret.txt bs=4M; rm secret.txt
```

## Benchmark & Performance

`dd if=/dev/zero of=<file> bs=1G count=1 oflag=dsync` — Misst die Schreibgeschwindigkeit (synchronisiert nach jedem Block).

```bash
dd if=/dev/zero of=/tmp/testfile bs=1G count=1 oflag=dsync
```

`dd if=<file> of=/dev/null bs=1M` — Misst die Lesegeschwindigkeit (verwirft die Ausgabe).

```bash
dd if=/tmp/testfile of=/dev/null bs=1M
```

`dd if=/dev/zero of=<file> bs=<size> count=<n> oflag=direct` — Testet die Schreibgeschwindigkeit per Direct-I/O (umgeht den Cache).

```bash
dd if=/dev/zero of=/tmp/testfile bs=4M count=256 oflag=direct
```

## Optionen & Flags

`bs=<size>` — Blockgröße für Lesen und Schreiben (Suffixe K, M, G). Größer = schneller.

```bash
bs=4M (üblich für Disk-Operationen)
```

`count=<n>` — Kopiert nur N Eingabeblöcke.

```bash
count=100 (mit bs=1M = 100 MB)
```

`skip=<n>` — Überspringt N Blöcke am Anfang der Eingabe.

```bash
skip=1 bs=512 (überspringt den MBR)
```

`seek=<n>` — Überspringt N Blöcke am Anfang der Ausgabe.

```bash
seek=1 bs=512 (schreibt hinter den MBR)
```

`conv=noerror,sync` — Macht bei Lesefehlern weiter und füllt mit Nullen auf (für beschädigte Platten).

```bash
dd if=/dev/sda of=rescue.img conv=noerror,sync bs=4K
```

`oflag=sync` — Synchronisiert die Ausgabe nach jedem Schreibvorgang (stellt sicher, dass Daten wirklich geschrieben sind).

```bash
dd if=image.iso of=/dev/sdb bs=4M oflag=sync
```

`iflag=fullblock` — Sammelt vollständige Eingabeblöcke (verhindert zu kurze Reads aus Pipes).

```bash
dd if=/dev/stdin of=output.bin bs=1M iflag=fullblock
```

<!-- PROSE:outro -->
## Fazit

dd ist eines der mächtigsten und zugleich gefährlichsten Werkzeuge der Unix-Welt: Es schreibt blind genau dorthin, wohin du es schickst — ohne Rückfrage und ohne Undo. Ein falsches `of=/dev/sdX` zerstört in Sekunden eine ganze Platte. Prüfe das Zielgerät deshalb **immer** vorher mit `lsblk` oder `fdisk -l`, vertausche niemals `if=` und `of=` und hänge das Gerät vor dem Schreiben aus. Setze `status=progress` für sichtbaren Fortschritt, eine sinnvolle `bs=` (meist `4M`) für Tempo und `conv=fsync` bzw. `oflag=sync`, damit am Ende wirklich alle Daten auf dem Datenträger liegen und nicht nur im Cache. Auf macOS sprichst du das Rohgerät `/dev/rdiskN` an (deutlich schneller) und hängst es zuvor mit `diskutil unmountDisk` aus. Im Zweifel lieber einmal mehr nachsehen, als eine unwiederbringliche Platte zu überschreiben.

## Weiterführende Links

- [Arch-Wiki: dd (englisch)](https://wiki.archlinux.org/title/Dd) – gründliche Referenz zu Disk-Images, Klonen und sicherem Löschen
- [ubuntuusers-Wiki: dd](https://wiki.ubuntuusers.de/dd/) – deutschsprachige Einführung mit Praxisbeispielen und Warnhinweisen
<!-- PROSE:outro:end -->

## Verwandte Kommandos

- [lsblk](https://www.jpkc.com/db/cheatsheets/shell-system/lsblk/) – listet Blockgeräte auf; vor jedem dd-Schreibvorgang zur Geräteprüfung nutzen
- [fdisk](https://www.jpkc.com/db/cheatsheets/shell-system/fdisk/) – Partitionstabellen anzeigen und bearbeiten
- [mount](https://www.jpkc.com/db/cheatsheets/shell-system/mount/) – Dateisysteme ein- und aushängen (vor dd aushängen)

