This tutorial will give you a step-by-step guide to increase disk space on an existing Debian VM hosted on Hetzner Cloud by adding a new volume and creating a separate mount point. This allows you to store your data independently from the root partition, freeing up space and keeping your system organized.
I ran into this problem while creating my own custom Debian package repository: I underestimated the disk space needed to host the repo and download all the required files. Rather than destroying and rebuilding my existing VM from scratch, I wanted to expand the disk and create a new partition for the repository data.
1. Add a Volume & Attach it to your VM
When you realize your VM’s disk isn’t enough, the first step is to add extra storage. You'll have to create a volume and attach it to your VM. Hetzner Cloud makes this pretty simple through their web console. That's the method we'll use here.
In the Hetzner web console, just look at the left menu — there’s a “Volumes” section waiting for you :
Then, you click on the red button "Create Volume" on the right and you'll see this window:
- The diskspace you need (GB)
- The name of the volume
- The server to which you want to attach it
- The mount option
- The filesystem if you chose 'automatic' for the mount option
My initial VM only contained 40Go of disk space, and I needed to add a volume of 60Go to my VM. So here's what it looked like for me :
Adapt it to your own needs and click "Create & Buy Now" : your volume is now created and attached to you VM !
2. Change the mount point & Make it permanent on your VM
First, log on your VM and do the following command to see the new volume attached to your VM :
lsblk -f
(consider using sudo if needed)
As you can see, the volume I added is here, under the name "sdb". We also see that the volume has the right filesystem, which is 'ext4' (that's the usual filesystem on Debian, Ubuntu, CentOs...).
Finally, we see that it already has a mount point : '/mnt/HC_Volume_103410845'.
I needed that diskspace to be available for my own custom Debian package repository under /var/local/my-debian-repo.
So first, I unmounted the disk with :
sudo umount /mnt/HC_Volume_103410845
--> Just change the mount point path with the one you see on your VM.
If you get an error at this point, it might be because your
mount point still has processes running on it.
You can check if there's any process accessing it with
sudo lsof <your_mount_point_path>
With my example, I would do
sudo lsof /mnt/HC_Volume_103410845
Then, I created the directory for my repo with:
sudo mkdir -p /var/local/my-debian-repo
--> Just change the directory path with yours.
Then, mount the volume to this directory:
sudo mount /dev/sdb /var/local/my-debian-repo
--> Just change /dev/sdb with your volume's path and var/local/my-debian-repo with your own directory path.
Note: If the directory already contains files, mounting the new volume will temporarily hide them. Make sure to back up any important data in /var/local/my-debian-repo before mounting, so it isn’t lost or hidden unintentionally.
Then, check it worked with df -h
Here you see that it worked for me, /var/local/my-debian-repo is mounted on the volume.
But that is not permanent. That means if you reboot your VM, the partition /dev/sdb won’t be mounted automatically. So, to make it permanent, you have to add it to /etc/fstab file.
Important: Before editing, back up your fstab file because it’s sensitive and a mistake can prevent your system from booting:
sudo cp /etc/fstab /etc/fstab.bak
Then, you can add your new partition to fstab to mount it permanently:
sudo echo '/dev/sdb /var/local/my-debian-repo ext4 defaults 0 2' | sudo tee -a /etc/fstab
--> Change the volume path and mount point to match your setup.
Note: -a
appends the line instead of overwriting the file.
If you feel more comfortable using a text editor to add the line, you can use nano or vim and insert the following line at the end of the file:
<your_volume_path> <your_mount_point> ext4 defaults 0 2
Then, you can check it worked with cat /etc/fstab
Bonus : if you find out later that you need to change the size of your volume, just use the web console, click on the "..." next to your volume and select 'Resize'.
Note : You can expand a volume but you can't shrink one.
Resize your volume according to your needs.
Don't forget to resize the filesystem on your VM with
sudo resize2fs /dev/sdb
--> Change /dev/sdb with the path to your volume.
Note: This only adjusts the filesystem to use the new space: the volume must already have been expanded in Hetzner’s console.
This tutorial is over, I hope it was helpful :)
Top comments (0)