Mkfs on block devices

Hello Developers,

While testing our addon on CentOS 7 host I’ve hit the following flaw.

mkfs.xfs failed to format a device where mkfs.ext4 succeeded.

To grant rw rights I’ve added oneadmin user to the system ‘disk’ group. This was enough to have mkfs.extX working untill I’ve tried to create XFS:

$ mkfs -t xfs -f -q /dev/storpool/one-sys-22-4-xfs
mkfs.xfs: error - cannot set blocksize 512 on block device /dev/storpool/one-sys-22-4-xfs: Permission denied

I’ve straced mkfs.xfs and found that in the kernel CAP_SYS_ADMIN is required to set BLKBSZSET on block devices, that is required by mkfs.xfs.

So I’ve tried with sudo but again failed. This time because of PATH/rights mismatch.

By default on CentOS 7 the oneadmin user is created with following path:

$ echo $PATH

But in /etc/sudoers.d/opennebula we have allowed /sbin/mkfs (where it is placed on most distributions):

Cmnd_Alias ONE_MISC = /bin/dd, /sbin/mkfs, /bin/sync

Obviously it can be solved by appending /sbin to the PATH or call explicitly /sbin/mkfs.

In our drivers I am using the function mkfs_command found in $LIB_LOCATION/sh/

For the moment I’ve solved the case by replacing MKFS variable in our scripts to:

MKFS=“sudo /sbin/mkfs”

Is there a safe way to change MKFS variable that will not be overwritten on update?

Kind Regards,
Anton Todorov

I think appending /sbin is the way to go. Can you submit a PR?

Yes I will send a PR with a little extended context to have an option to customize variables via external script.

Anton Todorov

Opened ticket #4137

I am proposing more general approach to add option to override each of the arguments via the environment where the script is called.

Anton Todorov