'리눅스 디스크 백업'에 해당되는 글 1건

1. 명령어 설명

리눅스 dd 명령어는 블록 단위로 파일복사, 파일변환을 수행하는 명령어이다.

리눅스 시스템에서는 디스크도 파일로 간주되므로, 디스크 및 디스크의 파티션을 복제하는데 사용 가능하다.

아래와 같은 용도로 자주 사용된다.

  • 파일 및 장치 복사
  • 디스크 및 파티션 백업/복원
  • 사이즈를 지정한 swap 파일 생성
  • 사이즈를 지정한 더미파일 생성
  • 디스크 I/O 성능 측정
Usage: dd [OPERAND]...
  or:  dd OPTION
Copy a file, converting and formatting according to the operands.

  bs=BYTES        read and write up to BYTES bytes at a time (default: 512);
                  overrides ibs and obs
  cbs=BYTES       convert BYTES bytes at a time
  conv=CONVS      convert the file as per the comma separated symbol list
  count=N         copy only N input blocks
  ibs=BYTES       read up to BYTES bytes at a time (default: 512)
  if=FILE         read from FILE instead of stdin
  iflag=FLAGS     read as per the comma separated symbol list
  obs=BYTES       write BYTES bytes at a time (default: 512)
  of=FILE         write to FILE instead of stdout
  oflag=FLAGS     write as per the comma separated symbol list
  seek=N          skip N obs-sized blocks at start of output
  skip=N          skip N ibs-sized blocks at start of input
  status=LEVEL    The LEVEL of information to print to stderr;
                  'none' suppresses everything but error messages,
                  'noxfer' suppresses the final transfer statistics,
                  'progress' shows periodic transfer statistics

N and BYTES may be followed by the following multiplicative suffixes:
c =1, w =2, b =512, kB =1000, K =1024, MB =1000*1000, M =1024*1024, xM =M,
GB =1000*1000*1000, G =1024*1024*1024, and so on for T, P, E, Z, Y.

 

2. 자주 사용하는 옵션

  • bs: 한번에 읽고 쓸 수 있는 최대 바이트 크기. 즉, block size
  • count: 복사할 block 수. 즉, bs * count 크기의 사이즈만큼 복사
  • if: 입력 파일 경로
  • of: 출력 파일 경로

3. 옵션에 사용되는 suffix 단위

  • c: 1byte (Character)
  • w: 2bytes (Word)
  • b: 512bytes (Block)
  • K: 1024bytes (Kibibyte, KiB)

4. 사용예시

[더미파일 생성]

# dd if=/dev/zero of=/dummyfile bs=1024 count=1024

=> 파일을 /dummyfile 경로에 생성하되, 0 문자(정확히는, ASCII NUL(0x00) 문자)를 복사해 채우며, 1024 byte 블록 단위로 1024번에 걸쳐 복사한다.

 

[디스크/파티션 복제]

# dd if=/dev/sdb1 of=/dev/sdc1 bs=1024

=> /dev/sdb1 파티션을 /dev/sdc1 파티션으로 복제하되, 1024byte 블록 단위로 복제한다.

 

[디스크/파티션 초기화]

# dd if=/dev/zero of=/dev/sdb1

=> /dev/sdb1 파티션을 초기화한다.

 

[파일을 복사하며 내용 중 소문자를 모두 대문자로 변환]

# dd if=/log1 of=/log1_upper bs=1024 conv=ucase

=> /log1 의 내용을 /log1_upper 로 1024byte 블록 단위로 복사하며, 모든 소문자를 대문자로 변환한다.

 

*/dev/zero 는 0을 무한히 반환하는 특수 파일

블로그 이미지

망원동똑똑이

프로그래밍 지식을 자유롭게 모아두는 곳입니다.

,