bugGNU GRUB - Bugs: bug #38284, GRUB should provide option to swap...


You are not allowed to post comments on this tracker with your current authentication level.

bug #38284: GRUB should provide option to swap partition order

Submitted by:  Ulf Zibis <ulfzibis>
Submitted on:  Fri 08 Feb 2013 12:45:51 AM UTC  
Votes:  40  
Category: BootingSeverity: Major
Priority: 5 - NormalItem Group: Feature Request
Status: NonePrivacy: Public
Assigned to: NoneOriginator Name: Ulf Zibis
Open/Closed: OpenRelease: 
Release: Bazaar - trunkReproducibility: Every Time
Planned Release: 2.03+

(Jump to the original submission Jump to the original submission)

Mon 28 Dec 2015 09:15:18 PM UTC, comment #9:

See comment #0 :
"... it dosn't work for the one on sda2 (~ 10 seconds after WinXP boot screen I got a blue-screen). ..."

Ulf Zibis <ulfzibis>
Mon 28 Dec 2015 08:21:08 PM UTC, comment #8:

Why is changing boot.ini to have partition(2) and have second Windows on sda2 not an option?

Vladimir Serbinenko <phcoder>
Project Administrator
Mon 28 Dec 2015 06:56:08 PM UTC, comment #7:

Currently, both Windows partitions are listed in the GRUB menu, but selecting the 2nd entry actually ends up in booting the 1st, which is a error to me.

Ulf Zibis <ulfzibis>
Mon 28 Dec 2015 06:42:39 PM UTC, comment #6:

@ Piotr Sawuk
Interesting workaround against manually manipulating the partition table with hex editor.
But both do not serve what I want.
I'm looking for a solution to spontaneously and easily do the selection via grub menu.
To boot one of the regarding Windows installations, its partition must be at the same position in the table, while this Windows was originally installed.
Both Windows here were originally installed to sda1, so only the one, which is recorded as the first entry in the partition table, will boot correctly.

Ulf Zibis <ulfzibis>
Sun 27 Dec 2015 02:01:59 PM UTC, comment #5:

have you looked at gptsync? create a gpt partition, and use gptsync to produce the order of mbr-entries you want, then use parttool to disable gpt so windows-xp-32bit actually boots...

I changed the sources to allow for grub to function nicely if gpt and mbr modules both are loaded and boot partition is accessible only through gpt. sadly for now you're limited to 3 partitions visible in mbr. as extended partitions overlap with their children, you cannot tell gptsync to create such a parent-partition...

Piotr Sawuk <piotr5>
Mon 11 Feb 2013 10:58:12 PM UTC, comment #4:

See here:

Ulf Zibis <ulfzibis>
Mon 11 Feb 2013 10:43:37 PM UTC, comment #3:

Pooh, how often should I explain, that there is nothing to fix in boot.ini?

Here it is. What would you think to repair here?

[boot loader]
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect

Ulf Zibis <ulfzibis>
Mon 11 Feb 2013 08:56:02 PM UTC, comment #2:

Have you tried fixing your boot.ini? Windows doesn't identify partitions by numbers other than in ntldr and fixing boot.ini will take care of this.

Vladimir Serbinenko <phcoder>
Project Administrator
Mon 11 Feb 2013 02:57:45 PM UTC, comment #1:

Please forget, what I have written for grub.cfg. I wasn't aware, that partitions normally are determined by their UUID, so the assignment should work even if partitions are swapped.

So I suggest to extend the os-prober script similar like the following:
(should be controlled by a new etc/default/grub entry)

if [ x"${swapped_part_1}" = xy && x"${swapped_part_2}" = xy ]; then
parttool $swapped_part_1 swap-order $swapped_part_2
set swapped_part_1=
set swapped_part_2=
save_env swapped_part_1
save_env swapped_part_2

menuentry 'Windows XP on sda1' {

menuentry 'Windows XP OLD on sda3' {
set swapped_part_1='hd0,msdos1'
set swapped_part_2=${root}
parttool $swapped_part_1 swap-order $swapped_part_2
save_env swapped_part_1
save_env swapped_part_2
chainloader +1

A first draft, of what should be added to grub-core/parttool/msdospart.c :
(I do not have any environment to build GRUB, so hopefully others have)
static struct grub_parttool_argdesc grub_pcpart_swapargs[] =
{"swap-order", N_("Swap the order in partition table"), GRUB_PARTTOOL_ARG_VAL},
{0, 0, 0}

static grub_err_t grub_pcpart_swap (const grub_device_t dev1,
const struct grub_parttool_args *args)
grub_device_t dev2 = parse (args[0]); // TODO: replace parse() by valid code
grub_partition_t part1, part2;
int index1, index2;
struct grub_msdos_partition_mbr mbr;
struct grub_msdos_partition_entry entry;

part1 = dev1->disk->partition;
part2 = dev2->disk->partition;
index1 = part1->index;
index2 = part2->index;

if (dev1->disk != dev2->disk)
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("partitions must be on same disk"));
if (index1 >= 4 || index2 >= 4)
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("logical partition not allowed"));

dev1->disk->partition = part1->parent;

/* Read the MBR. */
if (grub_disk_read (dev1->disk, 0, 0, sizeof (mbr), &mbr))
dev1->disk->partition = part1;
return grub_errno;

entry = mbr.entries[index1];
mbr.entries[index1] = mbr.entries[index2];
mbr.entries[index2] = entry;
grub_printf_ (N_("Partitions %d, %d are swapped now. \n"), index1, index2);

/* Write the MBR. */
grub_disk_write (dev1->disk, 0, 0, sizeof (mbr), &mbr);

dev1->disk->partition = part1;


Ulf Zibis <ulfzibis>
Fri 08 Feb 2013 12:45:51 AM UTC, original submission:

After several unsuccessful tries with different combinations of command "parttool (partition) hidden+-", I've found a possibility to have 2 WinXP installations, both originally installed on sda1 aka "C:", alternatively running on one disk. I copied my old Windows XP partition from sda1 to sda2. After a fresh new Windows XP installation was installed to sda1.

First I tried this:

It works for to boot the Windows installation on sda1, but it dosn't work for the one on sda2 (~ 10 seconds after WinXP boot screen I got a blue-screen).
Surely it should work to boot Windows from sda2, if that Windows installation was originally installed to sda2 aka "D:", which is not the case here. There may be a chance, to tweak Windows registry with advanced expert knowledge, to change the Windows drive letter mapping to make the Windows system volume named as "D:", as if it was originally installed so, but this is hard work.

So the only thing I found out, that works, is to swap the order of those partitions in the partition table (print from sfdisk):
Device Boot Start End #cyls #blocks Id System
/dev/sda1 * 0+ 3038 3039- 24410736 7 HPFS/NTFS/exFAT
/dev/sda2 16418 19456 3039 24410767+ 7 HPFS/NTFS/exFAT
/dev/sda3 3039 5390 2352 18892440 83 Linux
exchange/toggle with:
/dev/sda1 16418 19456 3039 24410767+ 7 HPFS/NTFS/exFAT
/dev/sda2 * 0+ 3038 3039- 24410736 7 HPFS/NTFS/exFAT
/dev/sda3 3039 5390 2352 18892440 83 Linux

Unfortunately GRUB can't do that until now, so hereby I suggest an additional
option e.g.:

parttool (hd0,1) swap-order (hd0,2)

The option should include swapping the volume-IDs in the menu entries in grub.cfg as well, so they would again match correctly.

So initially, Grub menu should look like:
Extended Options for Ubuntu
Memory test ...
Microsoft Windows XP Professional NEW (on /dev/sda1)
Microsoft Windows XP Professional OLD (on /dev/sda2)
But after once booting into "Windows XP OLD", according my RFE, after reboot, the menu should look like:
Extended Options for Ubuntu
Memory test ...
Microsoft Windows XP Professional NEW (on /dev/sda2) <-- note the swapped no.
Microsoft Windows XP Professional OLD (on /dev/sda1)



Ulf Zibis <ulfzibis>


No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -unavailable- added by piotr5 (Posted a comment)
  • -unavailable- added by phcoder (Posted a comment)
  • -unavailable- added by ulfzibis (Submitted the item)
  • -unavailable- added by ulfzibis

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 40 encouragements so far.

    Only logged-in users can vote.


    Please enter the title of George Orwell's famous dystopian book (it's a date):



    Follow 2 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed 02 Mar 2016 10:51:34 AM UTCphcoderPlanned ReleaseNone=>2.03+
    Fri 08 Feb 2013 12:45:51 AM UTCulfzibisCarbon-Copy-=>Added ulfzibis

    Back to the top

    Powered by Savane 3.1-cleanup1