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. 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.
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.
'/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.
If your system has 4 hard disks, you may find listing for:
/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:
Some Terminologies Relating to Linux Partitioning:
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.
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.
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.
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:
- fdisk – for creating, modifying, deleting partition, including creating and printing partition table and so on.
- parted – performs same operations as fdisk and even many more also considered.
- df – displays all the filesystems mounted on Linux Filesystem and their mount points.
- mount – for mounting filesystems, directories, changing mount point for a directory/device and all sorts of such operations.
- 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.
- umount – for unmounting filesystem from a partition.
- GParted/QParted – GUI Parted for Gnome and KDE systems.
- 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
ROOT_PART are the labels to be added to
/dev/sda1 which is ext4 formatted partition.
The ntfslabel command used for changing label of NTFS partitions.
# ntfslabel /dev/sda5 NTFS_DIR
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
/dev/sdb1 is the partition formatted with reiserFS filesystem.
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
/dev/sda5 is the SWAP formatted partition.
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:
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.
After this you will be prompted to change the label of selected partition.
And finally, the label of the partition will be changed.
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:
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
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:
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:
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
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
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.