Skip to content
Search

Dd

lastmod 2026-02-06created 2015-10-2318 edits

dd - convert and copy a file.

dd is a command-line utility for Unix and Unix-like operating systems whose main purpose is to convert and copy files.

In Unix, device drivers for hardware and special device files appear in the file system just like regular files. dd can read from and write to these files, provided the function is implemented in the respective driver. Therefore, dd can be used for tasks such as backing up the boot sector of a hard drive and obtaining a fixed amount of random data. The dd program can also perform conversions on the data while copying, including byte order swapping and ASCII↔EBCDIC text encoding conversion.

The name dd relates to the DD statement found in IBM's Job Control Language (JCL), where DD stands for "Data Description". The command's syntax resembles a JCL statement more than other Unix commands.

Originally designed for conversion between ASCII and EBCDIC, dd first appeared in Version 5 Unix. The dd command is specified in IEEE Std 1003.1-2008, which is part of the SUS.

Uses

  • Data transfer
  • Master boot record backup and restore
  • Data modification
  • Disk wiping
  • Data recovery
  • Drive performance benchmarking
  • Creating files with random data
  • Converting a file to uppercase

Flags

bs=BYTES
Sets both the number of bytes read at a time and the number of bytes written to the same value. If bs is specified, ibs and obs are ignored.
count=N
Specifies the number of blocks to copy.
if=FILE
Read from FILE instead of stdin
of=FILE
Write to FILE instead of stdout

Zero fill

Can be used for a low-level format.

$ sudo dd if=/dev/zero of=/dev/sdc2

Bootable USB

in MacOSX

Assume the USB disk is located at /dev/disk2.

$ diskutil list
$ diskutil unmountDisk /dev/disk2

## disk 가 아닌, rdisk를 사용한다.
$ sudo dd if=image.iso of=/dev/rdisk2 bs=1m

$ diskutil eject /dev/disk2

in Ubuntu

WARNING

Do not add a partition number. For example, use sdb, not sdb1.

$ lsblk
## USB는 /dev/sdb에 위치한다고 가정한다.
$ sudo dd bs=4M if=image.iso of=/dev/sdb && sync

Example

Describes how to create USB media for installing FreeBSD in a Windows environment.

Download dd.exe, a program that writes the installation image to a USB in a bootable form, from http://www.chrysocome.net/dd, and check the USB drive name.

dd --list

When actually writing the image to the USB memory stick, specify it by hard disk volume number.

dd if=FreeBSD-9.0-RC1-amd64-memstick.img of=\\?\Device\HarddiskVolume9 bs=64k --progress

Making it similar to usb-creator

When a boot disk is made from an iso file with usb-creator, checking the disk with sudo fdisk -l prints the following:

Disk /dev/sda: 14.32 GiB, 15376318464 bytes, 30031872 sectors
Disk model: Cruzer Fit
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 389FBC94-38B6-4D1A-8964-87488DB3D5A5

Device       Start      End  Sectors  Size Type
/dev/sda1       64  9291427  9291364  4.4G Microsoft basic data
/dev/sda2  9291428  9301499    10072  4.9M EFI System
/dev/sda3  9301500  9302099      600  300K Microsoft basic data
/dev/sda4  9306112 30031808 20725697  9.9G Linux filesystem

Analyzing the partition structure created by usb-creator gives the following:

Partition

Size

Type

Purpose

sda1

4.4G

Microsoft basic data

ISO image (casper/filesystem)

sda2

4.9M

EFI System

UEFI bootloader

sda3

300K

Microsoft basic data

UEFI boot catalog

sda4

9.9G

Linux filesystem

writable (casper-rw, persistent storage)

Why booting fails with dd

dd writes the ISO's hybrid MBR structure as is, and some UEFI firmware does not recognize it properly. usb-creator builds a separate GPT partition table and explicitly separates the EFI System Partition, so it has better UEFI compatibility.

Building the same structure manually

Uses the mount, umount, mkfs(mkfs.ext4, mkfs.vfat), wipefs, sgdisk, partprobe, and sync commands.

#!/bin/bash
USB=/dev/sdb          # USB 디바이스 (lsblk로 확인!)
ISO=ubuntu-24.04-desktop-amd64.iso

# 1. ISO를 loop 마운트하고 EFI 이미지 추출
sudo mkdir -p /mnt/iso
sudo mount -o loop "$ISO" /mnt/iso

# ISO 크기 확인 (섹터 단위)
ISO_SIZE=$(stat -c%s "$ISO")
ISO_SECTORS=$((ISO_SIZE / 512))

# 2. USB 초기화 및 GPT 파티션 생성
sudo wipefs -a "$USB"
sudo sgdisk --zap-all "$USB"

# 파티션 1: ISO 데이터 (Microsoft basic data)
sudo sgdisk -n 1:64:+4500M -t 1:0700 "$USB"

# 파티션 2: EFI System Partition
sudo sgdisk -n 2:0:+5M -t 2:EF00 "$USB"

# 파티션 3: 부트 카탈로그 (Microsoft basic data)
sudo sgdisk -n 3:0:+300K -t 3:0700 "$USB"

# 파티션 4: writable 영속 저장소 (나머지 공간)
sudo sgdisk -n 4:0:0 -t 4:8300 "$USB"

sudo partprobe "$USB"
sleep 2

# 3. 파티션 1: ISO 내용 복사
sudo mkfs.vfat -F 32 "${USB}1"
sudo mkdir -p /mnt/usb
sudo mount "${USB}1" /mnt/usb
sudo cp -a /mnt/iso/. /mnt/usb/
sudo umount /mnt/usb

# 4. 파티션 2: EFI 부트 파일 복사
sudo mkfs.vfat -F 12 "${USB}2"
sudo mount "${USB}2" /mnt/usb
sudo mkdir -p /mnt/usb/EFI/BOOT
sudo cp /mnt/iso/EFI/BOOT/* /mnt/usb/EFI/BOOT/
sudo umount /mnt/usb

# 5. 파티션 4: ext4 writable 영역 (casper-rw)
sudo mkfs.ext4 -L casper-rw "${USB}4"

# 6. 정리
sudo umount /mnt/iso
sudo sync

echo "완료. USB 부팅 가능 디스크 생성됨."

In short, it uses commands that each handle one stage of the USB disk work:

  1. Clearing signatures - wipefs
  2. Creating partitions - sgdisk
  3. Formatting partitions - mkfs
  4. Informing the kernel - partprobe
  5. Ensuring physical writes - sync

A simpler method: modify the ISO for EFI, then dd

If you want to use dd and only ensure EFI compatibility, use the isohybrid command:

# isohybrid로 UEFI 부팅 지원 추가 후 dd
sudo apt install syslinux-utils
sudo isohybrid --uefi ubuntu-24.04-desktop-amd64.iso
sudo dd bs=4M if=ubuntu-24.04-desktop-amd64.iso of=/dev/sdb status=progress oflag=sync

If this method does not work, use the manual partitioning method above. Check whether the BIOS is UEFI Only or also supports Legacy.

Standard I/O Pipe speed test

For the method using the dd command, see Standard streams#Standard I/O Pipe speed test.

Troubleshooting

General steps if USB boot fails

See Dd#General steps if USB boot fails.

See also

Favorite site

References


  1. How_to_create_bootable_USB_memory_stick.pdf ↩

author Zer0 sitemap