I have a disk with two partitions: sda1 and sda2. I would like change the number of sda1 to sda2 and sda2 to sda1.

It's possible but I don't remember the procedure. i.e. My first partition will be sda2 and the second sda1, so I need specify a manual order, not a automatic ordering like in fdisk -> x -> f.

How I change the order? Links to manuals or tutorials are also useful.

Thanks.

The reason: I have an application that needs read data from sda1 but the data is in sda2. Change the partition table is the faster solution for this issue. The system isn't critical but I don't want halt the system for too much time.

Now it is asking you to give the new details for the 'sda1' partition. So you have to give the numbers of sda2 here. So, I put '6 1012' here and press Enter:

/dev/sda1 :6 1012
/dev/sda1 6 1017 1012 3890128 83 Linux
/dev/sda2 :

Now check if the numbers printed after you pressed Enter are exactly the same as those printed earlier for sda2. If it is okay, continue with giving the new numbers for sda2:

/dev/sda2 :0
/dev/sda2 0+ 5 6- 23063+ 83 Linux
/dev/sda3 :

This time it was enough to enter "0" in my case - but you have to make sure the numbers aren't messed up in yours.

Next, continue with the other partitions in the same manner. If you already reached the end of the disk, pressing Enter is enough. Finally, check again that all the numbers are okay and save the partition table (or not). If you messed something up, have a look at man sfdisk and the descriptions of '-d', '-O' and '-I' options.

Notice also, that once you've made the crazy changes, you might need to run 'sync' so that the partitions are re-read before you try to mount them.

I just discovered a surprisingly easy solution to this problem. Say you have only one partition left named /dev/sda3. You want it to be called /dev/sda1. Open gdisk, convert the partition table to GPT, write, and exit. Then open it again, press sort (this will change the GPT number to 1), and then convert the GPT back to MBR via the expert options.

You would have to rewrite the drive partition table to reverse the order, which is a bit risky to do. If I were you I would fix the problem that makes you want to swap the order of device names and leave the partitions alone.

For instance if you have a script that needs to run on both machines and you want it to access the same device, then create a link in a different directory (not /dev) which is the same name on both servers, but links to /dev/sda1 on one, and /dev/sda2 on the other.

You can use any partition editor (fdisk or cfdisk) to edit the partitions but you need to either write down the current settings or take a photo of the screen. Delete the two partitions, and then create them manually, specifying all the correct values. Boot the system with a LiveCD to do this.

I can't change anything. My system is a Xen DomU and the problem is in the Dom0. I could recreate the order of partitions but is more complex in my situation. But anyway, I would like know how change the order.
–
J.F.Aug 15 '11 at 0:06

Just remember that this swapping will happen only after your partition containing /dev/ is loaded upon boot, so the initrd will still have the "correct" ones unless you fix it there too (exercise for the reader - will mkinitrd copy the strangeness?) This also doesn't address SELinux contexts.