How to Change Linux Partition Label Names on EXT4 / EXT3 / EXT2 and Swap

A Partition is a space carved out from a physical disk which can be used to either install an Operating System or just act as a storage space for Users files and other data....

Spread the love

A Partition is a space carved out from a physical disk which can be used to either install an Operating System or just act as a storage space for Users files and other data. Each partition is created directly on Hard Disk or External Disk attached to the system with starting and ending block address identifying the amount of space it takes on the drive.

Change Modify Linux Partition Disk Names

Change Linux Partition Disk Label Names

Although you can create n number of partitions you desire but a Linux system identifies maximum of 16 partitions which can be associated to any of SCSI, SATA, PATA or virtual hard disk. For identifying above partitions, A Linux system has its own general convention. That convention is in the form ‘/dev/sdxn‘ or ‘/dev/vdxn‘ where ‘x‘ is alphabet and ‘n‘ a number.

Here, '/dev' is the directory in '/' file system which holds files associated to each of the devices attached to a Linux system. After that 's' identifies a SATA, SCSI or PATA drive and 'v' is for virtual disks on KVM based Machines. The next alphabet i.e. 'd' is acronym for device and finally the next alphabet identifies the drive attached.

Linux Important Filesystem Directory Structure and Paths Explained

If your system has 4 hard disks, you may find listing for: /dev/sda, /dev/sdb, /dev/sdc, /dev/sdd in the output of fdisk command when ‘l’ option is invoked.


After the alphabet comes the number. A typical hard disk identifies 4 primary partitions of which there can be an extended partition too, which again holds multiple logical partitions. In that case, the first primary partition, which generally is the boot partition, holds the default label: '/dev/sda1' which signifies its position as first primary partition on first hard disk, likewise '/dev/sdb1' will be first primary partition on second hard disk.

The next primary partition will have sda2, then sda3 and so on, with logical partition starting from sda5. This is a just of how a Linux Partitioning is laid down, although currently one more type of partition exists, which is Linux LVM partition on which Logical Volume is created out of Physical Volume and Volume Groups on the fly without directly affecting the underlying hardware.

Linux Filesystem and Partitions – Types and Terminologies

A bare Linux system configures 2 partitions during normal installation i.e. root ('/') (Where the filesystem is laid down) and swap (a temporary storage space which is assumed to be twice of RAM by default which is although not necessary).

Bootloader is generally installed in root partition or the first primary partition. Partition lays down the base for filesystems which are then created on the partition, but before that it requires the partition to be formatted for the type of filesystem to be supported on that partition.

Some of the filesystems supported by Linux Systems include:
  1. ext2
  2. ext3
  3. ext4
  4. ReiserFS
  5. xfs
  6. FAT
  7. HPFS/NTFS/exFAT

Some Terminologies Relating to Linux Partitioning:

Primary Partition:

Directly holds area on hard disk specified in terms of first and last sector address and holding a label indicating the hard disk where it is and its number. It can hold the boot files for OS or the data as configured by user.

Extended Partition:

Partition which holds other partitions. Extended partition is created to hold multiple logical partitions. Unlike primary partition, it can’t hold the boot files of installed OS, as it holds and manages the logical partitions.

Logical Partition:

After first 4 primary partitions, come the logical partitions which are laid down on extended partition. These are generally used to hold the filesystem as laid down by user. Swap space is also configured as a logical partition.

Linux LVM Partition:

LVM partition is used for laying down filesystems created on Logical Volumes. LVM is acronym for Logical Volume Management, a feature of Linux to create on the fly Logical Volumes on partitions. It takes a partition, which then holds a Physical Volume and multiple Physical volumes are combined to create a volume group on which Logical Volume is laid down. Logical Volume is then formatted to hold the filesystem.

Volume:

A formatted segment of space, which can hold filesystem. Volume is created on the partition for mounting filesystem on it and allowing it to hold user data.

Since all the operations on partitions require modification of size of filesystem hosted by it, any modification, deletion or creation of partition require filesystems to be carefully unmounted and backed up to avoid risking loss of data.

Some Linux Utilities/Commands that come in handy for filesystem related operations include:
  1. fdisk – for creating, modifying, deleting partition, including creating and printing partition table and so on.
  2. parted – performs same operations as fdisk and even many more also considered.
  3. df – displays all the filesystems mounted on Linux Filesystem and their mount points.
  4. mount – for mounting filesystems, directories, changing mount point for a directory/device and all sorts of such operations.
  5. mkfs – creating and formatting a filesystem. Usually command is used in concatenation with the type of formatting desired. Like: mkfs.ext4 for formatting filesystem with type ext4.
  6. umount – for unmounting filesystem from a partition.
  7. GParted/QParted – GUI Parted for Gnome and KDE systems.
  8. Disks – Software Utility pre-installed on Linux systems for managing partitions through GUI.

Linux Utilities/Commands for Changing or Modifying Partition Names/Labels

Commands for changing or modifying Partition Name/ Label are dependent on type of filesystem on that partition with exception of some general commands.

Below you can find listing of all such commands.

1. e2label or tune2fs

The commands e2label or tune2fs used for changing label of ext2, ext3 and ext4 type partitions.

# e2label dev/sda1 ROOT
OR
# tune2fs –L ROOT_PART /dev/sda1

Here, ROOT and ROOT_PART are the labels to be added to /dev/sda1 which is ext4 formatted partition.

2. ntfslabel

The ntfslabel command used for changing label of NTFS partitions.

# ntfslabel /dev/sda5 NTFS_DIR

3. reiserfstune

The reiserfstune command used for labeling reiserFS formatted partitions.

Note: It is advisable to first unmount the filesystem before this command.

# reiserfstune –l HOME_PART /dev/sdb1

Where, /dev/sdb1 is the partition formatted with reiserFS filesystem.

4. mkswap

The mkswap command used for changing label of SWAP partition.

After unmounting the filesystem, following command needs to be executed to change the label of swap partition.

# mkswap -L SWAP_PART /dev/sda5

Where, /dev/sda5 is the SWAP formatted partition.

5. exfatlabel

The exfatlabel command used for changing the label of exFAT formatted partition.

# exfatlabel /dev/sda3 EX_PART

6. Changing Label of a partition in GUI – DISKS

Disks is a pre-installed utility found in most Linux systems which presents GUI for doing all the partitions related tasks which are done by fdisk and parted and even more than that. Disks can be used to change label of a partition by following procedure:

Show Linux Partition Table

Show Linux Partition Table

GUI of Disks shows, all the external drives and details of selected external drive including partitions, their labels, their size and type of formatting. First step is to select the partition whose label is to be changed, which is Partition 1 here, next step is to select gear icon and edit filesystem.

Change Linux Partition Label

Change Linux Partition Label

After this you will be prompted to change the label of selected partition.

Set Linux Partition Label Name

Set Linux Partition Label Name

And finally, the label of the partition will be changed.

Linux Partition Name Modified

Linux Partition Name Modified

Special Linux Utilities to Mount Partition with Label Names

1. Using Label for loading partition at boot time – /etc/fstab file

/etc/fstab is the file which is consulted at the boot time to mount the partitions that exist on the system. Partitions are by default identified by using UUID as per the entry in this /etc/fstab file.

But, there is another way to load the partition, instead of that long UUID, you can just pass the label of that partition in the file instead of UUID and from then on, your system would mount the partitions on the system using LABEL instead of UUID.

For loading any partition using Label rather than UUID just open the /etc/fstab file for editing:

$ sudo vi /etc/fstab

File looks like below:

Linux Fstab Mounted Partitions

Linux Fstab Mounted Partitions

Here, partition is recognized using UUID as seen above. Now if you want the partition to be recognized using label just edit the corresponding entry in the file replacing UUID=<uuid> by LABEL=<label>. Then, save and close the file. On next boot, the partition will be loaded using label instead of UUID.

2. Changing entries of partitions in partition table:

Some commands can be used to play with entries of partitions in partition table and shuffle the entries in the partition table.

These commands include:

1. gdisk

Utility which can be used to perform many useful operations on partitions, but highlighted here is one of its operation to change the partition names.

Procedure to follow:

# gdisk

This opens the gdisk and you will be prompted to enter the disk to be selected. Just enter the disk you want to select. '/dev/sda' for operating on first hard disk.

Next, you will get following prompt would appear asking you to enter any command. Enter ‘c’ here. You will be prompted to select the partition number whose name you want to edit. Enter the partition name and then you will be prompted to enter the new name. Enter the new name and hit ENTER.

Command(? For help):

Next, use the following option to verify that the change you did, is done.

Command(? For help): p

Now Close and exit gdisk, saving your changes.

Command(? For help): w

2. mount

Mount can also be used to change the name of partition. Following procedure can be used here:

Unmount the partition.

# umount /partition

Change the name of directory after it is un-mounted.

# mountpoint /partition &>/dev/null || mv /partition /new_name_partition

Edit /etc/fstab and change the mount point of partition from /partition to /new_name_partition and then remount the partition.

# mount /new_name_partition

Conclusion

Above are the techniques presented for Changing/Modifying the Name/Label of Linux Partitions. If you have other interesting techniques which can achieve the same thing do share with us in your precious comments.

Facebook Comments
Spread the love

Posted by News Monkey