How change partition number ID?

Hello. Thanks for reading my topic.
Here an HD disk in 6 partitions.
The partitions number are in sequence
sda1
sda2
sda5
sda6
sda3
sda4

I want change the number “sda” to an number sequence
sda1
sda2
sda3
sda4
sda5
sda6

Thus need change the sda4 to sda6. The others partitions will be deleted.

Have an nice week.

This looks like typical MSDOS partitioning, and you can’t choose the assigned numbers. You have sda2 as an extended partition, and the logical partitions it contains (5 and 6) will always appear immediately after it. Partitions 5 and 6 are logical.

The rules of MSDOS are that logical partitions only have numbers greater than 4. Primary and extended partitions are always 1,2,3 and 4.

2 Likes

Partition numbers reported by tools are “immutable”, in the sense that there is no way to override the auto-assignment made by the disk partitionning tools.

Those numbers are assigned because of how the partitions were created, the logical structuring and sequencing of the process in creating them for, as Dennis indicated, for MSDOS partitioning [technically referred to as the MBR (Master Boot Record) partitioning method].

Not sure why you would want to “tamper” with those numbers, except to make them “look pretty” somewhere but there would be no benefit derived, functionally, by any re-numbering, IF such were to have been possible.


Tools to help understand where, physically, each partition is located (and implicitly why) are the following two commands (which can be tweaked to report in the fashion you desire).

The information offered below applies to GUID partitioned disks.

NOTE:       The partition numbering for any partition table is based on the physical location of those partitions, and NOT based on the sequence in which they were created. If you insert a partition between two existing partitions (shrink the one closest to sector 0; reallocate the free space to a new sector), that inserted partition will be assigned the number after the shrunken partition, and all others after it will have their numbering incremented by 1. To demonstrate that, look for the label “DB001_F8”, which was the last partition created on the disk for which the partition list is provided below.


COMMAND:       lsblk

sudo lsblk -P -p -o NAME,FSTYPE,PARTLABEL,UUID,MOUNTPOINT | awk  '/[/]dev[/]sd[a-z][0-9]/ { print $0 }' | sort -V --key=1 | grep sda

giving you a report that looks like this:

For myself, I usually sort on key position 3, so that the outputs are sorted by assigned LABEL values, namely logically, rather than the “physical” label, which is the partition’s device name (sda?).

I would be curious to know if your “PARTLABEL=” values show the various sda[0-9]* identifiers by default, if you haven’t assigned them a specific LABEL string yourself. :slight_smile:


COMMAND:       parted

sudo  parted   /dev/sda   unit B   print

giving you a report that looks like this:

Here, I report the start and end positions as B (Bytes) which, for me, makes it easier to calculate to the sizing such that partitions start or end on sector starts/ends, thereby ensuring partition “alignment” which ensures fastest data transfer for read/write.


COMMAND:       fdisk

  • WARNING: DO NOT ATTEMPT TO MODIFY GParted PARTITIONNED DISK WITH THIS COMMAND.

( used only to verify if partitions are properly aligned; when they are not, there is a report of the form “Partition # does not start on physical sector boundary.” )

sudo   fdisk -l   /dev/sda

giving you a report that looks like this:

SNAPSHOT__PartitionsList__fdisk

Having learned from the experience of building my ROOT disk, I was then able to ensure my 2TB backup drive was properly partitioned such that all partitions were correctly aligned.

:slight_smile:

4 Likes

Thanks for all replies.
Have commands more simple to do, but can be dangerous. Thus I had done an backup and cleaned the HD creating the partitions in correct order.
Have an nice week.