• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Geek Diary

HowTos | Basics | Concepts

  • Solaris
    • Solaris 11
    • SVM
    • ZFS
    • Zones
    • LDOMs
    • Hardware
  • Linux
    • CentOS/RHEL 7
    • RHCSA notes
    • SuSE Linux Enterprise
    • Linux Services
  • VCS
    • VxVM
  • Interview Questions
  • oracle
    • ASM
    • mysql
    • RAC
    • oracle 12c
    • Data Guard
  • DevOps
    • Docker
    • Shell Scripting
  • Hadoop
    • Hortonworks HDP
      • HDPCA
    • Cloudera
      • CCA 131

How to Change the filesystem Labels in CentOS/RHEL

By admin

The device node name of a disk (/dev/sda, /dev/hda, /dev/vda, etc.) may change in some situations. For example, after switching cables around or upgrading certain packages, sda & sdc could swap places. This causes problems when /etc/fstab references filesystems by the disk names. Instead, we can use filesystem labels to refer them in /etc/fstab file. This allows us for identifying a filesystem without resorting to ephemeral block device names.

Note: The UUIDs and labels are not required if a filesystem resides on an LVM logical volume, as in default RHEL installations.

Check the current Label of the filesystem

1. To find out the label of the filesystem, you can use the “blkid” command as showb below.

# blkid /dev/sda1
/dev/sda1: LABEL="/boot" UUID="c9fdb384-19ed-4b94-b29e-23f0f566e970" TYPE="ext4"

2. You can also determine which filesystem in /etc/fstab file are referenced by their LABELs instead of actual device names. For example:

# cat /etc/fstab
LABEL="/boot"                                 /boot   ext4    defaults        1 2
UUID="80a27dc2-c309-4cc8-9ceb-3bb1a055cf3d"   /data   ext4    defaults        0 2

3. Additionally, you can also verify the kernel args line in /etc/grub.conf for any use of non-LVM device node names.

# grep kernel /etc/grub.conf
    kernel /vmlinuz-2.6.18-308.el5 ro root=/dev/vda2

Changing the Filesystem Labels Online

The e2label command can be used to set/change labels on ext2, ext3, and ext4 filesystems. The syntax to use the command is simple:

# e2label
Usage: e2label device [newlabel]

For example, to change the lable of the partition /dev/sda1 to /boot, use the below command:

# e2label /dev/sda1 /boot

When modifying existing labels, make sure to update any references to the old labels in /etc/fstab and /etc/grub.conf and modify them accordingly.

# grep LABEL /etc/grub.conf
kernel /vmlinuz-2.6.18-164.el5 ro root=LABEL=/
# grep LABEL /etc/fstab
LABEL=/                /         ext3    defaults        1 1
LABEL=/boot            /boot     ext3    defaults        1 2

A note about swap devices

To add/change labels to swap partitions, they must be turned off with “swapoff [DEVICE]” and remade with “mkswap -L [LABEL] [DEVICE]” before being turned back on with “swapon [DEVICE]”. Swap UUIDs are only possible in RHEL6 and above. See the mkswap man page for more details.

# man mkswap
CentOS / RHEL : How to change the UUID of the filesystem

Filed Under: CentOS/RHEL 6, CentOS/RHEL 7, Linux

Some more articles you might also be interested in …

  1. CentOS / RHEL 7 : How to reinstall GRUB2 from rescue mode
  2. Beginners Guide to “journalctl” – How To Use Journalctl to View and Manipulate Systemd Logs
  3. How to Disable Client Access Control in MySQL
  4. Troubleshooting slow network communication or Connection Timeouts in Linux
  5. How to Install and Configure Device Mapper Multipath in CentOS/RHEL 6,7
  6. CentOS / RHEL : How to change password hashing algorithm
  7. CentOS / RHEL : How to rotate /var/log/wtmp and /var/log/btmp file using logrotate
  8. How to enable SFTP Logging without chroot in CentOS/RHEL
  9. Troubleshooting Common GUI / X-Window Issues on CentOS/RHEL
  10. How to use auditd to monitor a file deletion in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • “su: Authentication failure” – in Docker
  • How to Pause and Resume Docker Containers
  • How to find docker storage device and its size (device mapper storage driver)
  • Understanding “docker stats” Command Output
  • ‘docker images’ command error – “Permission Denied”
  • Archives
  • Contact Us
  • Copyright

© 2019 · The Geek Diary