Hi all, the following will be a quick and dirt list of commands for use “dd” in a linux system for various task.

First of all you should create an Hard Disk Image, for example if you want to create an image of your /dev/sda device, you should have another disk (with a writable partition) (i.e. /dev/sdb) with a directory (i.e. /home mounted on it) and simply type :

dd if=/dev/sda of=/home/sda.bin

Or even a partition backup using the same disk device for source and destination like the following (if for example you have /home mounted on /dev/sda2) :

dd if=/dev/sda1 of=/home/sda1.bin

You should even create a compress image of the same disk above, using GZIP, simply type the following :

dd if=/dev/sda1 | gzip > /home/sda1.bin.gz

One of the most useful use of dd (it’s saved my life a lot of time) will be :

dd if=/dev/sda of=sda.boot.mbr bs=512 count=1

With the above command, you have backuped up your MBR (Master Boot Record) of your /dev/sda device and in case of disaster you should restore it, for example booting with a live CD using the following :

dd if=sda.boot.mbr of=/dev/sda bs=512 count=1

You should also create a manual RAID1 between two disk by executing the followinf script with a cron job :


#!/bin/sh
#

LOG="/var/log/mirror.log"
ADMIN="yourmail@yourprovider.ext"
ERROR=0

echo `/bin/date` >$LOG 2>&1
/bin/dd if=/dev/sda of=/dev/sdb bs=1M >>$LOG 2>&1
ERROR=$?
echo `/bin/date` >>$LOG 2>&1

if [ $ERROR -ne 0 ]; then
cat $LOG | /bin/mail -s "Report mirror `uname -n`" $ADMIN
fi

The above sript will copy the entire /dev/sda to /dev/sdb logging the process and send an email to your email address at the end for debug and monitoring purpose.
If the first hard disk (/dev/sda) fail, you should phisicaly umount it, and subsitute it with /dev/sdb then reboot the system.

Hope this help

Bye
Riccardo

Print This Post Print This Post

Leave a Reply

Spam Protection by WP-SpamFree

Contacts
Look at me at Linkedin Follow me on Twitter
My Flickr Albums My Facebook profile My YouTube Videos
SkypeMe My Linux Counter GMail me
Search
Google Search
Categories
Tag Cloud 3D
FeedBurner RSS

Visitors
Locations of visitors to this page
VMware related Blogs
The following are Blog sites with feeds I personally follow. When I'll have some spare time I will complete all Feed and Twitter links.