Backup and Restore of LINUX System Disk using "dd" command:

Backup and Restore of LINUX System Disk using "dd" command:

creating disk1:

# dd if=/dev/zero of=disk1 bs=1024000 count=2048

# mkdir d1

# mkfs.ext3 disk1

# mount disk1 d1 // It will end with error, so try,

# mount -o loop disk1 d1

creating disk2:

# dd if=/dev/zero of=disk2 bs=1024000 count=2048

#mkfs.ext3 disk2

# mkdir d2

# mount -o loop disk2 d2

# df -h -----  result will be,

We can also use conv=notrunc,noerror options with "dd" command ,

- The notrunc conversion option means do not truncate the output file — that is, if the output file already exists, just replace the specified bytes and leave the rest of the output file alone.

- Noerror means to keep going if there is an error. Dd normally terminates on any I/O error.

to confirm this,

# losetup -a
/dev/loop0: [fd00]:142387 (/root/disk1)
/dev/loop1: [fd00]:142390 (/root/disk2)

copy some file into d1 for example:

# wget http://ipv4.download.thinkbroadband.com/512MB.zip

shows like:

# ll /root/d1
total 541048
-rw-r--r--   1 root root  16589672 Dec 23 22:14 1GB.zip
-rw-r--r--   1 root root 536870912 May 30  2008 512MB.zip
drwxr-xr-x. 69 root root      4096 Dec 23 22:06 etc
drwx------   2 root root     16384 Dec 23 21:58 lost+found

Making image for /root/disk1:

Now it creates the image of /root/disk1.

[root@ranjith ~]# dd if=/root/disk1 of=~/d1backup.img
dd: writing to `/root/d1backup.img': No space left on device
3562841+0 records in
3562840+0 records out
1824174080 bytes (1.8 GB) copied, 47.1943 s, 38.7 MB/s

# pwd
/root/d2
# ls
lost+found

Restore the image on another partition:

# dd if=d1backup.img of=/root/disk2
3562840+0 records in
3562840+0 records out
1824174080 bytes (1.8 GB) copied, 46.6134 s, 39.1 MB/s

The above command will restore the image (d1backup.img) of /root/disk1 to /root/disk2.

# ll /root/d2
total 541048
-rw-r--r--   1 root root  16589672 Dec 23 22:14 1GB.zip
-rw-r--r--   1 root root 536870912 May 30  2008 512MB.zip
drwxr-xr-x. 69 root root      4096 Dec 23 22:06 etc
drwx------   2 root root     16384 Dec 23 22:05 lost+found

Comments

Popular posts from this blog

Resolved: DOCKER: Error response from daemon: Could not attach to network / rpc error: code = 7 desc = network not manually attachable.

yum failed 6 times. Cannot continue!

unexpectedly shrunk window (repaired) in dmesg log - TCP Peer