[How-To] Format and Mount Data Drive on Debian Server
Purpose
This doc shows how to take an additional virtual hard drive on a linux vm and make a mount point on the main drive with it for nextcloud data.
Prerequisites
List of prerequisites:
- Root user or sudo user
- Debian 12 LXC or VM
Instructions
Step 1: Create a Partition on the New Drive
- Use
fdisk
to partition the drive:sudo fdisk /dev/sdb
- Inside the
fdisk
utility:- Press
n
to create a new partition. - Select
p
for a primary partition. - Accept the default values for the first and last sectors (this will use the entire disk).
- Press
w
to write the changes and exit.
- Press
Step 2: Format the Partition
- Verify the partition name (it should be
/dev/sdb1
after partitioning):lsblk
- Format the partition with the ext4 filesystem:
sudo mkfs.ext4 /dev/sdb1
Step 3: Mount the Partition
- Create a directory to mount the drive (e.g.,
/mnt/nextcloud-data
):sudo mkdir /mnt/nextcloud-data
- Mount the partition to the directory:
sudo mount /dev/sdb1 /mnt/nextcloud-data
Step 4: Make the Mount Persistent
- Get the UUID of the new partition:
Example output:sudo blkid /dev/sdb1
/dev/sdb1: UUID="abcd-1234-efgh-5678" TYPE="ext4"
- Edit the
/etc/fstab
file:sudo nano /etc/fstab
- Add the following line to the file:
UUID=abcd-1234-efgh-5678 /mnt/nextcloud-data ext4 defaults 0 2
- Save and exit the editor.
Step 5: Update Nextcloud Configuration
-
Move existing Nextcloud data to the new drive:
sudo rsync -a /path/to/current/nextcloud/data/ /mnt/nextcloud-data/
Replace
/path/to/current/nextcloud/data/
with the actual path to your current Nextcloud data directory. -
Update the
datadirectory
path in Nextcloud's configuration file (config.php
):sudo nano /var/www/nextcloud/config/config.php
Find the
datadirectory
line and change it to:'datadirectory' => '/mnt/nextcloud-data',
-
Set the correct permissions:
sudo chown -R www-data:www-data /mnt/nextcloud-data
Step 6: Restart Services
-
Restart the web server and PHP:
sudo systemctl restart apache2
-
Ensure everything works:
- Log in to your Nextcloud instance.
- Verify that the new data directory is being used.
No Comments