Swapping the number of 2 partitions

Cameron Simpson cs at zip.com.au
Fri Oct 17 04:25:52 UTC 2014


On 16Oct2014 18:45, jd1008 <jd1008 at gmail.com> wrote:
>On 10/16/2014 03:32 PM, Cameron Simpson wrote:
>>On 16Oct2014 12:55, jd1008 <jd1008 at gmail.com> wrote:
>>>I am trying to avert having to dd out 2 partitions to external drive
>>>and repartition and dd them back in.
>>>
>>>What I am trying to do is renumber partition 1 as partition 2
>>>and partition 2 as partition 1.
>>>
>>>Is this possible? parted and fdisk and sfdisk do not seem to provide
>>>such operations.
>>
>>sfdisk has a dump option. I would think you could dump the partition 
>>table and reorder the partition records and reload it. I can't see 
>>any reason that would not work.
>
>OK, it's just that I did not want to wreck the drive, as I was not sure
>it would accomplish what I wanted.
>So, P2 will be renamed P1
>and P1 will be renamed (renumbered) P2.

I would expect so. Note that I haven't done this myself.

>Will this affect the other partitions P3 and P4 in any way?

Shouldn't.

>Such as, will it affect their starting offsets? Will the system
>no longer be able to identify them by their existing UUID?

AFAIK, the partition table is just a data structure laying out the on-disk 
location of partition. The partition number is the record number in the data 
structure. The physical location should be independent. So you should be able 
to rearrange the records.

I gather the UUID is embedded in the partition itself. But I have never found 
out. But on that basis, the system should be just fine. In fact, that's really 
the point of putting UUIDs on partitions - so the OS config files don't have to 
track partitions locations and hard drive locations.

Note that this suggestions doesn't move any of the on-disk data around (except 
the partition table itself I guess).

Could you explain _why_ you want to renumber the partitions? Does something 
have a hardwired desire to use "partition 1" or something?

Cheers,
Cameron Simpson <cs at zip.com.au>

Sometimes when you fill a vacuum, it still sucks.
         - attributed to Dennis Ritchie, about X


More information about the users mailing list