How to make disk image with dd on Linux or Unix
admin
2023-03-07 00:41:51
0

How to clone an entire hard disk

The syntax is:
dd if=/dev/input/DEVICE-HERE of=/dev/OUTPUT/DEVICE-HERE bs=64K conv=noerror,sync
To clone /dev/sdc (250G) to /dev/sdd (250G) in Linux, enter:
# dd if=/dev/sdc of=/dev/sdd bs=64K conv=noerror,sync
To clone /dev/ada0 (250G) to /dev/adb0 (250G) in FreeBSD, enter:
# dd if=/dev/ada0 of=/dev/adb0 bs=64K conv=noerror,sync
Where,

  1. if=/dev/file : Input device/file.

  2. of=/dev/file : Output device/file.

  3. bs=64k : Sets the block size to 64k. You can use 128k or any other value.

  4. conv=noerror : Tell dd to continue operation, ignoring all read errors.

  5. sync : Add input blocks with zeroes if there were any read errors, so data offsets stay in sync.

How to clone a partition

To clone /dev/sdc1 to /dev/sdd1, enter:
# dd if=/dev/sdc1 of=/dev/sdd1 bs=128K conv=noerror,sync
Sample outputs:

15874+0 records in
15873+0 records out
1040252928 bytes transferred in 3.805977 secs (273320858 bytes/sec)

dd make disk image

You can boot from a live cd. Once booted, make sure no partitions are mounted from the source hard drive disk. You can store disk image on an external USB disk. The syntax is as follows
dd if=/dev/INPUT/DEVICE-NAME-HERE conv=sync,noerror bs=64K | gzip -c > /path/to/my-disk.image.gz
In this example, create disk image for /dev/da0 i.e. cloning /dev/da0 and save in the current directory:
# dd if=/dev/da0 conv=sync,noerror bs=128K | gzip -c > centos-core-7.gz
Sample outputs:

How to make disk image with dd on Linux or UnixFig.01: dd command in action
The above command just cloned the entire hard disk, including the MBR, bootloader, all partitions, UUIDs, and data.


How to restore system (dd image)

The syntax is:
# gunzip -c IMAGE.HERE-GZ | dd of=/dev/OUTPUT/DEVICE-HERE
For example:
# gunzip -c centos-core-7.gz | dd of=/dev/da0

Tip #1: Not enough disk space locally? Use remote box

You can send the image through ssh and save it on the remove box called server1.cyberciti.biz:
# dd if=/dev/da0 conv=sync,noerror bs=128K | gzip -c | ssh vivek@server1.cyberciti.biz dd of=centos-core-7.gz

Tip #2: See progress while making an image with dd

You need to use GNU dd with coreutils version 8.24 as follows (pass the status=progress to the dd):
# dd if=/dev/sdc1 of=/dev/sdd1 bs=128K conv=noerror,sync status=progress
Sample outputs:

How to make disk image with dd on Linux or Unixgdd (GNU DD) in action with progress bar running on MacOS X


Tip #3: Save extra information

  • See how to save and restore MBR only.

  • Not a fan of dd? See top 6 open source disk cloning and imaging softwares.

  • Want to deal with corrupted disk? Try ddrescue command.


相关内容

热门资讯

特朗普:俄乌将实行为期3天的停... △特朗普(资料图)当地时间5月8日,美国总统特朗普在其社交媒体“真实社交”发文表示,在俄罗斯与乌克兰...
《星球大战》男主角发“特朗普躺... 据英国广播公司(BBC)5月8日报道,《星球大战》演员马克·哈米尔在社交平台发布一张AI生成的图片,...
产业园区招商政府委托媒介选型指... 导语:产业园区招商需兼顾资源整合效率与项目落地精准度,尤其在互联网招商模式下,平台流量、技术团队与资...
“无废城市”建设 | 为新材料... 4月26日,在常山生态工业园区的利安隆科润(浙江)新材料有限公司实验室里,企业品控部负责人、科技副总...
既能防晒又能听歌,还自带AI小... 春夏出门运动,你是不是也常常纠结:到底是戴帽子防晒,还是戴耳机听歌?两个都戴上,耳朵被压得生疼,帽檐...
伊朗警告过往船只远离美军舰艇:... 据美国有线电视新闻网(CNN)5月8日报道,一段录音显示,美伊在霍尔木兹海峡发生冲突后,伊朗革命卫队...
事关汉坦病毒,大西洋小岛牵动多... 5月6日,荷兰“洪迪厄斯”号邮轮停留在佛得角首都普拉亚的近海海域。新华社发(埃尔顿·蒙泰罗摄)发生汉...
上海尼为取得供栈收栈机专利,实... 国家知识产权局信息显示,上海尼为智能科技有限公司取得一项名为“一种供栈收栈机”的专利,授权公告号CN...
Win11终于不卡了!让CPU... 快科技5月8日消息,微软正针对Windows11系统用户体验进行深度优化,内部代号为Project ...
2026户外出行与通勤旗舰手机... 对于经常需要通勤、热爱户外活动的朋友来说,选择一款合适的手机至关重要。它需要满足单手操作的便捷性、坚...