Of course! This is a very common task. Let's walk through it step-by-step.
You've asked two great questions. The short answer is:
- No, you don't mount it first. You have to check that the system sees it, then prepare it (partition and format), and then you can mount it.
- To check if it's plugged in, you use command-line tools that list the block devices (like hard disks) attached to your system.
Here is the complete process from checking to mounting permanently.
Step 1: Check if the Server Detects the Hard Disk
First, you need to identify the new disk. This is the most critical step. Choosing the wrong disk in later steps can permanently erase all data on it (like your operating system disk!).
Open your terminal and use one of these commands. You'll likely need to use sudo to get the required permissions.
Recommended Command: lsblk
lsblk (list block devices) is the easiest to read. It shows disks and their partitions in a tree-like format.
sudo lsblk
You'll see output like this. Let's assume your original disk is sda and your new disk is a 1TB drive.
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 240.0G 0 disk
├─sda1 8:1 0 512M 0 part /boot/efi
└─sda2 8:2 0 239.5G 0 part /
sdb 8:16 0 931.5G 0 disk <-- THIS IS LIKELY YOUR NEW DISK
sr0 11:0 1 1024M 0 rom
How to identify the new disk:
- Size: It will match the size of the disk you just plugged in (e.g.,
931.5G for a 1TB disk).
- Mountpoint: It will have no mountpoint listed.
- Name: It will likely be
/dev/sdb, /dev/sdc, etc., if your first disk is /dev/sda. If you're using NVMe drives, it could be /dev/nvme1n1.
For the rest of this guide, we will assume your new, unformatted disk is /dev/sdb. REPLACE /dev/sdb WITH THE ACTUAL DEVICE NAME YOU FOUND.
Step 2: Partition the Disk
A new disk is like a blank book. Before you can write in it, you need to define its chapters. This is called partitioning. We will create one large partition that uses the whole disk.
We'll use fdisk, a standard partitioning tool.
sudo fdisk /dev/sdb
This will start the fdisk interactive prompt. Here are the commands you'll type, one by one:
g - This creates a new, empty GPT partition table. GPT is the modern standard and is recommended.
n - This creates 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 (this will make the partition use the entire disk).
p - (Optional) This prints the new partition table so you can review it. You should see a new partition like /dev/sdb1.
w - This is the most important step. It writes the changes to the disk and exits fdisk. Without this, nothing you did is saved.
Your new partition is now created. The system will know it as /dev/sdb1 (the 1 indicates the first partition on the sdb disk).
Step 3: Format the Partition
Now that you have a "chapter" (/dev/sdb1), you need to add lines to the pages so you can write on them. This is called formatting, or creating a filesystem. A great, all-purpose filesystem for Debian is ext4.
sudo mkfs.ext4 /dev/sdb1
Warning: Make absolutely sure you have the number at the end (/dev/sdb**1**). Formatting /dev/sdb (the whole disk) can work but is non-standard and can cause issues. You format the partition, not the disk.
This command will take a few seconds to a few minutes depending on the disk size.
Step 4: Mount the Disk
Now the disk is ready to be used. You need to "attach" its filesystem to a directory on your server. This directory is called a "mount point".
-
Create a Mount Point: Let's create a directory in /mnt for this purpose. You can name it anything you like.
sudo mkdir /mnt/mydisk
-
Mount the Disk (Temporarily): Now, mount the partition to that directory.
sudo mount /dev/sdb1 /mnt/mydisk
-
Verify the Mount: Check with lsblk again or df -h (disk free).
lsblk
Output should now show the mount point:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 0 931.5G 0 disk
└─sdb1 8:17 0 931.5G 0 part /mnt/mydisk <-- SUCCESS!
You can now read and write files to /mnt/mydisk, and they will be saved on your new hard disk!
Step 5: Make the Mount Permanent (Auto-mount on Boot)
The mount you just did is temporary. If you reboot the server, you will have to run the mount command again. To make it permanent, you need to add it to a special file called /etc/fstab.
-
Get the Disk's UUID: It's best to use the disk's unique ID (UUID) instead of its name (/dev/sdb1), because the name can sometimes change after a reboot.
sudo blkid /dev/sdb1
This will give you an output like:
/dev/sdb1: UUID="a1b2c3d4-e5f6-7890-a1b2-c3d4e5f67890" TYPE="ext4" PARTUUID="..."
Copy the UUID value (the long string in the quotes).
-
Edit /etc/fstab:
First, make a backup of the file, just in case.
sudo cp /etc/fstab /etc/fstab.bak
Now, open the file with a text editor like nano.
sudo nano /etc/fstab
-
Add a new line to the end of the file. The format is:
<UUID> <mount_point> <filesystem> <options> <dump> <pass>
Using our example, the line would be:
UUID=a1b2c3d4-e5f6-7890-a1b2-c3d4e5f67890 /mnt/mydisk ext4 defaults 0 2
defaults is a good standard set of options.
0 2 tells the system how to handle backups and filesystem checks on boot. 0 2 is correct for a secondary data disk.
-
Save and Exit: In nano, press Ctrl+X, then Y, then Enter.
-
Test your fstab entry: You can test that the entry is correct without rebooting. Just run mount -a, which mounts all filesystems in /etc/fstab. Since it's already mounted, it shouldn't do anything, but if you get an error, you know you have a typo in your fstab file.
sudo mount -a
If no errors appear, you're all set! The disk will now automatically mount every time you boot your server.