Topic: GParted crashed while moving NTFS partition to the left
Hi. So I had 3 partitions:
+-----------+-----------+-------------------+-----------+
| /dev/sda1 | /dev/sda2 | unallocated space | /dev/sda3 |
| NTFS | EXT4 | 35632170 sectors | NTFS |
| | | 16.99 GiB | |
+-----------+-----------+-------------------+-----------+
And decided to move /dev/sda3 partition to the left (into whole unallocated space). Unfortunately, while doing this operation at some point linux live-cd system (SystemRescueCd 3.8.1) froze (Scroll Lock and Caps Lock lights began blinking). I wasn't at the computer at that moment, so I don't know how much data have been already moved. Upon later reboot to the linux live-cd, I examined partition table, and the /dev/sda3 partition was set to:
- start: first sector of previously unallocated space (seems reasonable)
- size: old size of /dev/sda3 + 35632170 sectors (seems reasonable)
So what I'm thinking right now is: I need to find out how many sectors were copied (so I can move them back and restore filesystem as it was bit-by-bit). If I assume that GParted started copying from the start of /dev/sda3 to the start of unallocated space, so there somewhere on the /dev/sda3 should be 2 identical chunks of data (of the size 35632170 sectors) in sequence, i.e. 2 identical chunks one after another. Am I right?
/dev/sda3
+-----+------------------+------------------+-----+
| ... | identical blocks | identical blocks | ... |
| ... | 35632170 sectors | 35632170 sectors | ... |
+-----+------------------+------------------+-----+
If my logic is correct, I wrote a little python script to help me out to find those identical chunks:
SECTOR_SIZE = 512 # bytes
SHIFT = 35632170 * SECTOR_SIZE # bytes
OLD_PARTITION_SIZE = 440421975 # sectors
equal_sectors = 0
disk = open("/dev/sda3", "rb")
for sector_num in xrange(OLD_PARTITION_SIZE):
disk.seek(sector_num * SECTOR_SIZE)
read_wo_shift = disk.read(SECTOR_SIZE)
disk.seek(sector_num * SECTOR_SIZE + SHIFT)
read_with_shift = disk.read(SECTOR_SIZE)
if read_wo_shift == read_with_shift:
if equal_sectors == 0:
print("First match found at sector: " + str(sector_num))
equal_sectors += 1
else:
if equal_sectors > 0:
print("Total identical sectors in sequence found: " + str(equal_sectors))
equal_sectors = 0
if equal_sectors_num > 0:
print("Total identical sectors in sequence found: " + str(equal_sectors_num))
disk.close()
This script is looking for identical sectors spaced apart by 35632170 sectors and the number of identical sectors in sequence should be also 35632170 sectors. Well, at least I'm hoping that it does that. While I'm waiting for the script to finish the work, any comments, ideas?
Thank you