deleting one logical partition changes partition numbers of the others.

I started with
sda1 windows restore
sda3 extended
sda5 swap
sda6 /mandriva
sda7 /SUSE 11.3
sda8 /SUSE 11.2

I then made some changes with gparted (from PartedMagic 5.5) to create an ntfs partition to simulate a condition where someone may want to delete that partition and use the free space for linux. I then deleted that partition, sda2 then sda5 (swap) and taking some screenshots, went about resizing partitions to use that free space and then recreate swap. the intention being to create a basic guide on how to go about this.
I have previously only had my swap at the end of the extended partition, deleting it and recreating it later had caused little trouble.
I realize that a resize/move operation would have been a better choice.

What I was not expecting was the partition number changes that occurred.

root@PartedMagic:~# fdisk -l

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders, total 156301488 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x29b985ee

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1              63    17237744     8618841   12  Compaq diagnostics
/dev/sda3        17238016   156301311    69531648    f  W95 Ext'd (LBA)
/dev/sda5        19341312    37142527     8900608   83  Linux
/dev/sda6        37144576    59772927    11314176   83  Linux
/dev/sda7        59774976   156301311    48263168   83  Linux
/dev/sda8        17240064    19339263     1049600   82  Linux swap / Solaris

Partition table entries are not in disk order

Is this normal, or have I managed something that would usually take some determined effort?

Clearly this leaves nothing bootable.

I can fix it ,but is there a way to change those partition numbers back, if there is, that would have to be less of a headache

I should have added at least this to my previous post.

# Modified by YaST2. Last modification on Mon Sep 27 05:10:36 CST 2010
# THIS FILE WILL BE PARTIALLY OVERWRITTEN by perl-Bootloader
# Configure custom boot parameters for updated kernels in /etc/sysconfig/bootloader

default 0
timeout 8
##YaST - generic_mbr
gfxmenu (hd0,6)/boot/message
##YaST - activate

###Don't change this comment - YaST2 identifier: Original name: linux###
title Desktop -- openSUSE 11.3 - 2.6.34.7-0.3
    root (hd0,6)
    kernel /boot/vmlinuz-2.6.34.7-0.3-desktop root=/dev/disk/by-id/ata-Hitachi_HTS541680J9SA00_SB224CGGKE01PD-part7 resume=/dev/disk/by-id/ata-Hitachi_HTS541680J9SA00_SB224CGGKE01PD-part5 splash=silent quiet showopts vga=0x317
    initrd /boot/initrd-2.6.34.7-0.3-desktop

###Don't change this comment - YaST2 identifier: Original name: failsafe###
title Failsafe -- openSUSE 11.3 - 2.6.34.7-0.3
    root (hd0,6)
    kernel /boot/vmlinuz-2.6.34.7-0.3-desktop root=/dev/disk/by-id/ata-Hitachi_HTS541680J9SA00_SB224CGGKE01PD-part7 showopts apm=off noresume nosmp maxcpus=0 edd=off powersaved=off nohz=off highres=off processor.max_cstate=1 nomodeset x11failsafe vga=0x317
    initrd /boot/initrd-2.6.34.7-0.3-desktop

###Don't change this comment - YaST2 identifier: Original name:  linux (/dev/sda6)###
title linux (/dev/sda6)
    root (hd0,5)
    configfile /boot/grub/menu.lst

###Don't change this comment - YaST2 identifier: Original name:  openSUSE 11.2 - 2.6.31.12-0.2 (pae) (/dev/sda8)###
title openSUSE 11.2 - 2.6.31.12-0.2 (pae) (/dev/sda8)
    root (hd0,7)
    configfile /boot/grub/menu.lst

###Don't change this comment - YaST2 identifier: Original name: Vendor diagnostic###
title Vendor diagnostic
    rootnoverify (hd0,0)
    chainloader +1

When it’s ‘Jeffed’ like this…it’s ‘Jeffed’.

When it’s ‘Jeffed’ like this…it’s ‘Jeffed’.

Oh, now thats just a negative attitude.:slight_smile:

Well, I’m going to see what I can do with it anyway, If I can’t fix it, no big deal everything I need is securely backed up, and linux installs are simple and fast.

I think the main thing that bugs me is what happened, and how . I have done this type of partitioning many times, never before a problem like this, deleting one partition simply does not cause other partition numbers to change.

