LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-22-2007, 03:06 PM   #1
transparent9
LQ Newbie
 
Registered: May 2007
Posts: 14

Rep: Reputation: 0
Unhappy I think I copied a file over my entire Windows partition


I'm not new to computers, but I'm pretty new to Linux so I'm not sure exactly what happened under the hood here...

I was trying to copy a file from my desktop to my Windows partition in Ubuntu Desktop 7.04.

The Windows partition is NTFS, and I didn't set up NTFS-3G yet, but I didn't know at the time that NTFS is read only by default.

The exact command I did was:

sudo cp ~/Desktop/windows.iso /dev/sda1


Now I realize a) my drive was mounted under /media/sda1 and b) I should have specified the filename as in /dev/sda/windows.iso. I used sudo because when I tried to drag and drop to the drive, it said I didn't have write permission. I didn't realize at the time that it was because NTFS was read-only...

windows.iso is the vmware tools package that came with vmware server. Now, I have a volume mounted labeled "vmware tools", and parted sees a 20gb partition that used to be my Windows partition as an unrecognized filesystem.

So... what happened? Is my partition lost? Is there a way to repair it? Did I actually replace an entire 20gb partition with a 13mb ISO? Or did something else happen under the hood here?

Thanks for any insight...!
 
Old 05-22-2007, 03:46 PM   #2
Emerson
LQ Sage
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~amd64
Posts: 7,675

Rep: Reputation: Disabled
Welcome to LQ!

That was a clever and powerful command you issued there. You copied the ISO file to the raw device sda1 effectively ignoring the filesystem on it. Doing that you destroyed the filesystem structure. In other words, your Windows is fubared now.
 
Old 05-22-2007, 04:14 PM   #3
transparent9
LQ Newbie
 
Registered: May 2007
Posts: 14

Original Poster
Rep: Reputation: 0
Does that mean there is no way to repair the damage?
 
Old 05-22-2007, 04:23 PM   #4
Emerson
LQ Sage
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~amd64
Posts: 7,675

Rep: Reputation: Disabled
You overwrote first 13 MB of your Windows partition. Everything located there is gone for good. The rest of sda1 may be salvaged ... probably. Do not know a thing about NTFS nor tools that work on NTFS.
 
Old 05-22-2007, 04:55 PM   #5
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
You've discovered the reason we tell people not to run as root. When you do things as root (even through sudo) the system assumes you know what you want to do. In this case, that was to overwrite the /dev/sda1 partition with the iso file. Writing to /dev/sda1/SOMEFILE would have failed, as /dev/sda1 is not a directory.

I would try running a program called 'testdisk'. It can (often) recover filesystem structures from backups later in the filesystem. The first 13MB is gone though. You're lucky the file was so small.
 
Old 05-22-2007, 05:08 PM   #6
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Linux 11 (Bullseye)
Posts: 3,409

Rep: Reputation: 141Reputation: 141
Quote:
The first 13MB is gone though. You're lucky the file was so small.
Yes, but doesn't that mean that he's lost his entire directory tree? Sure, much of the data is there, but only as raw data. There's no practical way to get at it in any useful manner, is there?
 
Old 05-22-2007, 05:13 PM   #7
transparent9
LQ Newbie
 
Registered: May 2007
Posts: 14

Original Poster
Rep: Reputation: 0
Thanks for the info everyone. Now to see if I can salvage the rest of the drive...
 
Old 05-22-2007, 05:25 PM   #8
Junior Hacker
Senior Member
 
Registered: Jan 2005
Location: North America
Distribution: Debian testing Mandriva Ubuntu
Posts: 2,687

Rep: Reputation: 61
I would tend to agree with Quakeboy02. I'm not as educated in ntfs as Fat, but the first sector (512B) of a partition is usually used/reserved for boot code. The next two sectors (if I remember correctly), is the Fat (file allocation table), which is the directory structure to find files in the partition. I believe ntfs is not much different, Linux file systems use "super blocks" spread through the entire partition for the directories.
So using photorec or foremost can retrieve lost data in the partition, but the data at this point cannot be found through a format structure.
 
Old 05-22-2007, 05:39 PM   #9
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by Quakeboy02
Yes, but doesn't that mean that he's lost his entire directory tree? Sure, much of the data is there, but only as raw data. There's no practical way to get at it in any useful manner, is there?
The bootblock, partition table, and partition boot sector are all gone.

