Linux Backup: Hard Disk Clone with "dd"

 

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

时间: 2024-10-13 02:24:10

Linux Backup: Hard Disk Clone with "dd"的相关文章

Linux下分割、合并文件——dd和cat

功能说明:读取,转换并输出数据. 语 法:dd [bs=<字节数>][cbs=<字节数>][conv=<关键字>][count=<区块数>][ibs=<字节数>][if=<文件>][obs=<字节数>][of=<文件>][seek=<区块数>][skip=<区块数>][–help][–version] 补充说明:dd可从标准输入或文件读取数据,依指定的格式来转换数据,再输出到文件,设备或

Linux入门之磁盘管理(5)dd命令使用

在Linux中,经常需要一些数据读写等测试,还有文件以及其它数据的备份迁移,一般使用cp命令可以解决一部分,但是其无法进行控制数据的流向及动作,这时就可以使用dd命令,来进行灵活的数据流操作. dd 命令用法: dd  if=/PATH/FROM/SRC  of=/PATH/TO/DEST #解析:if表示inputfile,表示从if所指的文件读取数据流,然后输出到of所指的文件 详细解析: bs=# :block size,复制单元大小,默认不指定为byte,可以指定M count=#:  

linux backup

sudo tar cvpjf backup.tar.bz2 --exclude=/proc --exclude=/lost+found --exclude=/backup.tar.bz2 --exclude=/mnt --exclude=/sys --exclude=/data --exclude=/opt --exclude=/home/ak/work / sudo tar xvpfj backup.tar.bz2 -C /

linux下每次git clone不需输入账号密码的方法

在~/下, touch创建文件 .git-credentials, 用vim编辑此文件,输入内容格式: ame@zhenyun ~ $touch .git-credentials ame@zhenyun ~ $vim .git-credentials 在里面按“i”然后输入:https://{username}:{password}@github.com 比如 https://aoeddklj:[email protected] 2. 在终端下执行 ame@zhenyun ~ $git conf

tiny core linux backup保存文件和配置信息

Backup Backup may be used to save files and settings in Tinycore. Time taken to Start Up and Shut Down The more you have in backup, the longer it will take to start up and shut down Tinycore. For quicker start up and shut down, minimize the size of b

linux dd实现磁盘完整全盘镜像备份backup,恢复recover(restore)

1,dd操作就是简单的按字节复制,什么分区表啊,MBR(master boot record)啊统统照搬; 1. 磁盘克隆 也就是把整个硬盘复制一份.当然你首先需要在计算机上在接上一块新硬盘,并让系统识别.例如这块硬盘可能被识别为/dev/sdb,原有硬盘叫/dev/sda. 然后你可以在linux命令行上简单地执行: dd if=/dev/sda of=/dev/sdb 对就这么简单,此命令完成后,你的第二块硬盘上将有一个和第一块硬盘一模一样的副本,也是可以启动的.因为dd操作就是简单的按字节

linux系统--free,交换分区,mkswap,swapon,swapoff,dd,自动挂载,fuser

swap分区: free -m fdisk命令中,调整分区类型为82: 创建交换分区: mkswap /dev/sda8 -L LABEL swapon /dev/sda8 -a:启用所有的定义在/etc/fstab文件中的交换设备 swapoff /dev/sda8 [[email protected] ~]# free total       used       free     shared    buffers     cached Mem:       1906492     346

Linux -- dd 命令

11.2 `dd': Convert and copy a file================================== `dd' copies a file (from standard input to standard output, by default)with a changeable I/O block size, while optionally performingconversions on it.  Synopses: dd [OPERAND]...    

用dd实现linux硬盘备份

一个去年的老本,500G硬盘,空间各种捉急,准备迁移到公司的台式机上,却发现Linux上迁移环境没有Windows下那么方便,只能复制整块硬盘了. 从公司拿了一块1T的硬盘,插入移动硬盘盒(淘宝上搞的一个移动硬盘盒,40元),加电识别,格式化,开始硬盘复制. 市面上针对数据备份的软件不计其数,我们不讨论他们的优缺点.但是如果你正在使用Linux(其实如果你没有使用Linux,而是通过一些 Linux live CD来启动计算机,我想也是一样的),那么恭喜你,你可以简单地使用系统命令"dd&quo