Configure mount points and swap files

For a full list of keys, refer to the mounts module schema.

Create swap file

This example creates a 2 GB swap file at /swapfile using human-readable values.

1#cloud-config
2swap:
3  filename: /swapfile
4  size: 2G
5  maxsize: 2G

Set mount point and create swap file

In this example we mount: - ephemeral0 with the "noexec" flag, - /dev/sdc with mount_default_fields, and - /dev/xvdh with custom fs_passno “0” to avoid fsck on the mount.

The config also provides an automatically-sized swap with a maximum size of 10485760 bytes.

 1#cloud-config
 2mounts:
 3- [ /dev/ephemeral0, /mnt, auto, "defaults,noexec" ]
 4- [ sdc, /opt/data ]
 5- [ xvdh, /opt/data, auto, "defaults,nofail", "0", "0" ]
 6mount_default_fields: [None, None, auto, "defaults,nofail", "0", "2"]
 7swap:
 8  filename: /my/swapfile
 9  size: auto
10  maxsize: 10485760

Explanation of fields

Let us break down some of the options available.

Mounts

Set up mount points. mounts contains a list of lists. The inner list contains entries for an /etc/fstab line, e.g.:

[ fs_spec, fs_file, fs_vfstype, fs_mntops, fs-freq, fs_passno ]

With defaults:

mounts:
  - [ ephemeral0, /mnt ]
  - [ swap, none, swap, sw, 0, 0 ]

To remove a previously-listed mount (i.e., a default one), list only the fs_spec. For example, to override the default, of mounting swap [ swap ] or [ swap, null ].

  • If a device does not exist at the time, an entry will still be written to /etc/fstab.

  • /dev can be omitted for device names that begin with: xvd, sd, hd, or vd.

  • If an entry does not have all 6 fields, they will be filled in with values from the mount_default_fields below.

Note

You should set nofail (see man fstab) for volumes that may not be attached at instance boot (or reboot).

Example for mounts

mounts:
 - [ ephemeral0, /mnt, auto, "defaults,noexec" ]
 - [ sdc, /opt/data ]
 - [ xvdh, /opt/data, "auto", "defaults,nofail", "0", "0" ]
 - [ dd, /dev/zero ]

Mount default fields

The mount_default_fields values are used to fill in any incomplete entries in mounts. This must be an array, and must have 6 fields.

mount_default_fields: [ None, None, "auto", "defaults,nofail", "0", "2" ]

Swap

swap can also be set up by the mounts module. The default behavior is to not create any swap files, because size is set to 0.

swap:
  filename: /swap.img
  size: "auto" # or size in bytes
  maxsize: 10485760   # size in bytes