The bootblock can easily be rewritten, and there are any number of tools that can take a good stab at recovering the partition table. In fact, if the end of the first partition can be unambiguously identified, then the partition table for the first partition can be rebuilt manually with only a moderate amount of skill required (you simply assume it starts on the Cylinder 1).

The NTFS filesystem can be recovered far more easily than you might at first think because there is a duplicate copy of the partition boot sector at the end of the partition.

I really doubt that the system will boot after recovery; good chance that ntldr was taken out as well as boot.ini. But the drive is certainly recoverable.

Actually, it had never occurred to me that it was possible to write directly to /dev/hda; I would have expected the lack of a filesystem to prevent that. Other than with dd, I've never tried it.

Might be worth some fooling around; I wonder if an iso could be copied directly to a device using cp and have it work...
 
Old 05-22-2007, 05:45 PM   #10
Junior Hacker
Senior Member
 
Registered: Jan 2005
Location: North America
Distribution: Debian testing Mandriva Ubuntu
Posts: 2,687

Rep: Reputation: 61
Quote:
Originally Posted by jiml8
Actually, it had never occurred to me that it was possible to write directly to /dev/hda; I would have expected the lack of a filesystem to prevent that. Other than with dd, I've never tried it.

Might be worth some fooling around; I wonder if an iso could be copied directly to a device using cp and have it work...
Same question was poking at me.
 
Old 05-22-2007, 06:17 PM   #11
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Copying data directly to a device is certainly possible. All 'dd' does is open it like any other file.

As jiml8 points out, there is a backup copy of the filesystem structures in an NTFS partition. testdisk can usually recognize this and repair it. I also agree that it's unlikely to boot: the early files are likely to be critical ones.
 
Old 05-22-2007, 06:59 PM   #12
transparent9
LQ Newbie
 
Registered: May 2007
Posts: 14

Original Poster
Rep: Reputation: 0
Ok, in case anyone is curious, an update.

I ran testdisk, and used it to rebuild the rebuild the bootsector and repair the mft.

Then, I booted off the XP SP2 CD and from the recovery console, did chkdsk and then fixboot.

Now, amazingly, XP boots, though some things are a little screwy, like my taskbar is stuck at the bottom like I dragged it to be no lines tall, if that makes sense. It just looks like the top edge of the taskbar, but I can't drag it taller, even though the mouse changes to the up and down arrow draggy thing.

Most things appear OK. I think I can repair the Windows partition using a repair install.

HOWEVER, in ubuntu, the partition still doesn't show up under "my computer". I still see "vmware tools" as a volume. Is there something I can do to have ubuntu "reset" things, like redetect all my partitions or something? It also doesn't show up in the Hardware Information applet (vmware tools does), though testdisk and parted appear to see the partition OK.
 
Old 05-22-2007, 07:09 PM   #13
Junior Hacker
Senior Member
 
Registered: Jan 2005
Location: North America
Distribution: Debian testing Mandriva Ubuntu
Posts: 2,687

Rep: Reputation: 61
I wonder what Windows System Restore would do at this point for Windows?
Sometimes, when Windows reports errors, Linux will not mount it till Windows reports all errors fixed, rebooting Windows twice has been recommended to take care of that (not sure of the validity of this). Make sure the entries are still there in fstab.

Last edited by Junior Hacker; 05-22-2007 at 07:12 PM.
 
Old 05-22-2007, 08:10 PM   #14
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,286

Rep: Reputation: 4165Reputation: 4165Reputation: 4165Reputation: 4165Reputation: 4165Reputation: 4165Reputation: 4165Reputation: 4165Reputation: 4165Reputation: 4165Reputation: 4165
Let's see the output of
Code:
sudo fdisk -l
cat /etc/fstab
(that's a lower case ell in the first command)
 
Old 05-22-2007, 08:27 PM   #15
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Linux 11 (Bullseye)
Posts: 3,409

Rep: Reputation: 141Reputation: 141
Wow! Looks like filesystems have come a long way since I looked at FAT and UDF.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
mount partition from copied block device cs-cam Linux - General 0 09-23-2006 08:41 PM
Reinstalling GRUB on a copied partition Exasperated Linux - General 3 02-05-2005 06:02 PM
Windows files copied to my linux partition are locked when logged in as a normal user necbrownie Slackware 8 10-15-2004 09:11 AM
What is the code to copy a file from my windows partition to my linux partition? THEBIGFISH Linux - Newbie 3 03-15-2004 11:14 PM
Windows XP hogs entire 40 GB Hard Drive with one Partition jedi_zach Linux - General 2 02-09-2004 01:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:32 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