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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

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. more: command not found
  2. rpcinfo: can’t contact rpcbind: : RPC: Authentication error; why = Client credential too weak
  3. restorecon: command not found
  4. How to start/stop Virtual Machines in RedHat Virtualization
  5. vgextend Command Examples in Linux
  6. perf: command not found
  7. rsyslogd Command Examples in Linux
  8. CentOS / RHEL 7 : Configuring NTP using chrony
  9. GoBuster: command not found
  10. md5sum Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • pw-cat Command Examples in Linux
  • pvs: command not found
  • pulseaudio: command not found
  • pulseaudio Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright