| |

How to Repartition a Hetzner Cloud Server

This guide will walk you through the process of repartitioning a Hetzner cloud server to create an additional partition that can be formatted with a different file system (e.g., ZFS or BTRFS). We’ll use a CAX11 cloud server with Debian 12 as an example.

Prerequisites

  • A Hetzner cloud server (this guide uses a CAX11 with Debian 12)
  • Access to the Hetzner control panel
  • Basic knowledge of the Linux command line

Step 1: Boot into Rescue Mode

  1. Log into your Hetzner control panel.
  2. Select your server and boot it into Rescue mode.

Step 2: Analyze Current Partition Layout

Once in Rescue mode, connect to your server via SSH and follow these steps:

  1. Use lsblk to view available devices and their partitions:
   lsblk
  1. (Optional) Use df -h to check how much disk space is occupied by the operating system:
   df -h

Note: Generally, 10 GB is more than enough for the operating system.

Step 3: Prepare the Existing Partition

  1. Check the file system for errors:
   e2fsck -f /dev/sda1
  1. Resize the file system to 9G (1GB less than the target partition size):
   resize2fs /dev/sda1 9G

Note: We resize to 1GB less than the target partition size to ensure enough space is available for the file system, avoiding potential corruption.

Step 4: Resize and Create Partitions

  1. Start the parted utility:
   parted /dev/sda
  1. View the current partition layout:
   (parted) print
  1. Resize partition 1 to 10G:
   (parted) resizepart 1 10G

When prompted with a warning, type “yes” to continue.

  1. Create a new partition for the remaining space:
   (parted) mkpart
   Partition name?  []? 
   File system type?  [ext2]? zfs
   Start? 10G
   End? 100%
  1. Verify the new partition layout:
   (parted) print

You should see output similar to this:

   Model: QEMU QEMU HARDDISK (scsi)
   Disk /dev/sda: 41.0GB
   Sector size (logical/physical): 512B/512B
   Partition Table: gpt
   Disk Flags:

   Number  Start   End     Size    File system  Name  Flags
   14      1049kB  2097kB  1049kB                     bios_grub
   15      2097kB  258MB   256MB   fat16              boot, esp
    1      258MB   10.0GB  9742MB  ext4
    2      10.0GB  41.0GB  31.0GB  zfs
  1. Check if partitions are optimally aligned:
   (parted) align-check optimal 1
   (parted) align-check optimal 2

If the partitions are optimally aligned, you’ll see “1 aligned” and “2 aligned” as responses.

  1. Exit parted:
   (parted) quit

You may see a message: “Information: You may need to update /etc/fstab.”

Step 5: Disable Automatic Partition Growth

  1. Mount the resized partition:
   mount /dev/sda1 /mnt
  1. Create a file to disable automatic growth:
   touch /mnt/etc/growroot-disabled
  1. Unmount the partition:
   umount /mnt/

Step 6: Finalize File System Resize

  1. Check the file system again:
   e2fsck -f /dev/sda1
  1. Resize the file system to match the new partition size:
   resize2fs /dev/sda1

Step 7: Reboot the Server

Reboot your server to apply all changes:

shutdown -r now

Conclusion

You have now successfully repartitioned your Hetzner cloud server, creating an additional partition that can be formatted with ZFS or another file system of your choice.

Remember to format your new partition after the reboot. For ZFS, you would typically use the “zpool create” command. Also, update your “/etc/fstab” if necessary to mount the new partition automatically.

Note

This process involves manipulating partition tables and file systems, which can potentially lead to data loss if not done correctly. Always ensure you have a backup of your important data before proceeding with such operations.

Additionally, if you’re planning to use ZFS, consider Hetzner’s volume offerings as an alternative to repartitioning. Hetzner provides volumes based on networked block storage that can be attached to your cloud server as separate disks (e.g., /dev/sdb). These volumes can be used by ZFS as complete disks, allowing ZFS to manage its own partitioning. This approach offers more flexibility and can be easier to manage, especially when you need to expand storage capacity. Consider your specific use case and performance requirements when deciding between repartitioning and using Hetzner volumes.

Similar Posts