Topic: [closed] Switch the positions of two partitions (was Move/grow)
EDIT: Skip the parts about moving or growing a partition toward the beginning; apparently that is possible and I didn't know it. But I'm still asking about switching the positions of two partitions on a drive that are otherwise too large to copy-and-delete without an intermediate drive.
I enjoyed using GParted (livecd 0.3.3-0) for the first time last night, but I immediately saw a shortcoming that I believe can be fixed with a little effort. I program on a somewhat regular basis, but I don't know a whole lot about hard drive structures, so I want to try to understand this problem from an engineering point of view--in other words, I wanted to ask whether it can't be done or simply hasn't been implemented yet.
It seems that GParted can only move a partition into unallocated space forward from the partition (closer to the end) but not back from the partition (closer to the beginning). Intuitively I consider this limitation to be artificial, and its omission, which in many cases might require the user to have a blank intermediary drive handy, definitely hinders the usefulness of the program.
So I'd like to know this: How is moving a partition and its corresponding filesystem different from copying the partition from one place to the other and then deleting the original? If it's no different at all, or only different via certain differences in bookkeeping, it should be possible (and implemented) to copy then delete a partition+filesystem piece by piece.
Here are some use examples I've considered. In my opinion, all could be implemented primarily through judicious use of dd, at least for the movement of data itself. Please say if such operations would work, and if not, why they don't.
In these examples, two rows of digits represent an entire disk, each column representing a block of arbitrary size.
The top row in the examples below says what partition the original blocks belong to:
0 = unallocated
1 = /dev/hda1
2 = /dev/hda2
The bottom row is an index indicating the order the data takes in the original drive layout.
Case: A simple copy and delete. In this case, there is enough unallocated space in the target location to copy then delete. Moving 2 to the beginning of the drive, jumping over 1 in the process:
Original
000000112222
000000121234
Copy all of 2 to the unallocated space
222200112222
123400121234
Deallocate the old 2
222200110000
123400120000
Case: Swapping the positions of two partitions. In this case, the drive is entirely full, but we'd like to swap the positions of the first and the second partitions. Blocks of the drive's original data are moved from their initial to final positions one at a time, and each block overwritten becomes the next to be rewritten elsewhere. (This use case is particularly important since several other cases could be simplified to a position swap.)
Original
11111112222
12345671234
Copy 2:4 to RAM then overwrite with 1:7
11111112221
12345671237
Copy 1:4 to RAM then overwrite with 2:4 from RAM
11121112221
12345671237
Copy 2:1 to RAM then overwrite with 1:4 from RAM
11121111221
12345674237
Copy 1:1 to RAM then overwrite with 2:1 from RAM
21121111221
12345674237
Copy 1:5 to RAM then overwrite with 1:1 from RAM
21121111221
12341674237
Copy 2:2 to RAM then overwrite with 1:5 from RAM
21121111121
12341674537
Copy 1:2 to RAM then overwrite with 2:2 from RAM
22121111121
12341674537
Copy 1:6 to RAM then overwrite with 1:2 from RAM
22121111121
12341274537
Copy 2:3 to RAM then overwrite with 1:6 from RAM
22121111111
12341274567
Copy 1:3 to RAM then overwrite with 2:3 from RAM
22221111111
12341274567
Overwrite 1:7 with 1:3 from RAM
22221111111
12341234567
Case: Incremental movement. We would like to move 1 from the end of the drive to the beginning, but the unallocated space is not sufficient. (The problem of growing a partition toward the beginning instead of the end can be simplified into moving the partition toward the beginning followed by growing it toward the end.)
Original. A normal copy and delete is impossible because the unallocated space is insufficient.
0011111
0012345
Copy 1:1, 1:2 to their new positions.
1111111
1212345
Copy 1:3, 1:4 over old 1:1, 1:2.
1111111
1234345
Copy 1:5 over old 1:3.
1111111
1234545
Deallocate old 1:4, 1:5.
1111100
1234500