Wednesday, April 27, 2011

Recover Data from a Damaged hard disk using dd_rhelp

dd_rhelp is a bash script that handles a very usefull program written in C which is called dd_rescue, it roughly act as the dd linux command with the caracteristic to NOT stop when it falls on read/write errors.
This makes dd_rescue the best tool for recovering hard drive having bad sectors.In short, it’ll use dd_rescue on your entire disc, but will try to gather the maximum valid data before trying for ages on badsectors. So if you leave dd_rhelp work for infinite time, it’ll have the same effect as a simple dd_rescue. But because you might not have this infinite time , dd_rhelp will jump over bad sectors and rescue valid data. In the long run, it’ll parse all your device with dd_rescue.
You can Ctrl-C it whenever you want, and rerun-it at will, it’ll resume it’s job as it depends on the log files dd_rescue creates.In addition, progress will be shown in a ASCII picture of your device beeing rescued.
Why use dd_rhelp and not dd_rescue ?
dd_rhelp uses dd_rescue to compute a recovery path through the device that will focus on valid data recovering. This recovery path will go through all the device, exactly as dd_rescue could do it on its own without any path. This means that dd_rhelp will save you time ONLY IF YOU INTEND TO CANCEL ITS JOB BEFORE THE END of a full recovery.
Because a considerable amount of time is taken to try to rescue badsectors. This amount of time can be mesured in days,
month, years, depending on your device capacity and its defectiveness. You might not want to spend this time knowing that 99 percent of this time will be taken to look at badsector and won’t lead to any more data recovering.
dd_rhelp shifts this useless waiting time to the end. Using dd_rescue strait throughout your device make your waiting time dependent on the badsector distribution.
Install dd_rhelp
First you need to download latest version from here
Preparing your system
#apt-get install make gcc g++ ddrescue
If you are using ubuntu linux use the following command
sudo apt-get install make gcc g++ ddrescue
Download dd_rhelp using the follwoing command
wget http://www.kalysto.org/pkg/dd_rhelp-0.0.6.tar.gz
Now you have dd_rhelp-0.0.6.tar.gz file
Extract this file using the following command
tar xzvf dd_rhelp-0.0.6.tar.gz
cd dd_rhelp-0.0.6
Run the following commands
# ./configure
# make
# make install
If you are using ubuntu linux use the following command
sudo ./configure
sudo make
sudo make install
This will complete the installation and this will install program under /usr/local/bin/dd_rhelp
dd_rhelp Syntax
dd_rhelp {filename|device} {output-file} [{info}]
or dd_rhelp --help
or dd_rhelp --version
Now we will see how to use ddrescue under damaged disk
If you have a damaged hard disk /dev/sda1 and you have an empty space hard disk /dev/sda2 Now if you want to copy data from /dev/sda1 to /dev/sda2 use the following command
#dd_rhelp /dev/sda1 /dev/sda2/backup.img
If you are using ubuntu linux use the following command
sudo dd_rhelp /dev/sda1 /dev/sda2/backup.img
Output looks like below
/usr/bin/tail: Warning: “+number” syntax is deprecated, please use “-n +number”
=== launched via ‘dd_rhelp’ at 0k, 0 >>> ===
dd_rescue: (info): ipos: 104384.0k, opos: 104384.0k, xferd: 104384.0k
errs: 0, errxfer: 0.0k, succxfer: 104384.0k
+curr.rate: 10178kB/s, avg.rate: 8532kB/s, avg.load: 31.3%
dd_rescue: (info): /dev/sda2 (104391.0k): EOF
Summary for /dev/sda2 -> backup.img:
dd_rescue: (info): ipos: 104391.0k, opos: 104391.0k, xferd: 104391.0k
errs: 0, errxfer: 0.0k, succxfer: 104391.0k
+curr.rate: 355kB/s, avg.rate: 8519kB/s, avg.load: 31.3%
/usr/bin/tail: Warning: “+number” syntax is deprecated, please use “-n +number”
This copies an image of /dev/sda1 to sda2
Now you need to check the backup image consistency this will check for is there any problems with this image.
#fsck -y /dev/sda2/backup.img
If you are using ubuntu linux use the following command
sudo fsck -y /dev/sda2/backup.img
After finishing this checking you need to mount your disk image in to your other hard disk
#mount /dev/sda2/backup.img /mnt/recoverydata
If you are using ubuntu linux use the following command
sudo mount /dev/sda2/backup.img /mnt/recoverydata
This will mount all the data from the backup.img under /mnt/recoverydata now you can try to access the data it should
work without any problem.
Restore image
If you want to restore this image use the following command
#dd_rhelp /dev/sda2/backup.img /dev/sda1
If you are using ubuntu linux use the following command
sudo dd_rhelp /dev/sda2/backup.img /dev/sda1
Copy Disk Image to remote machine using SSH
If you want to copy your disk image to remote machine over ssh you need to use the following command
#dd_rhelp /dev/sda1 - | ssh username@machineip ‘cat /datarecovery/backup.img’
If you are using ubuntu linux use the following command
sudo dd_rhelp /dev/sda1 - | ssh username@machineip ‘cat /datarecovery/backup.img’
This will be prompetd for password of the username you have menctioned in the above command after entering the password
dd_rhelp strats copying obviously it will take some time to copy over the network.

Backup and Restore Linux Partitions Using Partimage

Partition Image is a Linux/UNIX utility which saves partitions in many formats (see below) to an image file. The image file can be compressed in the GZIP/BZIP2 formats to save disk space, and split into multiple files to be copied on removable floppies (ZIP for example), … Partitions can be saved across the network since version 0.6.0.When using Partimage, the partitions must be unmounted.
Partimage is veryuseful in the following situations
First you can restore your linux partition if there is a problem (virus, file system errors, manipulation error) . When you have a problem, you just have to restore the partition, and after 10 minutes, you have the original partition. You can write the image to a CD-R if you don’t want the image to use hard-disk space.
This utility can be used to install many identical computers. For example, if you buy 50 PCs, with the same hardware, and you want to install the same linux systems on all 50 PCs, you will save a lot of time. Indeed, you just have to install on the first PC and create an image from it. For the 49 others, you can use the image file and Partition Image’s restore function.
Supported file systems
ext2fs/ext3fs,Reiser3,FAT16/32,NTFS,HPFS,JFS,XFS,UFS(beta),HFS(beta)
Install Partimage in Ubuntu
First you need to make sure in your /etc/apt/sources.list file universe source list is enabled.
sudo apt-get install partimage
Install Partimage in Debian
#apt-get install partimage
This will complete the installation now
Before starting application you can check the all the available partitions using the following command
For Ubuntu Users
sudo fdisk -l
For debian users
#fdisk -l
Backup Partition
if you want to run the application use the following command
For Ubuntu Users
sudo partimage
For debian users
#partimage
Once it opens the application you should see similar to the following screen
Once you launch PartImage, use the Up and Down arrows to select which partition to back up.
Type the name of the path and file where you’re going to back up the partition.In this example I mounted the backup partition at /backup, I have to type /backup/serverbackup and not just serverbackup.
Action to be done should be Save partition into a new image file.
On the next screen, use no compression if you want the backup to be quicker. You really should use the Gzip or Bzip2 options only if your external hard drive or other backup partition is too small to hold the contents of the partition you’re backing up.
Now you should remember that the backup will save only the used space on the partition.So, if you have a 100 GB partition you’re backing up and only 11 GB of it is used, the partition image will be only 11 GB.
Now you press F5 to Continue for next screen here you need to enter a description of the save partition.
After PartImage examines the partition data for a while, it’ll give a summary of the partition.Here select ok and press enter
PartImage will start saving your partition to an image file on the backup partition and you can see the progress in the following screen.
Now you can see in the following screen backup partition operation completed successfully.
Then, you’ll be back to the terminal prompt.
Restore Partition
if you want to run the application use the following command
For Ubuntu Users
sudo partimage
For debian users
#partimage
Once it opens the application you should see similar to the following screen here you need to select the partition to restore,image file to use in my case i have saved my partition image file as serverbackup.000 if you want to menction .img extension at the time of backup it will save as .img file otherwise it will save as .000 extension,select restore partition from an image file option under action to be done select F5 for next screen
You should see the following screen select ok and press enter
Now you should see the following screen here you need to select the options The only extra option you can choose is Erase free blocks with zero values. If this option is enabled, all blocks which are not used are erased with zero bytes. This may be useful if you want to be sure that the data which were on the partition before this operation are fully erased. If this option is disabled, old data which was on currently unused blocks can be accessed (with some difficulty), because nothing is written on these blocks. These old data can be read with tools such as dd (GNU convert and copy) and press F5 to continue.
The partition to restore must have the same size as the saved partition. If the partition is smaller than the original one, the operation will fail. If it is bigger, space can be lost.
Now you should see the summary of restore partition information select ok and press enter
Confirm the image file you want to restore
Restore partition from an image file is in progress
Restore partition from an image file is completed successfully completed select ok and press enter Then, you’ll be back to the terminal prompt.