And if it is a bug in gparted or parted it needs a fix, before it does hit someone hard.

That’s usually what happens when you delete/create partitions in the middle of others.

Clearly this leaves nothing bootable.

Why? Use UUIDs for everything (Grub menu and /etc/fstab). Device names are irrelevant.

I can fix it ,but is there a way to change those partition numbers back, if there is, that would have to be less of a headache

Write the offset, size, partition ID of each (primary) partition, then - with fdisk - delete them all and create new partitions (of course with same offset, size and partition ID) in the order you like.

Well maybe you didn’t make clear exactly what info you wanted.

I read it to understand that you could fix it - So could I, but it wouldn’t be by trying to undo the changes.

And to be honest, I was struggling to make out exactly what you did, partly because you refer to sda2, but I didn’t see any fdisk info on that

*Partition numbers do change, exactly how and when I can’t say with absolute certainty, but they do/can. There are some experts about on this subject who I’m sure would love to give you every conceivable bit of information you need on this.

save you MBR first :

dd if /dev/sda of=sda.mbr bs=512 count=1

Or save just the partition table

dd if=/dev/sda bs=1 count=64 skip=446 of=sda.ptb

There you go. One of them found it already. We just need Carlos now to complete things :wink:

And to be honest, I was struggling to make out exactly what you did, partly because you refer to sda2, but I didn’t see any fdisk info on that

Welcome - Parted Magic (Linux 2.6.35.4-pmagic)

root@PartedMagic:~# fdisk -l

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders, total 156301488 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x29b985ee

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1              63    17237744     8618841   12  Compaq diagnostics
/dev/sda2        17238016    69298175    26030080    7  HPFS/NTFS
/dev/sda3        69298176   156301311    43501568    f  W95 Ext'd (LBA)
/dev/sda5        71397376    82014207     5308416   83  Linux
/dev/sda6        82016256    98961407     8472576   83  Linux
/dev/sda7        98963456   156295167    28665856   83  Linux
/dev/sda8        69300224    71395327     1047552   82  Linux swap / Solaris

The sda2 partition was created, as previously stated to simulate the situation mentioned, its worth noting that sda2 did originally contain a vista os. there were some resize/move opperations to get to this point, as you can tell.
The previously supplied fdisk -l output is from after this point, and as the system is now.

What’s bothering you? That sda8 should rather be called sda5 ?

OK. I understand what you did… at least enough to tell you not to do it again. If you want to delete/add partitions, do it from a live CD or PartedMagic, not from your installed system! Whether partition numbers change and when depends on the moment when the program you’re using inform the kernel about partition table changes (you would do it manually with partprobe). This is not a bug in parted or gparted. Again, don’t use device names in /etc/fstab. Make sure that the UUID of your swap partition hasn’t changed … or even vanished. Use the command blkid to print partitions UUIDs. Boot from a live CD, run fdisk, mount your root partition and edit /boot/grub/menu.lst according to fdisk output there (if needed).

OK. I understand what you did… at least enough to tell you not to do it again. If you want to delete/add partitions, do it from a live CD or PartedMagic,

I assume you missed the fact that I used the PartedMagic 5.5 liveCD then.

Yes I did miss that point, sorry. :shame:

I will try to make it simple for you as you indicated you wanted to write a better how to:

Primary Partitions are explicitely marked in the partition table as sda1 sda2 sda3 and sda4 these assignment will never change if you delete or one or more of them as far as Linux is concerned. While were talking about OS’s and Primary partitions, it is important to note that Windows assigns partitions to Drive letters starting with ‘C’. A hidden partition does not get a drive letter. A Linux partition does not get a drive letter. And partitions which have been deleted monst the primaries also don’t get a drive letter. So in short as it pertains to primaries, sda1,sda2,sda3,sda4 will disappear if deleted but will not change the drive assignments. In windows, if sda1 = C: and sda2 = D: and sda3 = E: and you delete sda2 then sda1 = C: sda3 = D: thus a re-assignment which by the way you can override in Windows Vista & Windows 7 ultimate but not in Windows 7 Basic.

Primary Partitions 2, 3, and 4 each can be made of type extended. The partitions that are of type extended are merely containers of a specific size which which you can create logical drives until all space in the extended is exhausted. In both Windows and Linux, assignment is only given for logical drive space which has been defined, and assignment is sequencial. Thusly, if you make 3 logical drives in extended space they will become sda5, sda6, sda7 in Linux and in Windows will become D: E: & F: (if not Linux drives). Windows does not give a drive letter to the extended partition. Also understand that Windows assigns drive letters first to Primaries then to extendeds.

This process works great for single hdd systems but gets a little convoluted when dealing with muti-hdd systems. In Linux, it’s straight forward, sda is physical drive 0 and sdb is physical drive 1. In Windows, being that it always assigns drive letters for primaries first, Drive 1 primary 1 = C: = sda1, Drive 1 primary 2 = sda2 but has no drive letter because it is type extended, Drive 1 Primary 3 = D: = sda3, Primary 4 = sda4 and has no drive letter because it’s Linux. Instead of mapping the extended logicals to drives, Windows will start assigning Primaries of drive 2 next. So if drive 2 has 2 partitions and one is primary, Drive 2 Primary 1 = E: = sdb1 and then it starts with Drive 1 Partition 2 Logical 1 = F: = sda5, Drive 1 Partition 2 Logical 2 = G: = sda6 then moves to Drive 2 Extended and assigns Drive 2 Partition 2 Logical 1 = H: = sdb5. If you then remove Drive 2 from the system, Windows will see F: becomes E:, G: becomes F: and software designed to refer to the old E: F: and G: will need reworking. One more thing will happen for windows machines. Since the second drive was added after initial install of the OS 1 hardware change is identified by Windows. Removing the hdd marks change 2 and restoring the hdd marks change 3 presuming that’s all you changed. When you attempt to make one more change Windows will require a re-install because you are limited to 3 major hardware changes (hdd, video, nic, sound). This is part of there anti-piracy policy where people will try to install on more than one machine or otherwise move the OS to another machine.

Hope this helps clear up your understanding.

It might change if you delete the second or the third partition using a partitioning tool which moves the remaining partitions to the top. In this case, sda3 becomes sda2 and sda4 becomes sda3.

Yuo can choose to use up to 4 primary partitions, if you want more than 4 partitions, one of those primary partitions needs to be an extended ( there can only be one extended ).
It makes no difference which primary is used as the extended.

I think everyone posting in this thread knows that. When we say ‘primary’, it also includes the extended if any, that we don’t need to mention, as it’s just a primary in the partition table (except for its partition id).

On 2010-10-10 08:06, caf4926 wrote:
>
> There you go. One of them found it already. We just need Carlos now to
> complete things :wink:

Not this “early”, I’m foggy :stuck_out_tongue:

Er… yes, logical partition numbers change if you remove one in the middle, or join two partitions.
Can’t be helped. Either adapt fstab and menu.lst, or don’t use device names, as “please_try_again” said.

Only primary partition numbers do not change.

Why the difference? Primaries are stored in a table, logicals in a linked list.

That there is one or two partitions listed in the “wrong” order? Computers do not care, that’s just
a warning for the human reading it. :-p

It is perfectly bootable, no problem. Just tell linux about the new layout. Don’t even try to “mend” it.

However, to re-mud the waters a bit more: There are tools to re-order logical partitions. :-p
Yes, it is possible. No, I don’t remember which tools. I think it was partition magic (pay-ware).
How come? Well, it is a linked list… you only have to move the pointers around. In disk. It is not
a re-partitioning.

Primaries too, exchanging the entries in the table. Doable.

You want to experiment? Fdisk, extended menu (experts only), option “f” is “fix partition order”.
Do it from a live, and reboot afterwards.

:smiley:

Now, this is not an experiment with soda water. It is your disk with valuable data… I would do a
full image of the original disk, just in case. Or learn how it works on a smaller disk.


Cheers / Saludos,

Carlos E. R.
(from 11.2 x86_64 “Emerald” at Telcontar)

After considering all posts here,I have concluded,
I would have avoided this problem completely if I had used resize/move option, and not delete on that / swap partition. The mentioned guide is on hold for now.

That’s usually what happens when you delete/create partitions in the middle of others.

and

Er… yes, logical partition numbers change if you remove one in the middle, or join two partitions.
Can’t be helped. Either adapt fstab and menu.lst, or don’t use device names, as “please_try_again” said.

well its not “in the middle” sda5 is, as you know at the start of the extended, but now I’m just nitpicking. the fstab and menu.lst edit is what I will be using, and have been looking at. I won’t be caught on this one again .

Also thanks to all for your replies, much appreciated!