Skip to content

Instantly share code, notes, and snippets.

@exocode
Last active June 18, 2024 16:07
Show Gist options
  • Save exocode/a7e12b063f23a1ef899b23bcbfc7d123 to your computer and use it in GitHub Desktop.
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.
#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"]
@tabascoterrier
Copy link

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 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment