How to setup partitions on my boot disk with cloud-config?

I try to initialize an ubuntu 16.04 server via cloud-init. While booting the server the first time I wanna create the following partitions:

  • root-fs (ext4 filesystem ubuntu)
  • data-disk (xfs formatted partition)
  • swap disk (4gb)

when I boot the machine regularly (without any cloud-init) I have a sda and sda1 (I think sda1 is the swap).

  • Can someone help me out with a "valid" or "working" example or help me correct my approach?

  • Or is this impossible to make partitions on the disk where I am sitting on?

btw. my host is Hetzner

This is my current approach:

#cloud-config
device_aliases: {'root-disk': '/dev/sda'}
resize_rootfs: true
disk_setup: root-disk: table_type: 'gpt' layout: - 75 - [25, 82] overwrite: true
fs_setup: - label: root-fs device: 'root-disk' filesystem: 'ext4' - label: data-disk device: root-disk filesystem: 'xfs'

1 Answer

To close that task I post here my answer: Important to know is, that resize_rootfs has to be falseI also ended up using mbr instead of gpt only because I couldn't figure out how to evolve with gpt. Maybe someone could post that example too.

#cloud-config
resize_rootfs: false
disk_setup: /dev/sda: table_type: 'mbr' layout: - 25 - 75 overwrite: true
fs_setup: - label: root_fs filesystem: 'ext4' device: /dev/sda partition: sda1 overwrite: true - label: data_disk filesystem: 'xfs' device: /dev/sda partition: sda2 overwrite: true
# now we attach the settings
runcmd: - [ partx, --update, /dev/sda ] - [ mkfs.xfs, /dev/sda2 ] - [ partprobe ] - parted /dev/sda set 1 boot on p
mounts: - ["/dev/sda1", "/"] - ["/dev/sda2", "/data-disk"]
2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like