# How to autoformat a drive using cloud-init

**URL:** <https://forums.suse.com/t/how-to-autoformat-a-drive-using-cloud-init/6221>\
**Category:** RancherOS\
**Created:** [April 23, 2017, 11:17pm UTC](https://forums.suse.com/t/how-to-autoformat-a-drive-using-cloud-init/6221 "2017-04-23T23:17:28Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![stieler-it](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/stieler-it/32/2204_2.png) [@stieler-it](https://forums.suse.com/u/stieler-it)\
**Post date:** [April 23, 2017, 11:17pm UTC](https://forums.suse.com/t/how-to-autoformat-a-drive-using-cloud-init/6221/1 "2017-04-23T23:17:28Z")

</div>

We’re using RancherOS on OpenStack and want to use a external attached volume to store the data of a database container.

To make our enviornments self-initializing, we want to have the volume auto-formatted and according to the docs RancherOS supports this exact requirement. However, we can’t get it to work.

This is an excerpt of the cloud-init:

```
#cloud-config
mounts:
- ["/dev/vdb", "/mnt", "ext4", ""]
rancher:
  state:
    fstype: ext4
    formatzero: true
    autoformat:
    - /dev/vdb

```

When running it manually using cloud-init-execute there is the following output:

```
mount: mounting /dev/vdb on /mnt failed: Invalid argument
> ERRO[0000] Failed to mount /mnt: exit status 255

```

Which is the same output which mnt -t ext4 /dev/vdb /mnt shows. I assume it is because the drive has not been formatted before.

Any idea what could be wrong?

---

<div class="post-metadata">

**Author:** ![huggla](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/huggla/32/3050_2.png) [@huggla](https://forums.suse.com/u/huggla)\
**Post date:** [April 25, 2017, 5:45pm UTC](https://forums.suse.com/t/how-to-autoformat-a-drive-using-cloud-init/6221/2 "2017-04-25T17:45:45Z")

</div>

You could try to echo the mount command to rc.local. By the time rc.local is executed it should be formatted.

---

<div class="post-metadata">

**Author:** ![stieler-it](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/stieler-it/32/2204_2.png) [@stieler-it](https://forums.suse.com/u/stieler-it)\
**Post date:** [April 25, 2017, 8:48pm UTC](https://forums.suse.com/t/how-to-autoformat-a-drive-using-cloud-init/6221/3 "2017-04-25T20:48:28Z")

</div>

Thanks! I don’t think it’s a timing issue though. The problem seems to be that the volume iis not being formatted at all…

---

<div class="post-metadata">

**Author:** ![huggla](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/huggla/32/3050_2.png) [@huggla](https://forums.suse.com/u/huggla)\
**Post date:** [April 26, 2017, 4:33am UTC](https://forums.suse.com/t/how-to-autoformat-a-drive-using-cloud-init/6221/4 "2017-04-26T04:33:39Z")

</div>

You could echo the format command too, as a workaround.

---

<div class="post-metadata">

**Author:** ![huggla](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/huggla/32/3050_2.png) [@huggla](https://forums.suse.com/u/huggla)\
**Post date:** [April 26, 2017, 7:36am UTC](https://forums.suse.com/t/how-to-autoformat-a-drive-using-cloud-init/6221/5 "2017-04-26T07:36:19Z")

</div>

You could perhaps have some use of [this](https://github.com/huggla/rancher-cloud-config).

---

<div class="post-metadata">

**Author:** ![stieler-it](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/stieler-it/32/2204_2.png) [@stieler-it](https://forums.suse.com/u/stieler-it)\
**Post date:** [April 28, 2017, 5:16pm UTC](https://forums.suse.com/t/how-to-autoformat-a-drive-using-cloud-init/6221/6 "2017-04-28T17:16:35Z")

</div>

Hi,

of course you’re right, it would be possible to write that functionality manually. However, I was hoping that the “reformat only if not formatted / zero” functionality can be used easily. I bet I can find out how to create the same functionality in bash, too.

For now, I stick to manually formatting the volume each time a new environment is created. It’s probably better to have a conditional format command in the bootup script of a productive system anways.

Thanks for your help, though!

Michael

---

<div class="post-metadata">

**Author:** ![tzrlk](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/tzrlk/32/2533_2.png) [@tzrlk](https://forums.suse.com/u/tzrlk)\
**Post date:** [June 9, 2017, 1:40am UTC](https://forums.suse.com/t/how-to-autoformat-a-drive-using-cloud-init/6221/7 "2017-06-09T01:40:43Z")

</div>

Have you got a startup script that does this that you’d be willing to post, @stieler-it?

---

<div class="post-metadata">

**Author:** ![stieler-it](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/stieler-it/32/2204_2.png) [@stieler-it](https://forums.suse.com/u/stieler-it)\
**Post date:** [June 9, 2017, 6:09am UTC](https://forums.suse.com/t/how-to-autoformat-a-drive-using-cloud-init/6221/8 "2017-06-09T06:09:40Z")

</div>

Setting up a new environment does not have to be an automated task for us right now. So I sticked to manually formatting the two volumes we need. After the next reboot they are mounted automatically.

We have now switched to Ubuntu for our test (had some performance problems and want to make sure it’s not RancherOS). Ubuntu with cloud-init also supports the format-if-needed functionality.

---

<div class="post-metadata">

**Author:** ![christopher\_clark](https://avatars.discourse-cdn.com/v4/letter/c/e56c9b/32.png) [@christopher\_clark](https://forums.suse.com/u/christopher_clark)\
**Post date:** [May 2, 2018, 6:49am UTC](https://forums.suse.com/t/how-to-autoformat-a-drive-using-cloud-init/6221/9 "2018-05-02T06:49:49Z")

</div>

I just tried doing some `mkfs.vfat` formatting myself in rancherOS while installing, and I couldn’t format my drives as well. So I don’t think you can format at all. RancherOS does not include the tools to format drives? I’m getting a command not found

---

<div class="post-metadata">

**Author:** ![stieler-it](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/stieler-it/32/2204_2.png) [@stieler-it](https://forums.suse.com/u/stieler-it)\
**Post date:** [May 2, 2018, 10:19pm UTC](https://forums.suse.com/t/how-to-autoformat-a-drive-using-cloud-init/6221/10 "2018-05-02T22:19:08Z")

</div>

We are using `sudo mkfs.ext4 /dev/vdb`

---

<div class="post-metadata">

**Author:** ![ekristen](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/ekristen/32/5153_2.png) [@ekristen](https://forums.suse.com/u/ekristen)\
**Post date:** [June 12, 2019, 4:04pm UTC](https://forums.suse.com/t/how-to-autoformat-a-drive-using-cloud-init/6221/11 "2019-06-12T16:04:15Z")

</div>

I believe the docs are wrong, if you want to use autoformat, all the parameters have to be passed in as kernel parameters. At least that is the only way I’ve been able to make it work.
