infochimps-labs/ironfan-pantry — pull request #44 by westbywest (2014-07-31 17:14:34+00:00)
Title: workaround for EC2 mkfs volume label issue

mkfs fails formatting an EBS volume on an AWS instance running Ubuntu 12.04.4 LTS:

```
realm-cluster-node-2 Compiled Resource:
realm-cluster-node-2 ------------------
realm-cluster-node-2 # Declared in /var/chef/cache/cookbooks/volumes/recipes/format.rb:34:in `block in from_file'
realm-cluster-node-2
realm-cluster-node-2 execute("/sbin/mkfs -t ext4 /dev/xvdb -L mnt") do
realm-cluster-node-2 action [:nothing]
realm-cluster-node-2 retries 0
realm-cluster-node-2 retry_delay 2
realm-cluster-node-2 guard_interpreter :default
realm-cluster-node-2 command "/sbin/mkfs -t ext4 /dev/xvdb -L mnt"
realm-cluster-node-2 backup 5
realm-cluster-node-2 returns 0
realm-cluster-node-2 cookbook_name "volumes"
realm-cluster-node-2 recipe_name "format"
realm-cluster-node-2 not_if "eval $(blkid -o export /dev/xvdb); test $TYPE = 'ext4'"
realm-cluster-node-2 end
realm-cluster-node-2
realm-cluster-node-2
realm-cluster-node-2
realm-cluster-node-2
realm-cluster-node-2 ================================================================================
realm-cluster-node-2 Recipe Compile Error in /var/chef/cache/cookbooks/volumes/recipes/format.rb
realm-cluster-node-2 ================================================================================
realm-cluster-node-2
realm-cluster-node-2
realm-cluster-node-2 Mixlib::ShellOut::ShellCommandFailed
realm-cluster-node-2 ------------------------------------
realm-cluster-node-2 execute[/sbin/mkfs -t ext4 /dev/xvdb -L mnt] (volumes::format line 34) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
realm-cluster-node-2 ---- Begin output of /sbin/mkfs -t ext4 /dev/xvdb -L mnt ----
realm-cluster-node-2 STDOUT:
realm-cluster-node-2 STDERR: Usage: mkfs.ext4 [-c|-l filename] [-b block-size] [-C cluster-size]
realm-cluster-node-2	[-i bytes-per-inode] [-I inode-size] [-J journal-options]
realm-cluster-node-2	[-G meta group size] [-N number-of-inodes]
realm-cluster-node-2	[-m reserved-blocks-percentage] [-o creator-os]
realm-cluster-node-2	[-g blocks-per-group] [-L volume-label] [-M last-mounted-directory]
realm-cluster-node-2	[-O feature[,...]] [-r fs-revision] [-E extended-option[,...]]
realm-cluster-node-2	[-T fs-type] [-U UUID] [-jnqvFKSV] device [blocks-count]
realm-cluster-node-2 ---- End output of /sbin/mkfs -t ext4 /dev/xvdb -L mnt ----
realm-cluster-node-2 Ran /sbin/mkfs -t ext4 /dev/xvdb -L mnt returned 1
```

Volume definition which triggered this:

```
volume(:mnt) do
size 20
keep false
create_at_launch true
device '/dev/sdb' # Note: will appear as /dev/xvdb on modern ubuntus
mount_point '/mnt'
mount_options ['defaults', 'noatime']
fstype 'ext4'
attachable :ebs
formattable true
resizable false
tags( :persistent => true, :local => false, :bulk => false, :fallback => false )
end
```

The sticking point seems to be using the -L parameter with mkfs. Running "sudo /sbin/mkfs -t ext4 /dev/xvdb" works as expected.

Leading from [this thread](http://serverfault.com/questions/239605/creating-an-ec2-image-on-amazon-fails-at-mkfs-ext3) on stack exchange, a work-around is to use e2label, i.e.
```
sudo /sbin/mkfs -t ext4 /dev/xvdb ; sudo e2label /dev/xvdb mnt
```