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

The Geek Diary

CONCEPTS | BASICS | HOWTO

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • Linux Services
    • VCS
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
    • Data Guard
  • DevOps
    • Docker
    • Shell Scripting
  • Interview Questions
  • 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. showmount Command Examples in Linux
  2. How to Change Timezone from CST To EST in CentOS/RHEL 7 Server
  3. Unable to Run X Applications Through SSH in Linux
  4. What are DNS Nameserver Types in Linux
  5. How to disable firewalld and and switch to iptables in CentOS / RHEL 7
  6. How to Install Apache, MariaDB, and PHP (FAMP) stack on FreeBSD 11
  7. How to Switch Password Algorithm on CentOS/RHEL
  8. Shopt: Not Found [No Such File Or Directory]
  9. “sudo: /etc/sudoers is world writable” – How to correct the permissions of sudoers file
  10. How to disable timeout in ssh during login prompt (login session inactivity) in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • How to disable ACPI in CentOS/RHEL 7
  • How to Use real-time query to access data on a physical standby database
  • CentOS/RHEL 8: “ACPI MEMORY OR I/O RESET_REG” Server Hung after reboot
  • How to Create a Physical Standby Database by Using SQL and RMAN Commands
  • Archives
  • Contact Us
  • Copyright

© 2021 · The Geek Diary