LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 01-08-2007, 09:06 AM   #1
Rekna
Member
 
Registered: Mar 2004
Posts: 33

Rep: Reputation: 15
Writing to a USB hard drive


Hi,

I am trying to recover data from a friends hard drive that is barley limping along. I hooked it up as a slave to my primary drive and I am able to read it (it is ntfs). I also have a large usb drive that I am transferring files to. Unfortunately my computer has a tendency to lock up under a heavy load. I have been trying to copy some rather large directories over to this drive but my computer has a tendency to hard lock under heavy load. Transferring to the USB drive only seems to actually write the files when I unmount the drive. This means if I start a transfer and my computer crashes in the middle of the transfer none of the files get written (at least not correctly). Is there a way to do a more robust transfer that writes the files fully immediately, as if I were copying from 1 local hard drive to another?

Thanks
 
Old 01-08-2007, 09:41 AM   #2
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Try this. If the failing drive is mapped as /dev/hdb and the USB drive is mapped as /dev/sda and if you already have a file system on /dev/sda1 then do this.
Code:
mkdir /mnt/sda1
mount -o sync /dev/sda1 /mnt/sda1
sfdisk -l /dev/hdb > /mnt/sda1/ntfs-partition-layout.txt
dd if=/dev/hdb of=/mnt/sda1/ntfs-mbr.dd bs=512 count=1 conv=notrunc,noerror
dd if=/dev/hdb1 of=/dev/sda1/ntfs-dump.dd conv=notrunc,noerror
sync
Regarding your question, the mount command using the sync option is what you are asking about.

When the commands above finish you will have three files on the USB drive. The first one is named ntfs-partition-layout.txt. It will tell you exactly how many blocks are used for the NTFS partition. This is helpful when you restore the backup image to a new disk. The second file is called ntfs-mbr.dd. It is really not important if you are going to replace the drive. It is really more valuable if you were going to restore the original drive to a given state. The third file is called ntfs-dump.dd. This contains the data in NTFS format.

Now shut down your machine and remove the defective drive. Connect the drive that you intend to use for a replacement and start Linux again. Then use cfdisk to create a destination partition on the new disk. Use the information in the file named ntfs-partition-layout.txt to make the partition as close to the size of the partition on the original disk as is possible. The ntfs-partition-layout.txt file is a text file so you can just type it to see what it says. Use the cfdisk utility to create the new partition on the new drive.
Code:
cfdisk
Use the menu options to create a new partition of the correct size, set the partition type to NTFS, make the partition bootable, and write the partition table to disk.

Now you can restore the image of the old drive. First make sure that Linux can see the new partition.
Code:
ls /dev/hdb*
You should see a listing for /dev/hdb1. If you do not then you need to restart Linux or start the Linux hotplug daemon.

Now you can restore the data from the image backup like this. This example assumes that the USB drive is still mounted at /mnt/sda1.
Code:
dd if=/mnt/sda1/ntfs-dump.dd of=/dev/hdb1 conv=notrunc,noerror
sync
Now you can try to mount the partition to see if it worked.
Code:
mkdir /mnt/ntfs
mount -t ntfs /dev/hdb1 /mnt/ntfs
ls /mnt/ntfs
umount /mnt/ntfs
Now shut down your Linux computer and remove the drive with the new NTFS data. Install this drive into the original computer and see if it will boot. You may find that Windows will report that the drive was not cleanly unmounted and will run the check disk utility. This is a good sign. Hopefully the Windows system will run without problems.

Note 1: The new ntfs partition on the new drive must be as close to the size of the original as is possible. If you make it a lot larger than the original ntfs partition then you will probably not be able to use the larger space. This is because you cannot reformat the ntfs partition after the data is restored in order for the file system to see the larger space. Therefore, if you made the ntfs partition on the new disk a lot larger than the original then the best outcome that you could hope for is that all that extra space would be wasted. The worst outcome would be that the restore would fail and you have wasted your time.

Note 2: This procedure will copy the ntfs partition as it is. It will not fix file corruption. It will not defragment the partition. The nice thing about this procedure is that it does not use the ntfs driver. The dd command does not know what kind of data it is copying. Consequently it cannot fix the data errors. If this procedure does not work then it is likely that the ntfs partition on the original disk was not readable by dd due to hardware problems on the original disk. In that case you could use a different procedure with a different recovery tool such as ddrescue. http://www.gnu.org/software/ddrescue/ddrescue.html The REALLY nice thing about ddrescue is that you can run it multiple times and it will build on its previous successes.

Good luck.

Last edited by stress_junkie; 01-08-2007 at 10:34 AM.
 
Old 01-08-2007, 09:55 AM   #3
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
Hi

If you give the command "sync" - all will be written to disk (like when you unmount). Maybe "sync" after each file?

Another thing to try: Often crashing under load is heat related. (E.g. a slow fan or lots of dust) If you try to open the case, and put it under load and it doesn't crash, then it's heat related. Adding a fan or something will help then.

Edit:
I didn't see the other answer - looked better than mine
 
Old 01-08-2007, 10:18 AM   #4
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Quote:
Originally Posted by Guttorm
Edit:
I didn't see the other answer - looked better than mine
Thanks but I often find that I provide more information than the person wants. I don't always know when to stop typing.

Last edited by stress_junkie; 01-08-2007 at 10:31 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Installing grub to external USB hard drive for later use as internal hard drive dhave Linux From Scratch 2 12-10-2005 08:48 AM
Writing to a USB hard drive in Ubuntu rockatship Linux - Hardware 3 09-18-2005 03:18 PM
Writing to Hard Drive issue? Tekerz Linux - Hardware 0 06-23-2005 02:47 PM
Problem Writing to A Hard Drive Farquar210 Red Hat 5 06-23-2004 01:35 PM
Freeze while writing to hard drive Kristoffer Slackware 2 03-23-2003 01:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 03:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration