[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug #38284] GRUB should provide option to swap partition order
From: |
Ulf Zibis |
Subject: |
[bug #38284] GRUB should provide option to swap partition order |
Date: |
Mon, 11 Feb 2013 14:57:45 +0000 |
User-agent: |
Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 Firefox/18.0 |
Follow-up Comment #1, bug #38284 (project grub):
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
fi
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)
==========================================================================
<code>
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;
return GRUB_ERR_NONE;
}
</code>
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?38284>
_______________________________________________
Nachricht gesendet von/durch Savannah
http://savannah.gnu.org/