How to Move MariaDB Data and /home to a New Volume (Virtualmin + Debian 13)

We’ve all been there. You spun up a fresh Debian 13 VPS, dropped Virtualmin on it, setup your LAMP stack, and everything was running beautifully. Then, your sites started growing. Or maybe you realized that keeping your heavy databases and user files on the root partition is a recipe for a late-night disk space panic.

If you are hosted at Somewhere, buying an extra Block Storage Volume is cheap and easy. But getting Virtualmin, MariaDB, and Debian’s systemd security layers to play nice with that new volume? That can get a bit tricky if you don’t know the sequence.

Between balancing my day job, troubleshooting server bugs, and managing four chaotic kids with my wife, I don’t have time for broken server boots. Today, I’ll show you exactly how I moved my MariaDB data directory and expanded my /home space to a new Hetzner volume without breaking Virtualmin.


The Plan: Safe Over Fast

We are messing with active databases and user website files. One wrong command can ruin your day, so our priority here is safety.

Before running a single command:

  1. Take a full snapshot of your VPS in the Somewhere dashboard
  2. Back up your Virtualmin servers.
  3. Make sure you have your SSH keys handy.

Our target device name for this guide will be /dev/sdb. Double-check yours using the lsblk command before proceeding.


Step 1: Format and Prepare the Volume

First, we need to put a filesystem on that raw block storage and mount it somewhere temporarily so we can sync our data over.

Run these commands as root or via sudo:

`bash

Format the new volume with ext4

sudo mkfs.ext4 /dev/sdb

Create a temporary staging area

sudo mkdir /mnt/newvolume sudo mount /dev/sdb /mnt/newvolume `


Step 2: Migrate MariaDB Data Safely

Debian 13 defaults to MariaDB, storing everything in /var/lib/mysql. We need to stop the service, copy the data while keeping all permissions intact, and update the configuration.

1. Stop the database engine

bash sudo systemctl stop mariadb

2. Copy data with permissions preserved

We use rsync with the -a flag (archive mode) to ensure owners, groups, and permissions stay exactly the same.

bash sudo mkdir /mnt/newvolume/mysql sudo rsync -av /var/lib/mysql/ /mnt/newvolume/mysql/

3. Update the configuration file

Open your MariaDB server configuration file. On Debian 13, it is usually located here:

bash sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

Scroll down until you find the datadir directive. Comment out the old one and add your new path:

`ini

datadir = /var/lib/mysql

datadir = /mnt/newvolume/mysql `

4. Fix Debian’s Systemd Sandboxing (The Step Everyone Misses!)

If you try to start MariaDB right now, it will crash with an “Access Denied” error. This isn’t a traditional Linux permission issue; it’s Debian’s systemd security policy blocking MariaDB from reading files outside of its standard paths.

Let’s tell systemd that our new path is safe:

bash sudo systemctl edit mariadb

This opens a blank override file. Paste these exact lines:

ini [Service] ReadWritePaths+=/mnt/newvolume/mysql/

Save and close the editor (in Nano, press Ctrl+O, Enter, then Ctrl+X). Now reload systemd and fire up your database:

bash sudo systemctl daemon-reload sudo systemctl start mariadb

You can verify it works by logging into your MySQL prompt and running: sql SHOW VARIABLES LIKE 'datadir';


Step 3: Spread /home to the New Volume

When it comes to Virtualmin users, you have two options. You can move the entire /home directory to the new volume, or you can selectively move specific heavy users using symlinks.

Personally, I prefer moving the entire /home directory if the new volume is large enough. It keeps everything clean. Here is how to do that.

1. Sync existing home data

bash sudo rsync -avz /home/ /mnt/newvolume/home/

2. Rename the old home directory

Instead of deleting the old folder immediately, let’s rename it as a safety net.

bash sudo mv /home /home_old sudo mkdir /home

3. Move MariaDB path again (If putting everything on the volume)

If your goal was to have the entire volume become your new /home, your MariaDB data is now sitting inside /home/mysql.

Go back to /etc/mysql/mariadb.conf.d/50-server.cnf, change datadir to /home/mysql, update your sudo systemctl edit mariadb path to /home/mysql/, reload systemd, and restart MariaDB.


Step 4: Make the Mounts Permanent

If you reboot your VPS right now, your volume won’t mount automatically, and your services will crash. We need to add it to /etc/fstab.

First, grab the unique identifier (UUID) of your block storage:

bash sudo blkid /dev/sdb

Copy the string inside the UUID="..." section. Now open your fstab file:

bash sudo nano /etc/fstab

If you decided to dedicate the entire volume to your websites (/home), add this line at the bottom:

text UUID=your-copied-uuid-string-here /home ext4 defaults,noatime 0 2

(Note: If you kept the volume separate at /mnt/newvolume and used symlinks instead, replace /home with /mnt/newvolume in the line above).

The Ultimate Safety Test

Before you close your terminal or reboot, run this command. It forces systemd to mount everything listed in your fstab file:

bash sudo umount /mnt/newvolume sudo mount -a

If this command finishes silently without throwing errors, you did it perfectly. Your server is now fully configured, your root partition is safe from overflowing, and you can safely delete the /home_old directory after a few days of stable running.


Next Steps

Now that your storage layout is optimized, head into your Virtualmin > System Information dashboard to ensure your disk space quotas are reading correctly from the new mount path. If you ran into any weird systemd quirks during the process, drop a comment below and let’s get it sorted out!

No Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.