1 (edited by gedakc 2016-05-04 22:43:42)

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

2

Re: [closed] Switch the positions of two partitions (was Move/grow)

psmay wrote:

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).

I stop reading here, because GParted can shrink or grow up a partition from the end or from the beginning.
So i dont understand your problem.
But i may miss something...

Any look at the docs ?
http://gparted.sourceforge.net/larry/tips/gfs.htm
http://gparted.sourceforge.net/documentation.php

Larry
GParted-project Admin
Former GParted-LiveCD maintainer (2007)

3

Re: [closed] Switch the positions of two partitions (was Move/grow)

I will admit that there's something I may have missed, too, so if backward movement is possible, go ahead and ignore that part, but there's still something left.

When I tried this last night, what I had was more or less this:
00000002233333

And what I wanted was this:
33333333333322

That is, I wanted to first swap 2 and 3's positions and then grow 3 into the remaining space.  This was simple to do using a copy and then a delete, then growing 3.  But what if I had this:

002233333

And wanted this:
333333322

Or even this:
333330022

Getting from 002233333 to 333330022 would not be possible without an intermediate drive in the current GParted.  Am I wrong?  So now my question is about swapping the positions of two (or more) partitions.

4

Re: [closed] Switch the positions of two partitions (was Move/grow)

i am sorry but i dont understand your outputs ...
Where does it come from, what is it ??????????

Larry
GParted-project Admin
Former GParted-LiveCD maintainer (2007)

5 (edited by psmay 2007-01-31 19:01:47)

Re: [closed] Switch the positions of two partitions (was Move/grow)

LarryT wrote:

i am sorry but i dont understand your outputs ...
Where does it come from, what is it ??????????

This isn't output; it's the layout of a drive.  As described in the first post, 0 represents unallocated space, 2 is /dev/hda2, and 3 is /dev/hda3.

6

Re: [closed] Switch the positions of two partitions (was Move/grow)

i am sorry but it is a bit too confused for my understanding.

Larry
GParted-project Admin
Former GParted-LiveCD maintainer (2007)

7

Re: [closed] Switch the positions of two partitions (was Move/grow)

Okay, the same problem restated in color:

http://uglycat.sprawling.org/switch-partitions.png

(All gray areas are unallocated.)

I have the disk layout outlined in the top image, and I want the disk layout in the bottom image.  Even if I move /dev/hda2 and /dev/hda3 all the way to the end of the drive, there is not enough unallocated space on the disk to make a copy of the /dev/hda3 partition at the beginning, so I cannot simply make a copy and delete the original.  I also don't have an extra drive to use intermediately.

It should be possible to do this, though, by moving around the data in the partitions in small blocks.  This is the feature I'm requesting.

8

Re: [closed] Switch the positions of two partitions (was Move/grow)

Thx for colors : i do understand tongue
As you may know, atm it is possible only if you have enough freespace (inculding shrinking partition).
To do thid, you need to shrink hda3, then move it to the end, then move da2 to the most right, then copy hda3 at the biginning of your drive (here it will change of number and become hda4!). Then you move the hda2 where you want and then grop up hte hda4 (was hda3) as you like.

Larry
GParted-project Admin
Former GParted-LiveCD maintainer (2007)

9 (edited by psmay 2007-02-01 00:53:39)

Re: [closed] Switch the positions of two partitions (was Move/grow)

I think you're missing my point.  Nothing should have to be shrunk.  This should be possible even if both partitions are entirely unshrinkable and even if both take up the entirety of the drive.  I'm going to use a set of real commands to make my point.

For the sake of demonstration, we'll define a "block" as 1 byte long.  I have a file named "device" which is 56 bytes long and consists of the following text:

ABCDEFGHIJKLMNOPQRSTUVWXYZ1234abcdefghijklmnopqrstuvwxyz

Because "device" is an analogue for an actual device (such as /dev/hda), it cannot be any larger or smaller than 56 blocks.  I also have a file "buffer" which represents 1 block of RAM.

Let's say the first 26 blocks (A-Z) represent a partition (such as /dev/hda1) and the last 30 blocks (1-4a-z) represent another partition (/dev/hda2).  The following script would move the second partition to the beginning and the first partition to the end, using only "buffer" to cache a piece that allows the rest to be shuffled into place:

