How to Add and Mount a New HDD as a Backup Disk on Debian

How to Add and Mount a New HDD as a Backup Disk on Debian

Adding a new hard drive to your Debian server or VM for backup storage is a critical task for data safety. This guide provides a straightforward, step-by-step process, from identifying the new disk to formatting, mounting, and ensuring it persists after a reboot.


Step 1: Identify the New Disk

First, you need to identify the device name of the newly added hard drive. Use the `lsblk` command, which lists all block devices.

lsblk

Look for a disk (e.g., /dev/sdb or /dev/vdb) that matches the size of your new drive and doesn't have any partitions listed under it. This confirms it's the correct, unformatted disk.


Step 2: Check for Existing Partitions

While `lsblk` is a great start, use `fdisk` to get a more detailed view and confirm the disk is empty. This prevents accidental data loss.

sudo fdisk -l /dev/vdb

If the output shows no partition table or partitions, you're ready to create one.


Step 3: Create a New Partition

Now, create a partition that spans the entire disk using the interactive `fdisk` utility.

sudo fdisk /dev/vdb

Inside the `fdisk` prompt, follow these commands:

  • Press n to create a new partition.
  • Press p for a primary partition.
  • Press 1 to select it as the first partition.
  • Press Enter twice to accept the default start and end sectors (this uses the whole disk).
  • Press w to write the changes to the partition table and exit.

Step 4: Verify the New Partition

Run `lsblk` again. You should now see a new partition, such as /dev/vdb1, listed under your disk.

lsblk

Step 5: Format the Partition

For backup purposes on a Linux system, the ext4 filesystem is an excellent choice due to its stability, performance, and journaling features. Format your new partition with it.

sudo mkfs.ext4 /dev/vdb1

Filesystem Comparison for Backup Drives

While ext4 is recommended, other filesystems have unique advantages. Here’s a quick comparison:

Feature ext4 (Recommended) XFS Btrfs
Max File Size 16 TiB 8 EiB 16 EiB
Journaling Yes Yes Yes (Copy-on-Write)
Built-in Snapshots No No (via LVM) Yes (Integrated)
Data Integrity Good (Checksums via external tools) Excellent (Metadata checksums) Excellent (Data & Metadata checksums)
Use Case General purpose, high compatibility, stable. Large files, high-performance streaming. Advanced features like snapshots & data integrity.

Step 6: Mount the Partition

First, create a directory that will serve as the mount point. This is where you'll access the files on your new drive.

sudo mkdir /mnt/hdd2-backup

Next, mount the partition to this directory.

sudo mount /dev/vdb1 /mnt/hdd2-backup

Verify that it's mounted correctly. The output should show your partition mounted at the specified path.

df -hT | grep vdb1

Step 7: Make the Mount Persistent on Reboot

To ensure your drive is automatically mounted every time the system boots, you must add it to the `/etc/fstab` file. Using the partition's UUID is the most reliable method.

1. Get the partition's UUID:

sudo blkid /dev/vdb1

2. Copy the UUID value from the output (e.g., `445a60ab-f76c-40c3-bdaa-12080a53a394`).

3. Back up your `fstab` file before editing:

sudo cp /etc/fstab /etc/fstab.bak

4. Open `/etc/fstab` with a text editor like `nano`:

sudo nano /etc/fstab

5. Add the following line to the end of the file, replacing the UUID with your own:

UUID=445a60ab-f76c-40c3-bdaa-12080a53a394  /mnt/hdd2-backup  ext4  defaults  0  2

6. Save the file and exit. Test the configuration by running:

sudo mount -a

If no errors appear, your setup is complete and correct.


Step 8: Use the New Backup Path

Your new, persistent backup storage is now ready. Simply point your backup software or scripts to use the /mnt/hdd2-backup directory.

/mnt/hdd2-backup

Professional & Remote Support

Stuck on a step or facing an unexpected error? Don't risk your data. Get expert help to ensure your backup system is configured correctly and securely.

Freelancer Contact: For direct assistance with your Debian server configuration, reach out via WhatsApp.

👉 Contact on WhatsApp


Remote Support

Frequently Asked Questions & Real-World Errors

Q: My system won't boot after editing /etc/fstab! What do I do?

A: This is a serious but fixable issue, usually caused by a typo. On boot, you'll likely see a message like this and be dropped into emergency mode:


You are in emergency mode. After logging in, type "journalctl -xb" to view
system logs, "systemctl reboot" to reboot, "systemctl default" or "exit"
to boot into default mode.
Give root password for maintenance
(or press Control-D to continue):
        

Solution:

  1. Enter your root password.
  2. Remount the root filesystem as read-write: `mount -o remount,rw /`
  3. Open `/etc/fstab` with `nano /etc/fstab`.
  4. Carefully check the line you added for typos. Common mistakes include a wrong UUID, a non-existent mount point, or a misspelled filesystem type.
  5. Fix the error, or to be safe, comment out the line by adding a `#` at the beginning.
  6. Save the file and reboot with `reboot`. The system should now start normally.

Q: How do I set the correct permissions for a backup user and verify them?

A: After mounting, the drive is owned by root, which can cause permission errors for your backup software. To fix this, change the owner. Let's assume your user is `backupuser`.

1. Check the current permissions. The owner will be `root`.


$ ls -ld /mnt/hdd2-backup/
drwxr-xr-x 2 root root 4096 Jul 21 16:30 /mnt/hdd2-backup/
        

2. Change the owner and group to your `backupuser`.

sudo chown backupuser:backupuser /mnt/hdd2-backup/

3. Verify the change. The owner should now be `backupuser`.


$ ls -ld /mnt/hdd2-backup/
drwxr-xr-x 2 backupuser backupuser 4096 Jul 21 16:30 /mnt/hdd2-backup/
        

Q: What does the 'device is busy' error from fdisk look like?

A: If the disk or one of its partitions is in use (e.g., auto-mounted), `fdisk` will fail with this specific error:


$ sudo fdisk /dev/vdb
fdisk: cannot open /dev/vdb: Device or resource busy
        

Solution: You cannot partition a disk that is in use. First, find out where it's mounted with `lsblk` or `df -hT`. Then, unmount it. For example, if it was automatically mounted to `/media/user/NEW_DISK`, you would run:

sudo umount /media/user/NEW_DISK

After unmounting, you can run `fdisk` again successfully.

Q: I think I formatted the wrong disk by mistake! Can I recover my data?

A: This is a critical situation. First, stop using the disk immediately. Do not write any new data to it. The more you use it, the lower the chance of recovery.

Data recovery is complex. The `mkfs.ext4` command overwrites the old filesystem metadata. While some data might still be physically on the drive, recovering it requires specialized tools.

  • Tool Recommendation: A powerful open-source tool for this is `testdisk`. It can scan for old partition tables and potentially recover them. You can install it with `sudo apt install testdisk`.
  • Procedure: Run `sudo testdisk`, select the affected drive, and follow its guided analysis.

Data recovery is not guaranteed. If the data is mission-critical, consider seeking professional help immediately. This is a perfect scenario where our remote support can provide expert guidance to maximize recovery chances.


Trusted by some of the biggest brands

We’re Waiting To Help You

Get in touch with us today and let’s start transforming your business from the ground up.