# I accidentally put swap file on my NTFS partition and lost data. Am I screwed?



## AiMingQi (Feb 21, 2009)

I had a complete windows failure and couldn't load windows on my drive. I installed Kubuntu onto one of my open partitions to see if the hd was actually broken. Then I created a swap file on another partition but I accidentally choose the wrong partition. I choose one that is loaded with my entire photo collection. I have some of it backed up, but my latest work is still there. I am going to be really sad if it is completely gone. 

I put on a fresh install of Windows onto another partition, but Windows won't read the affected partition and I can't do a 'quick' format back to NTFS and hope that the data is not gone. I plan to use pcinspector to recover the data. It is a 100gb partition so there is a lot of data there and I'm sure Kubuntu's swap file only affected a small part of the partition. But I can't figure out how to convert the partition back to NTFS. 

Does anyone know what affect Kubuntu might have had on that drive?

I'm really unclear how to use Kubuntu. I only experiemented with it a little. Which is why I got into this mess in the first place. I don't know how to run programs and I'm having a difficult time finding the right program.

This is my biggest computer disaster yet. 
SOMEBODY HELP ME PLEASE!


----------



## saikee (Jun 11, 2004)

It is quite possible that you have lost everything.

You are right in thinking the swap will affect a tiny area of the partition or even none of it but the real damage is the filing indexing system at the beginning of the partition. Without it it is a forensic exercise to piece the files back.

You can only blame yourself because you actually instructed explicitly a Linux to use the data partition as a scratch pad.

In your case I would suggest the following

(1) Load a Linux live CD. Kubuntu is as good as any

(2) When Linux is operational click terminal mode and obtain root privilege by command

```
sudo su
```
(3) You then ask Linux to display all the partitions of every disk by command

```
fdisk -l
```
(4) A partition has a Type number or ID. For NTFS it is type 7. A normal Linux partition is Type 83 whereas a swap is type 82. Thus if your report is accurate then you should see a partition still listed as Type 82 but has a ridiculously large size of 100Gb. Normal swap needs only to be 0.5 to 1Gb and a Linux may even survive without it.

(5) If you locate this swap partition successfully then you proceed to turn the partition back to Type 7 for NTFS filing system. Assuming the hard disk is sda you do this by command

```
cfdisk /dev/sda
```
Inside the cfdisk program you have an option on "type", Highlight the affected partition, select type and press return. You can see the 100+ partition types supported by Linux. Select type 7 or simply type "7" (without the ") and press return. At this stage nothing is permanent. You make it permanent by select "write" for effecting the change. After exiting cfdisk program I recommend a reboot.

(6) You reboot Kubuntu and use it to mount the changed partition. Assuming it is sda2 (adjust to suit your case and don't follow everything blindly, if in doubt ask question here!) the commands in terminal, after acquiring root privilege again, are

```
mkdir /mnt/sda2
mount -t ntfs /dev/sda2 /mnt/sda2 
ls /mnt/sda2
```
If you get a listing of directory after command "ls /mnt/sda2" go out to buy yourself a drink as most if not all your data will be intact. If an error is reported or the partition cannot be mounted then kick the dog and report back here. I run out of idea but others may be able to help.

A little explanation does no harm here-----------------------------------------

When you selected the ntfs partition as a swap and didn't alter the size then your action can cause change of just one byte in the partition table. As a swap has no filing system it does not need to be formatted. Therefore if there was no need for Kubuntu to use your swap, assuming you have a reasonably amount of ram, then your original ntfs indexing system could be intact.

My suggestion is just to change the partition ID, of one byte, from type 82 to 7. The operating system checks the partition type before deciding how to use it. The creation, deletion and modification of the partition table never touch the internal data. Everything is done in the 4x16 bytes within the MBR (because every hard disk has 4 primary partitions). Therefore my suggested change is "reversible" . You can go ahead to change it any number of times. If your NTFS filing index has not been damaged then your data is recoverable.

Good luck! as you might need it.


----------



## TerryNet (Mar 23, 2005)

Super advice and explanation, *saikee*!


----------



## saikee (Jun 11, 2004)

TerryNet,

We have to wait and see. 

If the OP fails to recover the data and the dog is kicked because of my recommendation the animal cruelty prevention people may come down on me like a ton of brick!


----------



## AiMingQi (Feb 21, 2009)

Thanks Saikee for your help.

I actually solved the problem a different way. I pulled my drive out and used a SATA external case I had to use my laptop to access the drive. Then I used Partition Table Doctor 3.5 to fix the drive. It was really quick and painless. Luckily I recovered all of my data and rebuilt the proper NTFS index system on the partition. So I'm back in business. 

I'm never going to touch Kubuntu again.


----------



## saikee (Jun 11, 2004)

> I'm never going to touch Kubuntu again.


Your problem is not specific to any Linux distro but the knowledge of what a swap is for.

Linux rarely need to defrag its partition because the use of a swap.

Like I explained before you can change the partition table without damaging its interior. You can learn the working of the partition table better in Linux than the MS systems because it has tools for you to carry out the changes.

Putting the disk on an eSata is to arrange it as a non-bootable disk so that you can use another operating system to fix the disk.(actually you can boot any MS or Linux system in an eSata if the main internal disk is absent!).

Linux, installed in the hard disk or on a Live CD, can fix this kind of problems regardless it is an internal or external, Sata or Pata, USB, Firewire or eSata disk.

Anyway I am glad you got it sorted.


----------



## newieGus (Mar 5, 2009)

Dear guys / saikee, thank you help. I could solve my problem, the same (identical) which AiMingQi. 
I did change the partition type from 82 to 7, but not mount. 
Then I used the PTDD, I was not previously an option FixedDisk but now yes!! and... repairing the unit successfully. 
Thanks again!


----------



## saikee (Jun 11, 2004)

*newieGus,

Welcome to the TSG Forum.*

Glad you found something useful.


----------