dd bs=1 count=1 conv=notrunc of=buffer if=device skip=0
dd bs=1 count=1 conv=notrunc if=device of=device skip=26 seek=0
dd bs=1 count=1 conv=notrunc if=device of=device skip=52 seek=26
dd bs=1 count=1 conv=notrunc if=device of=device skip=22 seek=52
dd bs=1 count=1 conv=notrunc if=device of=device skip=48 seek=22
dd bs=1 count=1 conv=notrunc if=device of=device skip=18 seek=48
dd bs=1 count=1 conv=notrunc if=device of=device skip=44 seek=18
dd bs=1 count=1 conv=notrunc if=device of=device skip=14 seek=44
dd bs=1 count=1 conv=notrunc if=device of=device skip=40 seek=14
dd bs=1 count=1 conv=notrunc if=device of=device skip=10 seek=40
dd bs=1 count=1 conv=notrunc if=device of=device skip=36 seek=10
dd bs=1 count=1 conv=notrunc if=device of=device skip=6 seek=36
dd bs=1 count=1 conv=notrunc if=device of=device skip=32 seek=6
dd bs=1 count=1 conv=notrunc if=device of=device skip=2 seek=32
dd bs=1 count=1 conv=notrunc if=device of=device skip=28 seek=2
dd bs=1 count=1 conv=notrunc if=device of=device skip=54 seek=28
dd bs=1 count=1 conv=notrunc if=device of=device skip=24 seek=54
dd bs=1 count=1 conv=notrunc if=device of=device skip=50 seek=24
dd bs=1 count=1 conv=notrunc if=device of=device skip=20 seek=50
dd bs=1 count=1 conv=notrunc if=device of=device skip=46 seek=20
dd bs=1 count=1 conv=notrunc if=device of=device skip=16 seek=46
dd bs=1 count=1 conv=notrunc if=device of=device skip=42 seek=16
dd bs=1 count=1 conv=notrunc if=device of=device skip=12 seek=42
dd bs=1 count=1 conv=notrunc if=device of=device skip=38 seek=12
dd bs=1 count=1 conv=notrunc if=device of=device skip=8 seek=38
dd bs=1 count=1 conv=notrunc if=device of=device skip=34 seek=8
dd bs=1 count=1 conv=notrunc if=device of=device skip=4 seek=34
dd bs=1 count=1 conv=notrunc if=device of=device skip=30 seek=4
dd bs=1 count=1 conv=notrunc of=device if=buffer seek=30
dd bs=1 count=1 conv=notrunc of=buffer if=device skip=1
dd bs=1 count=1 conv=notrunc if=device of=device skip=27 seek=1
dd bs=1 count=1 conv=notrunc if=device of=device skip=53 seek=27
dd bs=1 count=1 conv=notrunc if=device of=device skip=23 seek=53
dd bs=1 count=1 conv=notrunc if=device of=device skip=49 seek=23
dd bs=1 count=1 conv=notrunc if=device of=device skip=19 seek=49
dd bs=1 count=1 conv=notrunc if=device of=device skip=45 seek=19
dd bs=1 count=1 conv=notrunc if=device of=device skip=15 seek=45
dd bs=1 count=1 conv=notrunc if=device of=device skip=41 seek=15
dd bs=1 count=1 conv=notrunc if=device of=device skip=11 seek=41
dd bs=1 count=1 conv=notrunc if=device of=device skip=37 seek=11
dd bs=1 count=1 conv=notrunc if=device of=device skip=7 seek=37
dd bs=1 count=1 conv=notrunc if=device of=device skip=33 seek=7
dd bs=1 count=1 conv=notrunc if=device of=device skip=3 seek=33
dd bs=1 count=1 conv=notrunc if=device of=device skip=29 seek=3
dd bs=1 count=1 conv=notrunc if=device of=device skip=55 seek=29
dd bs=1 count=1 conv=notrunc if=device of=device skip=25 seek=55
dd bs=1 count=1 conv=notrunc if=device of=device skip=51 seek=25
dd bs=1 count=1 conv=notrunc if=device of=device skip=21 seek=51
dd bs=1 count=1 conv=notrunc if=device of=device skip=47 seek=21
dd bs=1 count=1 conv=notrunc if=device of=device skip=17 seek=47
dd bs=1 count=1 conv=notrunc if=device of=device skip=43 seek=17
dd bs=1 count=1 conv=notrunc if=device of=device skip=13 seek=43
dd bs=1 count=1 conv=notrunc if=device of=device skip=39 seek=13
dd bs=1 count=1 conv=notrunc if=device of=device skip=9 seek=39
dd bs=1 count=1 conv=notrunc if=device of=device skip=35 seek=9
dd bs=1 count=1 conv=notrunc if=device of=device skip=5 seek=35
dd bs=1 count=1 conv=notrunc if=device of=device skip=31 seek=5
dd bs=1 count=1 conv=notrunc of=device if=buffer seek=31

Running this script with a "device" file containing the aforementioned line of text results, as expected, in this being the contents of "device":

1234abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ

In my opinion this could be generalized to actual drive partitions just by adapting the algorithm a bit.  What do you think?

10

Re: [closed] Switch the positions of two partitions (was Move/grow)

Well the fisrt thing i think, is that i understand  smile
Next  : it sounds very good to me.
But since i am note the GParted C++ maintainer (it is Plors) i dont know what he think of this.
I send him the link.

Good job, anfd thanks for supporting GParted wink

Larry
GParted-project Admin
Former GParted-LiveCD maintainer (2007)

11

Re: [closed] Switch the positions of two partitions (was Move/grow)

ok, without reading all of it (sorry, time is a scarce resource atm) i don't think we're going to implement features like this anytime soon. I'm the only active coder and due to some private stuff i'm not very 'active' atm :-)

I'll try to fix bugs and do small stuff, but new features will have to wait a bit. Of course, if you can send patches, everything changes. smile

12

Re: [closed] Switch the positions of two partitions (was Move/grow)

Noted. :-)  I'll be trying to work out a general version of the data movement program.  After that, because GParted is capable of copying a partition from one place to another, I think that same code can probably be adapted to reconcile a filesystem+partition's new place on the drive.

In other words, I'll see what I can come up with...

13

Re: [closed] Switch the positions of two partitions (was Move/grow)

This is nice ! Thx smile

Larry
GParted-project Admin
Former GParted-LiveCD maintainer (2007)

14

Re: [closed] Switch the positions of two partitions (was Move/grow)

thank you very much.