How to add, partition, and mount a new drive in Debian (terminal only)
A complete guide to initializing a new HDD or SSD on a running Debian system using fdisk, mkfs, and fstab.
Introduction
You've just physically installed a new SSD or HDD into your Debian server. You reboot, but the drive doesn't appear. This is normal. In Linux, new drives must be manually partitioned, formatted, and mounted before the operating system can use them.
This guide will walk you through the entire process from the command line. We'll find the disk, create a modern GPT partition table, format it with the standard ext4 filesystem, and, most importantly, configure it to auto-mount safely on boot using fstab.
The tools we'll use are lsblk, fdisk, mkfs.ext4, and blkid.
Step 1: Find the new disk (the critical safety step)
This is the most important step. Choosing the wrong disk will destroy your data or your operating system. We need to be 100% certain we are targeting the new, blank drive.
The safest tool for this is lsblk, which lists block devices.
Run the lsblk command to see all connected drives:
xinit@localhost:~$ lsblk
# You will see output similar to this:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 99G 0 part /
sdb 8:16 0 500G 0 disk
How to read this:
- sda is our primary OS drive. You can see it has partitions (sda1, sda2) that are mounted (/boot, /).
- sdb is our new drive. It has a size of 500G, no partitions, and no mountpoint.
This confirms our new, blank disk is at /dev/sdb. We will use /dev/sdb for the rest of this guide. Your disk might be named /dev/sdc, /dev/vdb, or /dev/nvme0n1. Replace /dev/sdb with your disk's name in all following commands.
Step 2: Create a GPT partition table with fdisk
Now that we have our target (/dev/sdb), we need to create a partition table. We'll use GPT as it's the modern standard, required for disks larger than 2TB and generally preferred.
We will use the fdisk utility.
Open the target disk with fdisk:
xinit@localhost:~$ sudo fdisk /dev/sdb
You are now inside the fdisk prompt. We will press a series of single keys.
- Press g to create a new, empty GPT partition table.
- Press n to create a new partition.
- Press Enter (to accept the default partition number, 1).
- Press Enter (to accept the default first sector).
- Press Enter (to accept the default last sector, which uses the entire disk).
- Press w to write all changes to the disk and exit.
Here is what that interaction will look like:
Welcome to fdisk (util-linux 2.36.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): g ‹-- YOU PRESS 'g'
Created a new GPT disklabel (GUID: ...).
Command (m for help): n ‹-- YOU PRESS 'n'
Partition number (1-128, default 1): ‹-- YOU PRESS 'ENTER'
First sector (2048-..., default 2048): ‹-- YOU PRESS 'ENTER'
Last sector (2048-..., default 1048575966): ‹-- YOU PRESS 'ENTER'
Created a new partition 1 of type 'Linux filesystem' and size 500 GiB.
Command (m for help): w ‹-- YOU PRESS 'w'
The partition table has been altered.
Syncing disks.
Your disk now has a single partition located at /dev/sdb1.
Step 3: Create a file system (formatting)
Our new partition (/dev/sdb1) exists, but it's "raw". We need to format it with a filesystem so the OS can store files. We'll use ext4, the default for Debian.
Format the new partition using mkfs.ext4:
xinit@localhost:~$ sudo mkfs.ext4 /dev/sdb1
Warning: Make sure you are formatting the partition (/dev/sdb**1**), not the entire disk (/dev/sdb).
The command will take a moment to create the filesystem journal and inodes. Once done, the drive is ready to be mounted.
Step 4: Mount the drive (temporarily)
The drive is formatted, but not yet accessible. We need to "mount" it to a folder in our filesystem. We'll use /mnt/new_drive for this temporary test.
First, create the mount point (an empty directory):
xinit@localhost:~$ sudo mkdir /mnt/new_drive
Now, mount the partition to that directory:
xinit@localhost:~$ sudo mount /dev/sdb1 /mnt/new_drive
The drive is now "live". You can verify this with the df (disk free) command.
Check the mounted filesystems:
xinit@localhost:~$ df -hT
Filesystem Type Size Used Avail Use% Mounted on
...
/dev/sdb1 ext4 492G 28K 467G 1% /mnt/new_drive
You can now write files to /mnt/new_drive.
Step 5: "Safe removal" (unmounting)
If this were a USB drive, or if you needed to disconnect it, you cannot simply unplug it. You must first unmount it to ensure all data is safely written from memory to the disk.
Unmount the drive using the umount command:
xinit@localhost:~$ sudo umount /mnt/new_drive
If you get an error like umount: /mnt/new_drive: target is busy, it means a program (or your own shell) is currently inside that directory. Simply cd / to exit the directory and try the command again.
Step 6: Automount at boot (the fstab guide)
Our mount in Step 4 is temporary and will not survive a reboot. To make the drive mount automatically, we must add it to /etc/fstab.
Crucial: We will not use /dev/sdb1 in fstab. Device names can change on reboot (e.g., your drive could become /dev/sdc1). We will use the partition's UUID (Universally Unique Identifier), which is permanent.
First, find your partition's UUID:
xinit@localhost:~$ sudo blkid /dev/sdb1
The output will show its UUID. Copy this value. OUTPUT: /dev/sdb1: UUID="1234abcd-5678-90ef-ghij-1234567890ab" TYPE="ext4" ...
Next, create a permanent mount point. The /mnt directory is for temporary mounts. Let's create a directory like /srv/data (a good place for server data).
xinit@localhost:~$ sudo mkdir /srv/data
Now, open /etc/fstab with a text editor:
xinit@localhost:~$ sudo nano /etc/fstab
Go to the very bottom of the file and add one new line. The line has 6 columns: ‹UUID› ‹Mount Point› ‹Filesystem› ‹Options› ‹Dump› ‹Pass›
Use the UUID you copied, your new mount point, ext4, defaults, 0, and 2.
# ‹file system› ‹mount point› ‹type› ‹options› ‹dump› ‹pass›
... (other fstab entries) ...
# Mount for our new data drive
UUID=1234abcd-5678-90ef-ghij-1234567890ab /srv/data ext4 defaults 0 2
Save the file and exit nano (Ctrl+O, Enter, Ctrl+X).
The safe fstab test
Do not reboot to test! A typo in fstab can prevent your system from booting. We can test our fstab entry with the mount -a command, which mounts all drives listed in fstab that aren't already mounted.
Run the mount-all command:
xinit@localhost:~$ sudo mount -a
If the command completes with no errors, your fstab entry is correct.
You can verify it one last time with df:
xinit@localhost:~$ df -hT
# You should now see your drive mounted on its permanent home:
Filesystem Type Size Used Avail Use% Mounted on
...
/dev/sdb1 ext4 492G 28K 467G 1% /srv/data
Conclusion
You have successfully initialized a new disk on your Debian server. You safely identified it with lsblk, created a modern GPT partition with fdisk, formatted it with ext4, and—most importantly—configured it for safe and reliable automatic mounting using its UUID in /etc/fstab. Your drive is now ready for production use.