Skip to main content

How to backup Linux OS using “dd” Command

“dd” command can be really handy when it comes to taking an Operating System backup to clone the disk the OS is installed on. Here are few examples of using dd command for taking OS backup.
NOTE: The target drive must be either of identical size to the drive being cloned or larger. The dd command will copy both used and unused space from the target.

1. Backup Entire Hard disk To another DISK

1. In Below example we want to clone disk “sda” and have an identical disk on the server as “sdb”.
# fdisk -l
Disk /dev/sda: 12.9 GB, 12884901888 bytes
255 heads, 63 sectors/track, 1566 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00010897

Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 1567 12069888 8e Linux LVM

Disk /dev/sdb: 12.9 GB, 12884901888 bytes
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
2. To backup an entire copy of a hard disk to another hard disk connected to the same system, execute the dd command. The UNIX device name of the source hard drive is /dev/sda, and device name of the target hard disk is /dev/sdb, sync option allows to copy everything using synchronized I/O.
# dd if=/dev/sda of=/dev/sdb conv=noerror,sync
25165824+0 records in
25165824+0 records out
12884901888 bytes (13 GB) copied, 453.846 s, 28.4 MB/s
Here,
if: source disk drive (/dev/sda)
of: destination disk drive (/dev/sdb)
bs: read and write BYTES at a time (default is 512 Bytes, You can use bs=64k for bigger disks)
noerror: continue after read errors.
sync: use synchronized I/O for data, also for metadata
3. If want To restore data to original disk you need to repeat the previous step with the correct source(sdb) and destination(sda). You can even remove sda and boot from sdb in this case.
CAUTION: Reversing the arguments within a dd command can lead to erasing all of your precious data. Make sure to know the location and names of both your source(if=) and your target(of=).

2. Backup Entire Hard disk To disk image

1. You can create an image file of the hard disk and save it in other storage devices. There are many advantages to backing up your data to a disk image, one being the ease of use. This method is typically faster than other types of backups, enabling you to quickly restore data following an unexpected catastrophe. Use the command below to backup the hard disk /dev/sda to a disk image file.
# dd if=/dev/sda of=/var/tmp/sda_disk.img
Here,
if: source disk drive (/dev/sda)
of: destination disk drive (/dev/sdb)
2. To restore a hard disk with the image file of an another hard disk, use the following dd command example.
# dd if=sda_disk.img of=/dev/sdc
Here,
if: source disk drive (/dev/sda)
of: destination disk drive (/dev/sdb)

3. Backup Entire Hard disk To disk image on NFS and restoring it

1. Check if there is enough space on nfs server available.
# showmount -e nfs_server_IP
Export list for xx.xx.xx.xx:
/nfsshare *
# df -h
Filesystem                Size   Used  Avail  Use%  Mounted on
xx.xx.xx.xx:/nfsshare     16G    44M   15G    1%    /nfs_test
2. Create the image. Make sure you have enough bandwidth available.
# dd if=/dev/sda of=/nfs_test/sda_disk.img
25165824+0 records in
25165824+0 records out
12884901888 bytes (13 GB) copied, 263.396 s, 48.9 MB/s
Here,
if: source disk drive (/dev/sda)
of: destination disk drive (/dev/sdb)
3. To restore from the backup disk image on nfs (such as if there is a disk failure on disk sda and the system can’t boot), boot into rescue mode with networking.
4. Mount the nfs share. Let’s say newly created directory /nfsshare.
5. Restore sda using disk image backup.
# dd if=/nfsshare/sda_disk.img of=/dev/sda
Here,
if: source disk drive (/dev/sda)
of: destination disk drive (/dev/sdb)
6. Reboot the server.
# shutdown -r now

Comments

Popular posts from this blog

Cisco SG300 CLI Commands

Cisco SG300 CLI Commands Other parts were obtained using the CLI PDF provided by Cisco Remove a Trunk and switch to access config t int gi44 switchport trunk allowed vlan remove 2 switchport mode access switchport access vlan 2 or config t int gi44 switchport mode general switchport general allowed vlan remove 2 switchport mode access switchport access vlan 2 Change CDP Device ID Format to Hostname opposed to default MAC address s-sg300#sh cdp Global CDP information:         CDP is globally enabled         CDP log duplex mismatch is globally enabled         CDP log voice VLAN mismatch is globally enabled         CDP log native VLAN mismatch is globally enabled         Mandatory TLVs validation is disabled         Sending CDPv2 advertisements is enabled         Sending Appliance TLV is enabled       ...

Branches, Part II

Now that we’ve covered the mechanics behind Git branches, we can discuss the practical impact that they have on the software development process. Instead of introducing new commands, this module covers how the typical Git user applies this workflow to real projects, as well as some of the problems that arise in a branched environment. To Git, a branch is a branch, but it’s often useful to assign special meaning to different branches. For example, we’ve been using master as the stable branch for our example project, and we’ve also used a temporary branch to add some CSS formatting. Temporary branches like the latter are called topic branches because they exist to develop a certain topic, then they are deleted. We’ll work with two types of topic branches later in this module. Amid our exploration of Git branches, we’ll also discover that some merges cannot be “fast-forwarded.” When the history of two branches diverges, a dedicated commit is required to combine the branches. This ...

Distributed Workflows

Now that we know how to share information via a centralized workflow, we can appreciate some of the drawbacks of this collaboration model. While it may be convenient, allowing everyone to push to an “official” repository raises some legitimate security concerns. It means that for anyone to contribute content, they need access to the entire project. This is fine if you’re only interacting with a small team, but imagine a scenario where you’re working on an open-source software project and a stranger found a bug, fixed it, and wants to incorporate the update into the main project. You probably don’t want to give them push-access to your central repository, since they could start pushing all sorts of random snapshots, and you would effectively lose control of the project. But, what you can do is tell the contributor to push the changes to their own public repository. Then, you can pull their bug fix into your private repository to ensure it doesn’t contain any undeclared code. If y...