File Server Configuration in Debian Using Samba

Samba is a suite of Unix applications that speak the SMB (Server Message Block) protocol. Many operating systems,including Windows and OS/2, use SMB to perform client-server networking. By supporting this protocol, Samba allows Unix servers to get in on the action, communicating with the same networking protocol as Microsoft Windows products.
Install Samba in Debian
#apt-get install samba samba-common samba-client
This will start samba installation and prompted for the following questions
First you need to enter the Workgroup/Domain Name in this example i am using ruchi select ok and press enter
You want to use password encryption select yes and press enter
If you want to modify smb.conf to use WINS settings from DHCP.If you want select yes in this example i am selecting no
and press enter
Next one is how do you want to run samba daemon or inetd in this example i have selected as daemon and press enter
You want to craete samba password database file select yes and press enter
This will complete the samba installation part.
Preparing directories and users
Create directories for Samba to use with Windows
#mkdir windowsshare
Now we need to create users to access this directiory
#useradd david
Now create a password for this user using the following command
#smbpasswd -a david
Samba configuration
By default samba configuration file located at /etc/samba/smb.conf
In this file main section is Global where you can define all parameters and the example as follows
[global]
workgroup = ruchi
netbios name = fileserver
server string = %h server (Samba %v)
log file = /var/log/samba/log.%m
max log size = 1000
syslog = 0
Now you need to configure the share directory(ex:-samba) for users below is the example.
[SAMBA]
path=/windowsshare
browseable=yes
writeable=yes
valid users = david
admin users = debian
Testing Your Samba Permissions
If you want to check your configuration file is correctly configured or not you need to run the following command
#testparm
Output looks as follows
Load smb config files from /etc/samba/smb.conf
Processing section “[homes]”
Processing section “[printers]”
Processing section “[print$]”
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions
Now you need to restart the samba server using the following command
#/etc/init.d/samba restart
If you want to know more configuration options available for samba check samba config man page

Testing your samba configuration
You want to test your samba configuration for user david run the following command
#smbclient -L //serverip -U david
Mounting Samba Directories in Linux
Linux can view your Samba shared directories as it does any other medium (hard disk, NFS shares,CD-ROM, and so on).
Use mount to mount a Samba shared file system so that it is permanently connected to your Linux file system.Here’s an example of the mount command in which a home directory (/home/david) from a computer named toys on a local directory (/mnt/toys) is mounted. The command is typed, as root user, from a Terminal window:
# mkdir /mnt/toys
# mount -t smbfs -o username=david,password=test //toys/david /mnt/toys
The file system type for a Samba share is smbfs (-t smbfs). The username (david) and password (test) are passed as options (-o). The remote share of the home directory on toys is //toys/david. The local mount point is /mnt/toys. At
this point, you can access the contents of /home/david on toys as you would any file or directory locally. You will have the same permission to access and change the contents of that directory (and its subdirectories) as you would if you were the user chris using those contents directly from toys.
To mount the Samba shared directory permanently, add an entry to your /etc/fstab file. For the example just described,
you’d add the following line (as root user):
//toys/david /mnt/toys smbfs username=david,password=test
Troubleshooting Samba Server
If your Samba server isn’t working properly you need to check the following procedure
1) First you need to check your basic networking is working or not
2) Check Samba Service is Running or not using the following command
$ smbclient -L localhost
Password: **********
3) Make sure that your firewall ports are open.You need to open access to ports 137, 138, and 139 in your firewall so
that the Samba server can accept connections for services.
4) Make sure user passwords are working.Try accessing a shared Samba directory as a particular user using the
following command.
# smbclient //localhost/tmp -U david
In this example, smbclient connects to the directory share named tmp as the Samba user named david. If the password is
accepted, you should see information about the server and a smb:\> prompt.
Configuring the Windows workstations
logon to the Windows workstation as any user with administrative priviliges
[Windows 2000] Start -> Settings -> Control Panel -> System -> Network Identification -> Properties -> Member of ->
Domain -> type the domain name as specified in the ‘workgroup’ section of smb.conf -> ok
[Windows XP] Start -> Control Panel -> System -> Computer Name -> change -> Member of -> Domain -> type the domain name as specified in the ‘workgroup’ section of smb.conf file -> ok
enter the root username and password for the Samba file server
if you simply wish to transfer existing users from a workstation, then if a user exists on the Samba file server and on the workstation, at this point you could log them into the Samba file server and their profile from the workstation would be copied to the Samba file server when they log out