Home / Alt manpages / e2label(8)

  • e2label(8)
  • Admin command
  • linux

Change an ext4 Filesystem Label Safely with e2label

e2label looks harmless until you rename the wrong device and your fstab entries stop matching reality. You will read an ext2, ext3 or ext4 label, change it deliberately, and verify the new value landed on the right filesystem. Allow about ten minutes. You need the e2label command from e2fsprogs; the examples here use e2fsprogs 1.47.0, installed as package version 1.47.0-2.4~exp1ubuntu4.1.

Safety checkpoint

Setting a label changes filesystem metadata. The device argument is not a harmless name lookup. Confirm the path before using the two-argument form, and keep a backup or snapshot if the filesystem holds data you cannot recreate.

1. Confirm the command and identify the device

e2label takes a device and, optionally, a new label. It has no general-purpose help or version switch in the installed interface. Check which executable your shell will run, then inspect candidate block devices before changing anything:

$ command -v e2label
/usr/sbin/e2label
$ lsblk -o NAME,PATH,FSTYPE,LABEL,SIZE,MOUNTPOINTS
  • Use the full path shown by lsblk, such as /dev/sdb1, never a guess based on the disk's position.
  • Confirm the filesystem type is ext2, ext3 or ext4. Reading a label normally needs no elevated privilege when the device is readable, but access to a block device often does require sudo.
  • Do not confuse a disk with a partition. /dev/sdb and /dev/sdb1 can be entirely different objects, and the disk itself may not hold the filesystem whose label you intend to change.

2. Read the current label

Omit the optional label argument for a read-only query:

$ sudo e2label /dev/sdb1
ARCHIVE_2025

The output is the current volume label, followed by a newline. A blank line means the filesystem has no label, not that the command failed. Capture the old value before changing it if you may need to restore it.

Checkpoint

If the command reports that it cannot open the device or cannot find a valid filesystem superblock, stop. Recheck the path, filesystem type and permissions rather than trying several nearby device names.

3. Set a new label

Pass the exact label as the second argument; the command changes the filesystem metadata in place:

$ sudo e2label /dev/sdb1 ARCHIVE_2026
$ sudo e2label /dev/sdb1
ARCHIVE_2026

The command does not print a success message when the change works, so its exit status is the useful signal for scripts:

if sudo e2label /dev/sdb1 ARCHIVE_2026; then
    printf '%s\n' 'Filesystem label updated'
else
    status=$?
    printf 'e2label failed with status %s\n' "$status" >&2
    exit "$status"
fi

Run the read-back command after a successful write. This catches a wrong device argument and gives you an observable checkpoint before mounts, fstab changes or automation continue.

4. Keep the label within the ext2 limit

The installed manual documents a maximum of 16 characters for ext2 volume labels. If a label is longer, e2label truncates it and prints a warning. The same length is a sensible portable limit when the filesystem may later be used as ext2, ext3 or ext4:

$ sudo e2label /dev/sdb1 THIS_LABEL_IS_LONGER_THAN_SIXTEEN
Warning: label too long, truncating.
$ sudo e2label /dev/sdb1
THIS_LABEL_IS_LO

Do not treat exit status 0 as proof the complete string was stored. Always read it back, especially in scripts. A short label made from letters, digits, underscores or hyphens is easier to recognise in lsblk output and avoids accidental whitespace.

5. Verify with a second filesystem tool

For a local ext filesystem, tune2fs gives an independent read of the superblock. It is a verification command here, not a replacement for choosing the correct device:

$ sudo tune2fs -l /dev/sdb1 | grep '^Filesystem volume name:'
Filesystem volume name:   ARCHIVE_2026

The spacing in the output is not significant. The value after the field name should match the result from e2label. If the two readings disagree, stop using the device and investigate rather than repeatedly writing labels.

6. Recover from a mistake

If you changed the label on the wrong filesystem but know the previous value, restore it by passing that value back to the same device:

$ sudo e2label /dev/sdb1 ARCHIVE_2025
$ sudo e2label /dev/sdb1
ARCHIVE_2025

Changing a label does not restore any other metadata and does not undo a wrong mount or partition operation. If you do not know the old value, check your inventory, backups or documentation before choosing a replacement: do not infer it from a mount directory alone.

For a mounted ext filesystem, the local e2label manual says online label manipulation is supported for filesystems that support it, without truncating the label in those cases. The safest operational practice is still to schedule metadata changes, check the exact filesystem type, and avoid changing a busy production volume unless your maintenance procedure permits it. Never unmount a service filesystem casually: stopping services and unmounting can cause an outage.

Common traps

  • "No such file or directory": the path is wrong, the device is absent, or a symlink target is unavailable. Check lsblk and readlink -f before retrying.
  • "Couldn't find valid filesystem superblock": the argument may be the whole disk, a non-ext filesystem, a damaged filesystem, or an image that is not a filesystem at all. Do not run repair tools merely because a label query failed.
  • Permission denied: retry with sudo only after confirming the device. Elevated privilege does not make an uncertain device choice safe.
  • Unexpected label in later commands: remember labels are metadata, not unique identity. Check UUIDs with blkid /dev/sdb1 when you need to tell filesystems apart reliably.

Done means

  • The device path and filesystem type were checked before the write.
  • The old label was read, and the new label was read back with e2label.
  • The label is no longer than 16 characters when portability across ext2, ext3 and ext4 matters.
  • A second read with tune2fs -l agrees with the requested value.
  • A wrong label can be restored without guessing at the device or the previous value.