You are not logged in.

#1 2007-11-17 15:31:58

Kienja Kenobi
Member
Registered: 2007-08-17
Posts: 62

Change Partition ID?

Is there any way for me to change the ID of a partition, without moving or deleting partitions?  For example, I want to change "sda1" so that it is identified as "sda2" without moving around or deleting partitions.

Offline

#2 2007-11-17 18:16:25

retsaw
Member
From: London, UK
Registered: 2005-03-22
Posts: 132

Re: Change Partition ID?

I don't think there are any tools that can do that.  But if you delete a partition and create a new partition in the same place the filesystem will remain intact, so you could delete sda1 and sda2, the first partition you create should then be sda1, so create a new partition in the place of sda2, then create a new partition in the place of sda1.

Why do you want to do this?

Offline

#3 2007-11-17 22:26:10

Kienja Kenobi
Member
Registered: 2007-08-17
Posts: 62

Re: Change Partition ID?

Deleting the partitions is precisely what I do not want to do.  I need to change sdb4 into sdb1.  All four of those partitions contain a massive amount of information that I can not simply throw away.  I have encountered many reasons to be able to change a partition ID like this, but currently it would be nice to be able to do this because of GRUB.  If I create a backup image of my boot partition and then restore that image into a partition that does not have the exact same ID (sdb1), then it becomes worthless.

Last edited by Kienja Kenobi (2007-11-17 22:27:41)

Offline

#4 2007-11-17 22:27:18

somairotevoli
Member
Registered: 2006-05-23
Posts: 335

Offline

#5 2007-11-18 13:23:48

retsaw
Member
From: London, UK
Registered: 2005-03-22
Posts: 132

Re: Change Partition ID?

Like I said, if you create the new partitions in the same place as the old partitions, the filesystems will remain intact, that means you won't lose your data.  But as always you should have a backup anyway, since you never know when your hard drive will fail.

If you don't like that idea the other way, that I can think of, of doing this would be to use dd to reorder the order the partitions are in, in the partition table.  From a quick look at the wikipedia article on the MBR I believe it is this order which determines which number is applied to which partition.

As to your possible problem when restoring your boot partition, it is not that much extra work to fix GRUB to boot when do the restore.

Last edited by retsaw (2007-11-18 13:24:50)

Offline

#6 2007-11-20 13:56:27

Kienja Kenobi
Member
Registered: 2007-08-17
Posts: 62

Re: Change Partition ID?

somairotevoli, thank you very much for the link.  I think that will solve some of my problems. 

