.. _cce-disk-setup: Configure partitions and filesystems ************************************ Cloud-init supports the creation of simple partition tables and filesystems on devices. - Disk partitioning is done using the ``disk_setup`` directive. - File system configuration is done using the ``fs_setup`` directive. For a full list of keys, refer to the `disk setup module`_ schema. General example =============== .. literalinclude:: ../../../module-docs/cc_disk_setup/example1.yaml :language: yaml :linenos: Partition a disk ================ The ``disk_setup`` directive instructs Cloud-init to partition a disk. The format is: .. code-block:: yaml #cloud-config disk_setup: ephemeral0: table_type: 'mbr' layout: true /dev/xvdh: table_type: 'mbr' layout: - 33 - [33, 82] - 33 overwrite: True The format is a list of "dicts of dicts". The first value is the name of the device and the subsequent values define how to create and lay out the partition. The general format is: .. code-block:: yaml disk_setup: : table_type: 'mbr' layout: overwrite: Where: - ````: The name of the device. ``ephemeralX`` and ``swap`` are special values which are specific to the cloud. For these devices, cloud-init will look up what the real device is and then use it. For other devices, the kernel device name is used. At this time, only simple kernel devices are supported, meaning that device mapper and other targets may not work. Note: There is currently no handling or setup of device mapper targets. - ``table_type=``: Currently, the following are supported: - ``mbr``: (default) sets up an MS-DOS partition table - ``gpt``: sets up a GPT partition table Note: At this time only ``mbr`` and ``gpt`` partition tables are allowed. We anticipate that in the future we will also have ``RAID`` to create a ``mdadm`` RAID. - ``layout={...}``: The device layout. This is a list of values, with the percentage of disk that the partition will take. Valid options are: - ``[, [, `` is the **percentage** of the disk to use, while ```` is the numerical value of the partition type. The following sets up two partitions, with the first partition having a swap label, taking 1/3 of the disk space, and the remainder being used as the second partition: :: /dev/xvdh': table_type: 'mbr' layout: - [33,82] - 66 overwrite: True - When layout is "true", it instructs cloud-init to single-partition the entire device. - When layout is "false" it means "don't partition" or "ignore existing partitioning". If layout is set to "true" and overwrite is set to "false", cloud-init will skip partitioning the device without a failure. - ``overwrite=``: This describes whether to "ride with safetys on and everything holstered". - "false" is the default, which means that: 1. The device will be checked for a partition table 2. The device will be checked for a filesystem 3. If either a partition of filesystem is found, then the operation will be **skipped**. - "true" is **cowboy mode**. There are no checks and things are done blindly. Use this option only with caution, you can do things you really, really don't want to do. Set up the filesystem ===================== ``fs_setup`` describes the how the filesystems are supposed to look. .. code-block:: yaml fs_setup: - label: ephemeral0 filesystem: 'ext3' device: 'ephemeral0' partition: 'auto' - label: mylabl2 filesystem: 'ext4' device: '/dev/xvda1' - cmd: mkfs -t %(filesystem)s -L %(label)s %(device)s label: mylabl3 filesystem: 'btrfs' device: '/dev/xvdh' The general format is: .. code-block:: yaml fs_setup: - label: