Hetzner VPS: filesystem partitions

Автор | 21.10.2022

Sometimes I need to have separate partitions on VPS in Hetzner.

The simplest way to create a custom disk structure – use Cloud-init script

With commands:

#cloud-config

# we need to disable the initial call to "growpart" as otherwise the first partition would consume
# all space on the dist
#
# The final disk layout is:
# #0    0 - 10GB - ext4 on /
# #1 10GB - 100% - lvm
#
# The reason for this approach is that when using CentOS on Hetzner you cannot use
# the "disk_setup" mechanism from cloud-init, it simply is ignored.

growpart:
  mode: off

runcmd:
  - printf "fix\n" | parted ---pretend-input-tty /dev/sda print        # Fix parted error, first
  - [ parted, "/dev/sda", mkpart, primary, ext2, "10GB", "100%" ]  # create a new partition, starting at 10GB
  - [ parted, "/dev/sda", set, "2", lvm, on ]  # set LVM flag
  - [ growpart, "/dev/sda", "1" ]  # grow first partition to 10GB
  - [ partx, --update, "/dev/sda" ] # reload partition table
  - [ resize2fs, /dev/sda1 ] # resize first partition (/) to 10GB
  - [ pvcreate, "/dev/sda2" ] # create PV on /dev/sda2 (100%-10GB)
  - [ vgcreate, vg1, "/dev/sda2" ] # create VG, adding PV /dev/sda2

repo_update: true
repo_upgrade: all

packages:
  - lvm2  # missing in the Hetzner image

In this example, we have 10Gb for / and empty disk /dev/sdb

Залишити відповідь