Traditionally, Linux on x86 hardware has used MSDOS partition tables. In this case, removing /dev/sda2
won't shift any of the higher numbered partitions down, because the primary partitions act like "slots": you can use them in any order you like, and removing one doesn't affect any of the others.
If instead you had sda{1-7}
with sda4
being the extended partition and sda{5-7}
being logical partitions within that extended partition, deleting sda6
would shift sda7
down. Logical partitions simply behave differently in this regard.
Newer versions of Linux are switching to GPT partition tables instead, though this is a slow process since there are limitations that prevent wholesale switching at this time.
In the GPT case, you don't need to use extended partitions to get more than 4 partitions on a single disk, and like MSDOS primary partitions, GPT partition numbers work like slots. You can delete a partition from the middle of a range and only leave a hole, with the existing partitions keeping their number. If you then create a new one, it fills the hole.
Your question asks about partition labels, however, and nothing I've talked about so far has anything to do with labels. Partition labels, in the sense used in Linux, are attributes of the filesystem, not the partition table. They exist to prevent changes to device names from causing problems with mounting filesystems. By using filesystem labels, you don't have to worry about device name changes because you're mounting partitions by label, not by device name. This is particularly helpful in cases like USB, where the device naming scheme is dynamic, and depends in part on what has been plugged in previously since the last reboot.
Linux mkfs.*
programs typically use the -L
flag to specify the label.
To mount a partition by label instead of by device name, use LABEL=mypartname
in the first column of /etc/fstab
. If you check your current /etc/fstab
, you'll probably find that there are already partitions being mounted that way. Linux GUI installers typically do this for you as a convenience.
You can mount a filesystem by label interactively, too, by passing the label with -L
to mount(8)
.
GPT does allow you to name a partition, but I don't know that it has anything to do with anything discussed above.
EDIT: One thing you do get with GPT which is relevant here, however, is a unique identifier for each partition, called a UUID. They work similarly to labels, but are different in several ways:
UUIDs are automatically assigned pseudorandom numbers, rather than a logical name you pick yourself.
You use -U
instead of -L
to mount(8)
a partition by UUID rather than by label.
You use UUID=big-ugly-hex-number
instead of LABEL=mynicelabel
in /etc/fstab
.
They are attributes of the partition, not the filesystem, so they will work with any filesystem as long as you can use GPT. A good example is a FAT32 partition on a USB stick: FAT32 doesn't have a filesystem label, and since it's on a USB stick you can't reliably predict which /dev/sd*
name it will get.
/dev/sda2
must be a primary partition, since logical partitions get numbers beginning with 5, no matter which parition number you used for the extended partition. So, your issue should be covered by the first case: removing/dev/sda2
should cause no renumbering. And again, using UUIDs or labels will avoid the need to worry about this entirely. – Warren Young Aug 23 '11 at 11:30