6

Cloud-init provides the disk_setup, fs_setup and mounts modules to partition, format and mount a volume to a virtual machine, however these options remain undocumented at both http://cloudinit.readthedocs.org and AWS.

Does there exist a functional example of cloud-init configuration that will partition, format and mount a single EBS volume at AWS to an instance provisioned as follows:

"Volume" : {
  "Type" : "AWS::EC2::Volume",
  "Properties" : {
    "Size" : "100",
    "VolumeType" : "gp2",
    "AvailabilityZone" : { "Fn::GetAtt" : [ "ServerInstance", "AvailabilityZone" ] }
  },
  "DeletionPolicy" : "Delete"
},
"MountVolume" : {
  "Type" : "AWS::EC2::VolumeAttachment",
  "Properties" : {
    "InstanceId" : { "Ref" : "ServerInstance" },
    "VolumeId"  : { "Ref" : "Volume" },
    "Device" : "/dev/sdh"
  }
},

The closest I have so far is the following (with syntax issues corrected):

disk_setup:
  /dev/xvdh:
    layout: true
    overwrite: false
    table_type: 'mbr'
fs_setup: 
  - label: data
    device: /dev/xvdh0
    filesystem: ext4
mounts:
- [ xvdh0, /opt/data ]

According to the cloud-init-output.log the attempt to partition fails as follows:

2015-12-08 15:23:11,534 - util.py[WARNING]: Failed partitioning operation
'list' object has no attribute 'splitlines'

(For reasons undocumented an attempt to create a volume called /dev/sdh results in a partition appearing called /dev/xvdh, thus the mismatch in naming)

Graham Leggett
  • 208
  • 2
  • 10

1 Answers1

3

I know this is old, but here's what I came up with:

mounts:
    - [ "LABEL=rkt", "/var/lib/rkt" ]

fs_setup:
    ## rkt
    -   device: /dev/xvdg
        partition: none
        label: rkt
        filesystem: ext4

It formats /dev/xvdg -- unpartitioned -- as ext4 and labels it accordingly.

I had to add disk-setup to the cloud_init_modules list in /etc/cloud/cloud.cfg; it's not there by default, so fs_setup (which is processed by cc_disk_setup) wouldn't have any affect.

blalor
  • 176
  • 3
  • 1
    as of 2018 and Amazon Linux 2, `disk_setup` runs just before `mounts`. It's also true for the 'ECS optimized' AMI. – tedder42 Oct 22 '18 at 18:06