博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linux Backup: Hard Disk Clone with "dd"
阅读量:5332 次
发布时间:2019-06-14

本文共 3377 字,大约阅读时间需要 11 分钟。

 

Most of Windows users may know "Norton Ghost". Norton Ghost is a backup software for hard disks. It can backup a whole hard disk or a partition to an image file. Also, Norton Ghost can copy all the contents from a hard disk to another exactly. However, Norton Ghost is a Windows software, users on other operating system (such as Linux) can not enjoy its powerful function. Fortunately, most of Unix/Linux operating system provides a command line whose function is similar to Norton Ghost, it is called "dd".

In fact, "dd" is much powerful than Norton Ghost. You can use many arguments to control it. In this short article, we only concern on how to backup a whole hard disk or a partition.

Hard Disk Clone

Suppose you have a 40GB hard disk and a removable hard disk whose capacity is 60GB, and you want to backup all the files from the hard disk to the removable disk. With "dd", it is a very easy task. Again, suppose your hard disk's Unix device name is /dev/sda and the removable disk is /dev/sdb. The following command can copy all the content from /dev/sda to /dev/sdb:

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

Here, if=... sets the source and of=... sets the destination. "dd" doesn't care of the contents of the hard disk. It just reads bytes from /dev/sda and writes them into /dev/sdb. It doesn't know what are files. So, the hard disk file system and how many partitions it has are not important. For example, if /dev/sda is splitted into three partitions, the /dev/sdb will have the same partitions. i.e. "destination" is completely same with "source".

Notice: to execute "dd" you should login as "root" or switch to "root" using "su" command. And you must be careful, a small mistake may cause a serious problem!

Making a Hard Disk Image File

Most of time you don't want to make a complete duplication of your hard disk. You may prefer to creating an image file of the hard disk and save it in other storage devices. The following command will create an image file "disk1.img" in your user's directory from /dev/sda:

dd if=/dev/sda of=~/disk1.img

Since you have created an image file, you can compress it with "gzip" or "bzip2":

gzip disk1.img #generates disk1.img.gz or

bzip2 disk1.img #generates disk1.img.bz2

You can save much storage space with compression. But it will take very long time.

Partition Clone

Backing up a hard disk partition is much similar to backing up a whole hard disk. The reason is that Unix/Linux uses device name, such as /dev/sda1, /dev/sda5... to indicate the partitions. For example, if you want to create an image file from the first partition of /dev/sda, use "dd" like this:

dd if=/dev/sda1 of=~/disk2.img

Also, you can compress the image file:

gzip disk2.img

By the way, you can copy a partition to another partition completely, just set "of" to the partition's device name. For example:

dd if=/dev/sda1 of=/dev/sdb5

This command will copy all the contents from /dev/sda1 to /dev/sdb5. You must be sure that the capacity of /dev/sdb5 is larger than /dev/sda1.

Restoring from an Image File

To restore a partition or a hard disk from an image file, just exchange the arguments "if" and "of". For example, restore the whole hard disk from the image file "disk1.img":

dd if=disk1.img of=/dev/sda

Restore the first partition of /dev/sda from the image file "disk2.img":

dd if=disk2.img of=/dev/sda1

转载于:https://www.cnblogs.com/linuxbo/p/4313747.html

你可能感兴趣的文章
4,7周围玩家
查看>>
关于webpack升级过后不能打包的问题;
查看>>
vue - 生命周期
查看>>
SQL Server用户权限详解
查看>>
Python正则表达式
查看>>
Linux进程间通信--命名管道
查看>>
UVa 10970 - Big Chocolate
查看>>
js输出
查看>>
set,env,export,set -x,set -e;
查看>>
H5多文本换行
查看>>
HAL层三类函数及其作用
查看>>
Odoo 去掉 恼人的 "上午"和"下午"
查看>>
web@h,c小总结
查看>>
java编程思想笔记(一)——面向对象导论
查看>>
Data Structure 基本概念
查看>>
Ubuntu改坏sudoers后无法使用sudo的解决办法
查看>>
NEYC 2017 游记
查看>>
【BZOJ 3669】 [Noi2014]魔法森林 LCT维护动态最小生成树
查看>>
[搬运] 写给 C# 开发人员的函数式编程
查看>>
vsftpd虚拟用户【公司系统部分享】
查看>>