Skip to content

partition

One partition on a disk, made with parted, with a partition table on a disk that has none. It never shrinks, moves or deletes a partition, and never relabels a disk.

Use partition to give a new data disk its partition table and partitions, ready for filesystem or lvm_volume_group. It’s the parted you’d otherwise script, made safe to run on every apply: it makes what’s missing, grows a partition when you ask, and refuses everything that could lose data.

A whole new disk as one partition for LVM:

step "parted" {
package {
name = "parted"
}
}
step "data_part" {
partition {
device = "/dev/vdb"
number = 1
start = "1MiB"
end = "100%"
flags = ["lvm"]
}
}

After the cloud provider enlarged the disk, let the partition follow:

step "data_part" {
partition {
device = "/dev/vdb"
number = 1
start = "1MiB"
end = "100%"
flags = ["lvm"]
resize = true
}
}

Use a stable name for the disk where you can, such as /dev/disk/by-id/...: /dev/vdb can be another disk after a reboot.

Name Type Required Description
device string Yes The disk, such as /dev/vdb or /dev/disk/by-id/….
end string Yes Where it ends: a size, such as “20GiB”, or a percentage of the disk, such as “100%” for the rest of it.
flags list of string No The partition’s whole set of flags, such as [“lvm”] or [“esp”]. Unset leaves them alone.
label string No The partition table to make on a disk without one: “gpt” (default) or “msdos”. A disk with another table is refused, never relabelled.
number number Yes The partition’s number, from 1. parted numbers a new partition with the lowest free one, so make them in order.
resize bool No Grow the partition when end moves out, as after a disk is enlarged. Shrinking is always refused.
start string Yes Where it starts: a size in MiB, GiB or TiB, such as “1MiB” for the first.

Conn3x sets these; reference them as conn3x_partition.<circuit>__<step>["<host>"].<name>.

Name Type Description
in_sync bool Whether the partition was there, from start to end, with its flags, at the last refresh.
revision string Changes each time Conn3x changes this on the host. Handlers watch it.

A step lowers to the conn3x_partition resource, one instance per host, and connects with its circuit’s ssh block.

Reading. On every plan, Conn3x reads the disk with parted -m. in_sync is true when the disk has the label table, and partition number runs from start to end with its flags. Start and end are compared within a MiB, since parted aligns them, and 100% means the end of the disk, short of the backup GPT.

A blank disk. A disk with no partition table gets label, gpt unless you say msdos. Then the partition is made with parted -a optimal.

What it refuses. Each of these fails the step with nothing changed:

  • relabelling a disk that has another partition table, which would lose every partition on it;
  • shrinking a partition, which can lose what’s past its new end;
  • moving a partition’s start;
  • growing one without resize = true;
  • a number that isn’t the next free one, since parted numbers a new partition itself and would otherwise make a different one than you asked for.

Flags. flags is the partition’s whole set: listed flags are set, and others are cleared. Leave it unset to leave them alone.

Changes. Changing start, end, label or flags updates the partition in place, within the limits above. Changing device or number replaces the step.

A partition step has no on_remove, like the other storage steps. Taking it out of a circuit leaves the partition and its data as they are.