e2label
Set or change a filesystem's label
TLDR
Change the volume label on a specific ext partition
SYNOPSIS
e2label
PARAMETERS
The device name of the filesystem (e.g., /dev/sda1).
The new label to assign to the filesystem. If omitted, e2label displays the current label.
DESCRIPTION
The `e2label` command allows you to view or change the filesystem label of an ext2, ext3, or ext4 filesystem. The filesystem label can be used by mount(8), fsck(8), and other utilities to refer to a filesystem. This is particularly useful for identifying partitions when their device names (e.g., /dev/sda1) might change, making the system more robust against device reordering. Warning: Using `e2label` on a mounted filesystem may cause data corruption. It is recommended to unmount the filesystem before using `e2label` to modify the label. If you are using an older kernel, ensure you upgrade it before using this functionality; older kernels might not correctly support labels longer than 16 characters. The command can either display the current label or assign a new one. If no label is provided, it displays the existing label. If a new label is given as an argument, the old label is replaced with the new label. Filesystem labels can be a convenient way to identify partitions, but should not be relied upon exclusively for critical system operations.
CAVEATS
Using `e2label` on a mounted filesystem is strongly discouraged and may lead to data corruption. Always unmount the filesystem before changing the label.
Older kernels may have limitations on the maximum length of the filesystem label. Ensure your kernel supports the label size you intend to use.
ERROR HANDLING
If `e2label` fails to set the new label (e.g., due to insufficient permissions or filesystem errors), it will typically return a non-zero exit code. You can use this exit code in scripts to check for successful label modification.
MOUNTING BY LABEL
Filesystems with labels can be mounted using their labels in the `/etc/fstab` file. For example, instead of mounting `/dev/sda1`, you could mount `LABEL=MyRootPartition`.
HISTORY
The `e2label` command is part of the e2fsprogs package, which provides utilities for managing ext2, ext3, and ext4 filesystems. It was developed alongside these filesystem types to provide a mechanism for labeling and identifying partitions. The introduction of filesystem labels offered an improvement over relying solely on device names, especially in scenarios where device mappings could change across reboots.
It's usage became prevalent once labels were adopted and supported by bootloaders and init systems for mounting root file systems or other critical partitions.