How to autoformat a drive using cloud-init

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:

- ["/dev/vdb", "/mnt", "ext4", ""]
    fstype: ext4
    formatzero: true
    - /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?

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

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…

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

You could perhaps have some use of this.


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!


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

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.

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

We are using sudo mkfs.ext4 /dev/vdb

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.