Last active
May 4, 2022 04:30
-
-
Save ctron/88fa70926fc14c894e42ecf373cb271e to your computer and use it in GitHub Desktop.
Reserving additional space on Hetzner cloud instances using CentOS 7
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 | |
# 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: | |
- [ 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 |
Interesting … I never tried that. I changed the title to CentOS 7 though.
Got it working for CentOS8 Hetzner image as well. Problem is that gparted is complaining that not all space is used, therefore you can't use the whole disk at the beginning. So fix this, first.
#cloud-config
# we need to disable the initial call to "growpart" as otherwise the first partition would consume
# all space on the dist
# 1. Fix potential parted error "Not all of the space available to.."
# 2. Create a 2nd XFS partition starting at 10GB
# 3. Enable LVM on 2nd partion
# 4. Grow partition 1 (/) to 100% (0-10GB)
# 5. Re-Read partition layout
# 6. resize / partition to use the whole 10GB
# 7. Create LVM PV
# 8. Create LVM LV
#
# The final disk layout is:
# #0 0 - 10GB - XFS 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, -s, "/dev/sda", mkpart, primary, ext2, "10GB", "100%" ] # create a new partition, starting at 10GB
- [ parted, -s, "/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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Seems to be ignored here when trying to instantiate CentOS8 instance. Is still:
Logs: