1 (edited by pilgrim 2013-04-24 22:20:10)

Topic: [SOLVED] gparted crashed during resizing

I was careless to resize my partitions without a backup, so I am here with quickly diminishing hope help with recovering my data.  I wanted to grow my boot partition and started gparted with resizing the / by 100M to the right to make room for it.  The disk layout is very basic for linux: 200M ext2 /boot, ext4 /, swap. I remember gparted reporting 4M as the optimum block size and I left it working without supervision wink When I came back the gparted window was gone, restarting gparted showed the old layout (before resize), reboot started throwing whole bunch of errors, so I stopped and wend to rescue CD and did testdisk which showed filesystem errors on / partition but was showing some directory tree.  When I decided to create a logfile of test disk I was expecting to be asked where to put it, which it never did and crashed... changing directory to my usb flash produced the following log file:

http://www.filefactory.com/file/6i9by1p … stdisk_log

The / partition looks worse now, is it possible testdisk would write to the location it scans??? Is there someone on here with enough knowledge to work a miracle here?  I really hope so!  BTW, anyone looking at the logfile will notice that the partitions are on top of md raid1 (yes I could have removed one of the disks before doing all this risky stuf... some good ideas are just too late...)
Thanks!
P

2

Re: [SOLVED] gparted crashed during resizing

By default testdisk should not write any data to the drive until you instruct it to do so.

If possible, it is recommended to make an exact copy of the drive to another drive using a tool such as dd.  That way you can experiment on one drive and if you do not get the result you desire, then you can dd again and start all over.

When shrinking to the right, GParted will first shrink the file system, and then move it sector by sector to the right, starting with the end of the partition and working towards the start.

Which version of GParted did you use?

3

Re: [SOLVED] gparted crashed during resizing

Gedakc,
Thank you for your reply!  I was using the current live CD.  Gparted v 0.15.0 with testdisk 6.13.  I have a couple other rescue CDs, so I may have used the testdisk from one of them before, so it may have been a different version.  I'll look for another drive to dd to.  Do you have any suggestions as to what to check for?
Thanks!
p

4

Re: [SOLVED] gparted crashed during resizing

If you know how much you shrunk the partition, and how much you moved it to the right, you should be able to guess where the new start of the partition might be.  This can help to determine if the end of the shrunk partition would be overwritten when moving to the right.  If not overwritten then you might be able to reset the partition boundaries and recover the data directly.

5

Re: [SOLVED] gparted crashed during resizing

I was moving the left boundary to the right by 100M.  How would one guess? Do you think it stopped during shrinking or moving?
Thanks!
p

6

Re: [SOLVED] gparted crashed during resizing

If GParted reported 4M as the optimum block size, then GParted would have completed the shrink stage and was onto the moving stage.

7

Re: [SOLVED] gparted crashed during resizing

Thanks, gedakc.  Can you think of a way to figure out where exactly it crashed and more importantly some way to restore the data?

8

Re: [SOLVED] gparted crashed during resizing

You might try researching what the file system header looks like and then scanning the disk for sectors that contain the file system header.  That would help you locate were the data is stored.

As to where it crashed, you could compare the sectors from the source partition location and the destination partition location until you find the spot where these differ.  That would indicate where the crash occurred.

When the location of the crash is found, then you could copy the remaining uncopied sectors to complete what the copy operation should have done.

Please note that all of the above will take some investigative work and some time.  As such you might want to instead consider using photorec to try to recover your files.

9

Re: [SOLVED] gparted crashed during resizing

Thanks, gedakc!
Are there any tools to help me follow the first approach?  Until this moment in my life I lived blissfully unaware of the internals of filesystems wink  Some of the files that I need to recover the most are python files.  I'll give photorec try, though I cannot imagine it would be able to handle those.
p

10

Re: [SOLVED] gparted crashed during resizing

pilgrim wrote:

Are there any tools to help me follow the first approach?

You might try searching through various threads on this forum.  Others have attempted this and been successful, though I do not recall any particular post clearly documenting the steps.

11

Re: [SOLVED] gparted crashed during resizing

Given the 100M move, do we know exactly by how many sectors was gparted moving the partition? I believe the block size is 4k in my case. does it align by block size?  I tries photorec and it does not recover what I need. I can figure out an approximate inode number where the file system was being moved.  I guess if I can find the location of the 100M that repeats itself, I'm done?  The question is how wink
p

12

Re: [SOLVED] gparted crashed during resizing

With recent versions of GParted, the default is align to MiB.  This means that GParted will align the partition to start on a Mebibyte boundary.  On a device with 512 byte sectors, this will be a multiple of 2048.  Hope that helps.

13

Re: [SOLVED] gparted crashed during resizing

Thanks, gedakc, it helps a little, but I am more interested to know what would be the exact number of bytes by which gparted would have been moving the tail (or some way to find it out).  I noticed that istat from sleuthkit starts giving me errors beginning from block group 1344.  I copied groups 1344 and 1345 into a file and was fiddling with it until I found that up until file offset of 0x3f9c335 I have a portion of a large csv data file, then 0xA271AAB of zeros and at e20dde0 data continues.  It looks like gparted overwrites the destination with zeros before writing?  I tried a string search of the fragment before zeros within the tail of the file and had no luck.  Does this behavior make sense to you?  The block of zeros seems odd to me and the size of it is also larger than I would have expected.  For 100M resize I would have expected something like 0x6400000 fie system move, or no?  Can you please shed some more light on what is going on here?
thx,
p

14

Re: [SOLVED] gparted crashed during resizing

GParted copies each sector from the source location to the destination location, regardless of whether the sector contains data.  This means that even "zeroed" sectors are copied.

Prior to moving the data, GParted creates an all encompassing partition that spans the area for both the original and the destination partition locations.

When moving a partition from right to left, GParted starts copying at the left hand side and proceeds to the right.

When moving a partition from left to right, GParted starts copying at the right hand side and proceeds to the left.

To perform the copy, GParted runs tests with copying blocks of 1, 2, 4, 8, and 16 MiB of data.  It will select the block sized based on which block provided the fastest copy rate.

After the data has been moved, GParted shrinks the partition to encompass only the destination partition location.

To learn the exact specifics of how the data is copied you can look at the gparted source code.

15 (edited by pilgrim 2013-04-24 22:21:44)

Re: [SOLVED] gparted crashed during resizing

I'm updating this for the benefit of others, as I was able to restore my disk after learning more about ext2/3/4 file systems.  The tools I used were sleuthkit on Caine live CD and python.  Specifically, fsstat reports some useful summary information about block groups, including inode ranges and inode table locations.  Using the inode ranges from fsstat we can get additional information by looking at some random inodes by hand with istat <inote number>.  By doing this I noticed that inodes starting from block group 1344 (inodes > 11010048) give errors.  The relevant part of the fsstat output is:

Group: 1343:
Inode Range: 11001857 - 11010048
Block Range: 44007424 - 44040191
Layout:
Super Block: 44007424 - 44007424
Group Descriptor Table: 44007425 - 44007438
Data bitmap: 43515919 - 43515919
Inode bitmap: 43515935 - 43515935
Inode Table: 43523616 - 43524127
Data Blocks: 43524128 - 44040191
Free Inodes: 8192 (100%)
Free Blocks: 32768 (100%)
Total Directories: 0

Group: 1344:
Inode Range: 11010049 - 11018240
Block Range: 44040192 - 44072959
Layout:
Data bitmap: 44040192 - 44040192
Inode bitmap: 44040208 - 44040208
Inode Table: 44040224 - 44040735
Data Blocks: 44040209 - 44040223, 44040736 - 44072959
Free Inodes: 8192 (100%)
Free Blocks: 24544 (74%)
Total Directories: 0

This tells us that the inode table in this part was already moved, while the previous one is still intact.  Realizing that I need to look for the break between blocks 43524128 and 44040224, and knowing that my move was approximately 100M I was able to narrow the search with the following python code:

sda2 = open("/dev/sda2","r")
block = 43524128
size =0x1000

for n in range(30):
    sda2.seek((block+20000*n)*size)
    dump = sda2.read(40000*size)
    offset = dump.rfind(dump[:100])
    print offset
    if(offset>0):
        print block+20000*n,'>',offset,'>',dump[:20], dump[:20].encode("hex")

Basically, we are looking for ~100M that repeats itself.  Luckily for me there was something unique there to find a match.  I had to narrow the location with further scripts and double check by hand.  After this I was able to reverse the move and mount the filesystem.  This is probably not the optimum way to get there, but the optimum would have been to back up my data in the first place wink I hope this write up is not needed by anybody...
p

16

Re: [SOLVED] gparted crashed during resizing

'Glad to hear that you were able to recover you data.  smile

And thank you for reporting back with how you approached this task, and marking the post as solved.