이 페이지의 이전 버전을 보고 있습니다. 현재 버전 보기.

현재와 비교 페이지 이력 보기

버전 1 다음 »

하드디스크를 이미지로 백업하는 법


파티션 확인

lsblk
fdisk -l /dev/sdc


# lsblk
NAME          MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
...
sdc              8:32   0  74.5G  0 disk
├─sdc1          8:33   0  73.2G  0 part
├─sdc2          8:34   0     1K  0 part
└─sdc5          8:37   0   1.3G  0 part


# fdisk -l /dev/sdc
Disk /dev/sdc: 74.5 GiB, 80026361856 bytes, 156301488 sectors
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: dos
Disk identifier: 0x000e6f33

Device     Boot     Start       End   Sectors  Size Id Type
/dev/sdc1  *           63 153501074 153501012 73.2G 83 Linux
/dev/sdc2       153501075 156296384   2795310  1.3G  5 Extended
/dev/sdc5       153501138 156296384   2795247  1.3G 82 Linux swap / Solaris

zero padding

zero padding 하면 이미지로 만들었을 때 용량이 줄어듬

상태가 좋지 않은 디스크에는 하지 않는 것이 좋음

mount /dev/sdc1 /mnt
dd if=/dev/zero bs=4M | pv | dd of=/mnt/tmpzero.txt bs=4M
sync
rm /mnt/tmpzero.txt
sync
umount /mnt


# mount /dev/sdc1 /mnt

# dd if=/dev/zero bs=4M | pv | dd of=/mnt/tmpzero.txt bs=4M.
34.9GiB 0:14:03 [31.1MiB/s] [    <=>    ]
dd: error writing '/mnt/tmpzero.txt': No space left on device                                                    ]
0+403467 records in
0+403466 records out
50254086144 bytes (50 GB, 47 GiB) copied, 1385.26 s, 36.3 MB/s

# sync

# rm /mnt/tmpzero.txt

# sync

# umount /mnt


HDD → dd 이미지

하드디스크 백업 명령어. 진행 상태를 보기 위해 pv 명령어를 파이핑 함.

raw 이미지는 마운트 가능함.

dd if=/dev/sdc bs=32M | pv | dd of=sdc.raw bs=512 conv=sparse


# dd if=/dev/sdc bs=32M | pv | dd of=sdc.raw bs=512 conv=sparse
10.4GiB 0:03:29 [39.0MiB/s] [    <=>    ]

dd 이미지 → VM 이미지

VM에 올리지 않는다면 만들지 않아도 무방함

qemu-img convert -O qcow2 -S 512 sdc.raw sdc.qcow2


참고

https://itectec.com/superuser/clone-only-space-in-use-from-hard-disk/

https://serverfault.com/questions/439128/dd-on-entire-disk-but-do-not-want-empty-portion

https://www.reddit.com/r/linuxquestions/comments/ax2af1/is_there_a_way_to_speed_up_the_dd_command/

https://www.geeksforgeeks.org/pv-command-in-linux-with-examples/

https://unix.stackexchange.com/questions/31669/is-it-possible-to-mount-a-gzip-compressed-dd-image-on-the-fly

https://qemu.readthedocs.io/en/latest/tools/qemu-img.html


  • 레이블 없음