# Mkfs on block devices

**URL:** <https://forum.opennebula.io/t/mkfs-on-block-devices/1422>\
**Category:** Integration Support\
**Created:** [November 4, 2015, 8:50am UTC](https://forum.opennebula.io/t/mkfs-on-block-devices/1422 "2015-11-04T08:50:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![atodorov\_storpool](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/atodorov_storpool/32/5327_2.png) [@atodorov\_storpool](https://forum.opennebula.io/u/atodorov_storpool)\
**Post date:** [November 4, 2015, 8:50am UTC](https://forum.opennebula.io/t/mkfs-on-block-devices/1422/1 "2015-11-04T08:50:03Z")

</div>

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  
> /usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/var/lib/one/.local/bin:/var/lib/one/bin`

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/scripts_common.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

---

<div class="post-metadata">

**Author:** ![jmelis](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/jmelis/32/24_2.png) [@jmelis](https://forum.opennebula.io/u/jmelis)\
**Post date:** [November 5, 2015, 9:37am UTC](https://forum.opennebula.io/t/mkfs-on-block-devices/1422/2 "2015-11-05T09:37:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![atodorov\_storpool](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/atodorov_storpool/32/5327_2.png) [@atodorov\_storpool](https://forum.opennebula.io/u/atodorov_storpool)\
**Post date:** [November 5, 2015, 11:36am UTC](https://forum.opennebula.io/t/mkfs-on-block-devices/1422/3 "2015-11-05T11:36:37Z")

</div>

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

Cheers,  
Anton Todorov

---

<div class="post-metadata">

**Author:** ![atodorov\_storpool](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/atodorov_storpool/32/5327_2.png) [@atodorov\_storpool](https://forum.opennebula.io/u/atodorov_storpool)\
**Post date:** [November 6, 2015, 7:10am UTC](https://forum.opennebula.io/t/mkfs-on-block-devices/1422/4 "2015-11-06T07:10:28Z")

</div>

Opened ticket #4137 [http://dev.opennebula.org/issues/4137](http://dev.opennebula.org/issues/4137)  
PR [https://github.com/OpenNebula/one/pull/74](https://github.com/OpenNebula/one/pull/74)

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

Cheers,  
Anton Todorov
