Last active
March 17, 2025 09:17
-
-
Save exocode/a7e12b063f23a1ef899b23bcbfc7d123 to your computer and use it in GitHub Desktop.
Create xfs partitions on Hetzner via cloud-init. It keeps root disk available again after rebooting. Simply change your desired sizes and filesystem to use it for your needs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 | |
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"] |
Thanks for the example, I've followed but I can't get it to save mounts in the /etc/fstab. Here is what I've tried.
#cloud-config
package_update: true
package_upgrade: true
packages:
- parted
resize_rootfs: false
disk_setup:
/dev/xvdb:
table_type: 'gpt'
layout:
- 10
- 30
- 10
overwrite: true
fs_setup:
- label: elastic
filesystem: 'ext4'
device: '/dev/xvdb'
partition: 'xvdb1'
overwrite: true
- label: elastic_data
filesystem: 'ext4'
device: '/dev/xvdb'
partition: 'xvdb2'
overwrite: true
- label: elastic_logs
filesystem: 'ext4'
device: '/dev/xvdb'
partition: 'xvdb3'
overwrite: true
runcmd:
- [ partx, --update, /dev/xvdb ]
- [ mkfs.ext4, /dev/xvdb1 ]
- [ mkfs.ext4, /dev/xvdb2 ]
- [ mkfs.ext4, /dev/xvdb3 ]
- [ partprobe ]
- mkdir /opt/elastic && mkdir /opt/elastic/data && mkdir /opt/elastic/logs
mounts:
- [ "/dev/xvdb1", "/opt/elastic" ]
- [ "/dev/xvdb2", "/opt/elastic/data" ]
- [ "/dev/xvdb3", "/opt/elastic/logs" ]
there is no /boot ext3 partition in all these suggestions
why?
@ilyangru you are the king, if they made a statue, they would run out of concrete for your balls
The @ilyangru example very nearly worked for me as is with an Ubuntu 20.04 box, I just had to quote the "1" in the 5th runcmd. It took me longer than I'd like to figure out so hopefully that'll help someone else.
#cloud-config
# Ubuntu 18.04+
resize_rootfs: false
write_files:
- content: |
# Any text
path: /etc/growroot-disabled
runcmd:
- [ sgdisk, -e, /dev/sda ]
- [ partprobe ]
- [ parted, -s, /dev/sda, mkpart, primary, xfs, "25%", "100%" ]
- [ mkfs.xfs, /dev/sda2 ]
- [ growpart, /dev/sda, "1" ]
- [ resize2fs, /dev/sda1 ]
mounts:
- [ /dev/sda2, /var/lib/mongodb ]
Thank you folks, the very last cloud-config worked for me too. I didn't need to mount or format new partitions, but I needed two of them, so I used this line for parted:
- [ parted, -a, opt, -s, /dev/sda, mkpart, primary, "15%", "60%", mkpart, primary, "60%", "100%"]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hey @ilyangru I finally had time to test it, it does not work for me.
I also had to install parted as it was not present.
I believe it has to do with the distro, I am using debian 10.
Are you guys using ubuntu?
My cloud-init-output.log looks like
EDITED
I can confirm it perfectly worked with ubuntu-20.01 , the partition appeared right after the reboot
It did not work on Debian 11.
Does somebody know what makes the difference?
It could be https://bugs.launchpad.net/cloud-init/+bug/1920939