retsaw, thank you very much for the advice, but honestly I think my knowlege of dd and the MBR is too little to attempt what you say.  Your second method of saving partitions with dd and then restoring them once I move around partitions would not work because there is way too much information that I would have to save and move around.  I do not have that much free space.  Finally, I use Parted Magic to edit my partitions.  In my experience, deleting a partition and creating a new one in its place does indeed lose all of the information that was once there (That is, the information is physically on the disk but does not show up in the partition).  Restoring the boot partition from a saved clone sounds easy, but for some reason it is not.  When I make a clone of the boot partition from hda1 and then restore it to something like hda2, GRUB will start at the computer's boot-up but it will not even be able to show the menu of operating systems.  I go through /boot/grub/menu.lst and change all of the paths to the new partitions, but GRUB is still completely unable to show its menu of operating systems.  I also update GRUB's hardware listing file (I can not remember the file's name), but that does not affect anything either.  I am not currently at home, but when I get there I will be able to give you the error message GRUB shows at boot-up.

Offline

#7 2007-11-20 17:50:39

retsaw
Member
From: London, UK
Registered: 2005-03-22
Posts: 132

Re: Change Partition ID?

Kienja Kenobi wrote:

When I make a clone of the boot partition from hda1 and then restore it to something like hda2, GRUB will start at the computer's boot-up but it will not even be able to show the menu of operating systems.  I go through /boot/grub/menu.lst and change all of the paths to the new partitions, but GRUB is still completely unable to show its menu of operating systems.

For this to actually work you have to restore it to the same physical part of the disk (the partition number is irrelevant).  How GRUB works is the it puts a small amount of code (Stage 1) in the MBR or boot sector of your boot partition, this code has the location of the Stage 1.5 code for the filesystem GRUB is installed on hardcoded in it, the Stage 1.5 code tell GRUB how to read the filesystem, GRUB can then find the rest of the files it needs and finish loading.  GRUB works like this because it is not possible to put the code to read a filesystem in the 446 bytes it has available in the MBR.  Basically the Stage 1.5 file has to remain in the same physical location on the disk, if it moves GRUB will stop working and you'll have to reinstall GRUB to the MBR (or partition boot sector) using grub-install to get it working again.

Kienja Kenobi wrote:

In my experience, deleting a partition and creating a new one in its place does indeed lose all of the information that was once there (That is, the information is physically on the disk but does not show up in the partition).

That might depend on what program you use to do this, using the basic tools such as fdisk and cfdisk the data will still be there and visible if you don't make a mistake.  I haven't tried doing it for the purpose of renumbering the partitions, but I have done it a number of times as part of the process of resizing a partition since cfdisk does not have an option for resizing.  If you use more advanced partitioning tools, those may also format the partition aswell, and then the data is effectively gone (though it may still be on the disk, but not necessarily in a form that is easy to recover).

Kienja Kenobi wrote:

Your second method of saving partitions with dd and then restoring them once I move around partitions would not work because there is way too much information that I would have to save and move around.  I do not have that much free space.

You misunderstood how I intended you use dd.  I was suggesting using it to reorder the partition data in your MBR which should in effect renumber your partitions, I was not suggesting you copy the filesystems with dd at all.  I can give you instructions on doing it if you tell me how you want your partitions renumbered, but note I haven't tried doing this myself and even though it should be safe and reversible don't hold me responsible should things go wrong.

Last edited by retsaw (2007-11-20 17:55:11)

Offline

#8 2007-11-21 13:33:28

Kienja Kenobi
Member
Registered: 2007-08-17
Posts: 62

Re: Change Partition ID?

I see!  My mistake, then.  Putting GRUB into a partition with the right number (say, hda1) was really only a side effect of the real problem.  That is, the GRUB files must be in the same physical place on the hard disk, regardless of partition ID.  In that case, when I need to restore the GRUB partition to a different place on the hard drive I will try grub-install to make it work again.  It is possible, then, to use grub-isntall to restore nothing but GRUB's data in the partition's boot sector, or the MBR?  (I have never used only grub-install, I have always installed GRUB through a Linux distrubution's installer)

I use the Parted Magic Live CD, which is a GUI system that takes out a lot of the manual calculation and coding.  I imagine Parted Magic formats any newly created partition. 

Thank you for the offer, but I think I would rather not attempt dd and the MBR.  I am sure it would work, but I will stick to the idea of grub-install if I move the GRUB data.

Last edited by Kienja Kenobi (2007-11-21 13:36:27)

Offline

#9 2007-11-21 14:08:49

lloeki
Member
From: France
Registered: 2007-02-20
Posts: 456
Website

Re: Change Partition ID?

for the record, fdisk expert options (x) allow you to fix (f) partition order. that is, make partition order be going in ascendant block ordering, as it often happens that the partition order is the order of partition creation or any other kind of shuffling around, which ends up being a bad thing, because linux copes with it easily, but some os/tools don't, and might f*ck up grandiosely.

Last edited by lloeki (2007-11-21 14:09:16)


To know recursion, you must first know recursion.

Offline

#10 2007-11-21 16:53:53

retsaw
Member
From: London, UK
Registered: 2005-03-22
Posts: 132

Re: Change Partition ID?

Kienja Kenobi wrote:

In that case, when I need to restore the GRUB partition to a different place on the hard drive I will try grub-install to make it work again.  It is possible, then, to use grub-isntall to restore nothing but GRUB's data in the partition's boot sector, or the MBR?

|I expect it will copy over the other files it uses to load up, but it will leave your menu.lst intact and only update your device.map if you tell it to with the "--recheck" option.

Kienja Kenobi wrote:

Thank you for the offer, but I think I would rather not attempt dd and the MBR.  I am sure it would work, but I will stick to the idea of grub-install if I move the GRUB data.

That's probably best, though it means I'll have to try it out on one of my hard drives at some point, just to confirm to myself if it will actually work or not.

Offline

Board footer

Powered by FluxBB