3

I'm running a centos 7 server.
I want to change the label of the root file system (xfs).
xfs_admin -L "newlabel" /dev/mapper/centos-root fails because it can't operate on a mounted filesystem.

Is it possible to change label of mounted filesystem?

Is there a way to run something like that during boot before the root fs is mounted?

2 Answers 2

6

The ability to update the label of a mounted XFS file system was recented added. August 2018 for upstream code and November 2018 for RHEL/CentOS 7 packages.

Update the label like this (as root):

xfs_io -c "label -s MYNEWLABEL" /MNTPOINT

From the xfs_io man page:

label [ -c | -s label ]
On filesystems that support online label manipulation, get, set, or clear the filesystem label. With no options, print the current filesystem label. The -c option clears the filesystem label by setting it to the null string. The -s label option sets the filesystem label to label. If the label is longer than the filesystem will accept, xfs_io will print an error message. XFS filesystem labels can be at most 12 characters long.

For upstream code this required Linux kernel >= 4.18 and xfsprogs >= 4.17.0.

For RHEL / CentOS 7 this required packages kernel >= 3.10.0-957.el7 and xfsprogs >= 4.5.0-17.

References:

1
  • 1
    thanks, that was very useful. I had to follow it up with a "partprobe" before the label appeared in /dev/disk/by-label
    – Paul M
    Commented Sep 2, 2020 at 16:02
0

From man xfs_admin

Devices that are mounted cannot be modified. Administrators must unmount filesystems before xfs_admin or xfs_db(8) can convert parameters. A number of parameters of a mounted filesystem can be examined and modified using the xfs_growfs(8) command.

2
  • 1
    I know. That is exactly what I'm trying to find a solution to... This is the root file system so you can't unmount it. This is why I asked in my question if there is a way to run some command/script before the root file system is mounted during boot
    – csny
    Commented Nov 22, 2015 at 10:51
  • Well, since the documentation says it can't be done, I would say you're searching in vain.
    – cristi
    Commented Nov 22, 2015 at 11:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .